mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-11 14:09:21 +00:00
differentiate between an invalid resource and a validation error in output
This commit is contained in:
parent
bb478da7e0
commit
928d694e66
2 changed files with 16 additions and 5 deletions
|
|
@ -3,6 +3,7 @@ package output
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/yannh/kubeconform/pkg/validator"
|
||||
)
|
||||
|
||||
type result struct {
|
||||
|
|
@ -26,10 +27,16 @@ func NewJSONOutput(withSummary bool) Output{
|
|||
func (o *JSONOutput) Write(filename string,err error, skipped bool) {
|
||||
status := "VALID"
|
||||
msg := ""
|
||||
|
||||
if err != nil {
|
||||
status = "INVALID"
|
||||
msg = err.Error()
|
||||
if _, ok := err.(validator.InvalidResourceError); ok {
|
||||
status = "INVALID"
|
||||
} else {
|
||||
status = "ERROR"
|
||||
}
|
||||
}
|
||||
|
||||
if skipped {
|
||||
status = "SKIPPED"
|
||||
}
|
||||
|
|
@ -47,6 +54,7 @@ func (o *JSONOutput) Flush() {
|
|||
Summary struct {
|
||||
Valid int `json:"valid"`
|
||||
Invalid int `json:"invalid"`
|
||||
Errors int `json:"errors"`
|
||||
Skipped int `json:"skipped"`
|
||||
} `json:"summary"`
|
||||
} {
|
||||
|
|
@ -59,6 +67,8 @@ func (o *JSONOutput) Flush() {
|
|||
jsonObj.Summary.Valid++
|
||||
case r.Status == "INVALID":
|
||||
jsonObj.Summary.Invalid++
|
||||
case r.Status == "ERROR":
|
||||
jsonObj.Summary.Errors++
|
||||
case r.Status == "SKIPPED":
|
||||
jsonObj.Summary.Skipped++
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ import (
|
|||
|
||||
type TextOutput struct {
|
||||
withSummary bool
|
||||
nValid, nInvalid, nSkipped int
|
||||
nValid, nInvalid, nErrors, nSkipped int
|
||||
}
|
||||
|
||||
func NewTextOutput(withSummary bool) Output {
|
||||
return &TextOutput{withSummary, 0,0,0}
|
||||
return &TextOutput{withSummary, 0,0,0, 0}
|
||||
}
|
||||
|
||||
func (o *TextOutput) Write(filename string,err error, skipped bool) {
|
||||
|
|
@ -22,11 +22,12 @@ func (o *TextOutput) Write(filename string,err error, skipped bool) {
|
|||
}
|
||||
|
||||
if err != nil {
|
||||
o.nInvalid++
|
||||
if _, ok := err.(validator.InvalidResourceError); ok {
|
||||
fmt.Printf("invalid resource: %s\n", err)
|
||||
o.nInvalid++
|
||||
} else {
|
||||
fmt.Printf("failed validating resource in file %s: %s\n", filename, err)
|
||||
o.nErrors++
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -39,7 +40,7 @@ func (o *TextOutput) Write(filename string,err error, skipped bool) {
|
|||
|
||||
func (o *TextOutput) Flush() {
|
||||
if o.withSummary {
|
||||
fmt.Printf("Run summary - Valid: %d, Invalid: %d, Skipped: %d\n", o.nValid, o.nInvalid, o.nSkipped)
|
||||
fmt.Printf("Run summary - Valid: %d, Invalid: %d, Errors: %d Skipped: %d\n", o.nValid, o.nInvalid, o.nErrors, o.nSkipped)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue