mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-20 10:27:02 +00:00
output: unexport status constants
This commit is contained in:
parent
daab22bc8a
commit
896a75d394
3 changed files with 24 additions and 21 deletions
|
|
@ -44,24 +44,24 @@ func (o *jsono) Write(filename, kind, name, version string, err error, skipped b
|
||||||
s := status(kind, name, err, skipped)
|
s := status(kind, name, err, skipped)
|
||||||
|
|
||||||
switch s {
|
switch s {
|
||||||
case VALID:
|
case statusValid:
|
||||||
st = "VALID"
|
st = "VALID"
|
||||||
o.nValid++
|
o.nValid++
|
||||||
case INVALID:
|
case statusInvalid:
|
||||||
st = "INVALID"
|
st = "INVALID"
|
||||||
msg = err.Error()
|
msg = err.Error()
|
||||||
o.nInvalid++
|
o.nInvalid++
|
||||||
case ERROR:
|
case statusError:
|
||||||
st = "ERROR"
|
st = "ERROR"
|
||||||
msg = err.Error()
|
msg = err.Error()
|
||||||
o.nErrors++
|
o.nErrors++
|
||||||
case SKIPPED:
|
case statusSkipped:
|
||||||
st = "SKIPPED"
|
st = "SKIPPED"
|
||||||
o.nSkipped++
|
o.nSkipped++
|
||||||
case EMPTY:
|
case statusEmpty:
|
||||||
}
|
}
|
||||||
|
|
||||||
if o.verbose || (s != VALID && s != SKIPPED && s != EMPTY) {
|
if o.verbose || (s != statusValid && s != statusSkipped && s != statusEmpty) {
|
||||||
o.results = append(o.results, result{Filename: filename, Kind: kind, Name: name, Version: version, Status: st, Msg: msg})
|
o.results = append(o.results, result{Filename: filename, Kind: kind, Name: name, Version: version, Status: st, Msg: msg})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,19 @@
|
||||||
package output
|
package output
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/yannh/kubeconform/pkg/validator"
|
"github.com/yannh/kubeconform/pkg/validator"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
_ = iota
|
_ = iota
|
||||||
VALID
|
statusValid
|
||||||
INVALID
|
statusInvalid
|
||||||
ERROR
|
statusError
|
||||||
SKIPPED
|
statusSkipped
|
||||||
EMPTY
|
statusEmpty
|
||||||
)
|
)
|
||||||
|
|
||||||
type Output interface {
|
type Output interface {
|
||||||
|
|
@ -33,19 +36,19 @@ func New(outputFormat string, printSummary, verbose bool) (Output, error) {
|
||||||
|
|
||||||
func status(kind, name string, err error, skipped bool) int {
|
func status(kind, name string, err error, skipped bool) int {
|
||||||
if name == "" && kind == "" && err == nil && skipped == false {
|
if name == "" && kind == "" && err == nil && skipped == false {
|
||||||
return EMPTY
|
return statusEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
if skipped {
|
if skipped {
|
||||||
return SKIPPED
|
return statusSkipped
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(validator.InvalidResourceError); ok {
|
if _, ok := err.(validator.InvalidResourceError); ok {
|
||||||
return INVALID
|
return statusInvalid
|
||||||
}
|
}
|
||||||
return ERROR
|
return statusError
|
||||||
}
|
}
|
||||||
|
|
||||||
return VALID
|
return statusValid
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,27 +37,27 @@ func (o *text) Write(filename, kind, name, version string, reserr error, skipped
|
||||||
|
|
||||||
o.files[filename] = true
|
o.files[filename] = true
|
||||||
switch status(kind, name, reserr, skipped) {
|
switch status(kind, name, reserr, skipped) {
|
||||||
case VALID:
|
case statusValid:
|
||||||
if o.verbose {
|
if o.verbose {
|
||||||
_, err = fmt.Fprintf(o.w, "%s - %s %s is valid\n", filename, kind, name)
|
_, err = fmt.Fprintf(o.w, "%s - %s %s is valid\n", filename, kind, name)
|
||||||
}
|
}
|
||||||
o.nValid++
|
o.nValid++
|
||||||
case INVALID:
|
case statusInvalid:
|
||||||
_, err = fmt.Fprintf(o.w, "%s - %s %s is invalid: %s\n", filename, kind, name, reserr)
|
_, err = fmt.Fprintf(o.w, "%s - %s %s is invalid: %s\n", filename, kind, name, reserr)
|
||||||
o.nInvalid++
|
o.nInvalid++
|
||||||
case ERROR:
|
case statusError:
|
||||||
if kind != "" && name != "" {
|
if kind != "" && name != "" {
|
||||||
_, err = fmt.Fprintf(o.w, "%s - %s %s failed validation: %s\n", filename, kind, name, reserr)
|
_, err = fmt.Fprintf(o.w, "%s - %s %s failed validation: %s\n", filename, kind, name, reserr)
|
||||||
} else {
|
} else {
|
||||||
_, err = fmt.Fprintf(o.w, "%s - failed validation: %s\n", filename, reserr)
|
_, err = fmt.Fprintf(o.w, "%s - failed validation: %s\n", filename, reserr)
|
||||||
}
|
}
|
||||||
o.nErrors++
|
o.nErrors++
|
||||||
case SKIPPED:
|
case statusSkipped:
|
||||||
if o.verbose {
|
if o.verbose {
|
||||||
_, err = fmt.Fprintf(o.w, "%s - %s %s skipped\n", filename, name, kind)
|
_, err = fmt.Fprintf(o.w, "%s - %s %s skipped\n", filename, name, kind)
|
||||||
}
|
}
|
||||||
o.nSkipped++
|
o.nSkipped++
|
||||||
case EMPTY: // sent to ensure we count the filename as parsed
|
case statusEmpty: // sent to ensure we count the filename as parsed
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue