mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-11 14:09:21 +00:00
Better logging messages
This commit is contained in:
parent
ae5fbffb95
commit
11cfca1498
4 changed files with 20 additions and 11 deletions
2
main.go
2
main.go
|
|
@ -104,7 +104,7 @@ func realMain() int {
|
|||
flag.IntVar(&nWorkers, "workers", 4, "number of routines to run in parallel")
|
||||
flag.StringVar(&k8sVersion, "k8sversion", "1.18.0", "version of Kubernetes to test against")
|
||||
flag.StringVar(&skipKinds, "skipKinds", "", "comma-separated list of kinds to ignore")
|
||||
flag.BoolVar(&strict, "strict", false, "activate strict mode")
|
||||
flag.BoolVar(&strict, "strict", true, "activate strict mode")
|
||||
flag.StringVar(&outputFormat, "output", "text", "output format - text, json")
|
||||
flag.BoolVar(&quiet, "quiet", false, "quiet output - only print invalid files, and errors")
|
||||
flag.Parse()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package output
|
||||
|
||||
import "github.com/yannh/kubeconform/pkg/validator"
|
||||
import (
|
||||
"github.com/yannh/kubeconform/pkg/validator"
|
||||
)
|
||||
|
||||
const (
|
||||
VALID = iota
|
||||
|
|
@ -15,6 +17,10 @@ type Output interface {
|
|||
}
|
||||
|
||||
func status(err error, skipped bool) int {
|
||||
if skipped {
|
||||
return SKIPPED
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if _, ok := err.(validator.InvalidResourceError); ok {
|
||||
return INVALID
|
||||
|
|
@ -23,9 +29,5 @@ func status(err error, skipped bool) int {
|
|||
}
|
||||
}
|
||||
|
||||
if skipped {
|
||||
return SKIPPED
|
||||
}
|
||||
|
||||
return VALID
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,18 +31,18 @@ func (o *TextOutput) Write(filename string, err error, skipped bool) {
|
|||
switch {
|
||||
case s == VALID:
|
||||
if !o.quiet {
|
||||
fmt.Printf("file %s is valid\n", filename)
|
||||
fmt.Printf("%s - file is valid\n", filename)
|
||||
}
|
||||
o.nValid++
|
||||
case s == INVALID:
|
||||
fmt.Printf("invalid resource: %s\n", err)
|
||||
fmt.Printf("%s - invalid resource: %s\n",filename, err)
|
||||
o.nInvalid++
|
||||
case s == ERROR:
|
||||
fmt.Printf("failed validating resource in file %s: %s\n", filename, err)
|
||||
fmt.Printf("%s - failed validating resource: %s\n", filename, err)
|
||||
o.nErrors++
|
||||
case s == SKIPPED:
|
||||
if !o.quiet {
|
||||
fmt.Printf("skipping resource\n")
|
||||
fmt.Printf("%s - skipping resource\n", filename)
|
||||
}
|
||||
o.nSkipped++
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,14 @@ func Validate(rawResource []byte, schema *gojsonschema.Schema) error {
|
|||
}
|
||||
|
||||
if !results.Valid() {
|
||||
return InvalidResourceError{err: fmt.Sprintf("resource does not conform to schema: %+v", results)}
|
||||
msg := ""
|
||||
for _, errMsg := range results.Errors() {
|
||||
if msg != "" {
|
||||
msg += " - "
|
||||
}
|
||||
msg += errMsg.Description()
|
||||
}
|
||||
return InvalidResourceError{err: msg}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Reference in a new issue