diff --git a/main.go b/main.go index 88abc1f..a1726fb 100644 --- a/main.go +++ b/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() diff --git a/pkg/output/main.go b/pkg/output/main.go index 0f137d4..e23bbfe 100644 --- a/pkg/output/main.go +++ b/pkg/output/main.go @@ -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 } diff --git a/pkg/output/text.go b/pkg/output/text.go index a1a0a7f..47af997 100644 --- a/pkg/output/text.go +++ b/pkg/output/text.go @@ -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++ } diff --git a/pkg/validator/main.go b/pkg/validator/main.go index 480ae15..b79aa31 100644 --- a/pkg/validator/main.go +++ b/pkg/validator/main.go @@ -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