mirror of
https://github.com/yannh/kubeconform.git
synced 2026-04-16 09:09:53 +00:00
Better logging messages
This commit is contained in:
parent
ae5fbffb95
commit
11cfca1498
4 changed files with 20 additions and 11 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue