1+ // This is the main package to import to embed kubeconform in your software
12package validator
23
34import (
45 "context"
56 "fmt"
7+ "io"
8+
69 "github.com/yannh/kubeconform/pkg/cache"
710 "github.com/yannh/kubeconform/pkg/registry"
811 "github.com/yannh/kubeconform/pkg/resource"
9- "io"
1012
1113 "github.com/xeipuuv/gojsonschema"
1214 "sigs.k8s.io/yaml"
1315)
1416
17+ // Different types of validation results
1518type Status int
1619
1720const (
18- _ Status = iota
19- Error
20- Skipped
21- Valid
22- Invalid
23- Empty
21+ _ Status = iota
22+ Error // an error occurred processing the file / resource
23+ Skipped // resource has been skipped, for example if its Kind was part of the kinds to skip
24+ Valid // resource is valid
25+ Invalid // resource is invalid
26+ Empty // resource is empty. Note: is triggered for files starting with a --- separator.
2427)
2528
2629// Result contains the details of the result of a resource validation
@@ -30,6 +33,7 @@ type Result struct {
3033 Status Status
3134}
3235
36+ // Validator exposes multiple methods to validate your Kubernetes resources.
3337type Validator interface {
3438 ValidateResource (res resource.Resource ) Result
3539 Validate (filename string , r io.ReadCloser ) []Result
@@ -38,12 +42,12 @@ type Validator interface {
3842
3943// Opts contains a set of options for the validator.
4044type Opts struct {
41- SkipTLS bool // skip TLS validation when downloading from an HTTP Schema Registry
42- SkipKinds map [string ]bool // List of resource Kinds to ignore
43- RejectKinds map [string ]bool // List of resource Kinds to reject
44- KubernetesVersion string // Kubernetes Version - has to match one in https://github.com/instrumenta/kubernetes-json-schema
45- Strict bool // thros an error if resources contain undocumented fields
46- IgnoreMissingSchemas bool // skip a resource if no schema for that resource can be found
45+ SkipTLS bool // skip TLS validation when downloading from an HTTP Schema Registry
46+ SkipKinds map [string ]struct {} // List of resource Kinds to ignore
47+ RejectKinds map [string ]struct {} // List of resource Kinds to reject
48+ KubernetesVersion string // Kubernetes Version - has to match one in https://github.com/instrumenta/kubernetes-json-schema
49+ Strict bool // thros an error if resources contain undocumented fields
50+ IgnoreMissingSchemas bool // skip a resource if no schema for that resource can be found
4751}
4852
4953// New returns a new Validator
@@ -63,10 +67,10 @@ func New(schemaLocations []string, opts Opts) Validator {
6367 }
6468
6569 if opts .SkipKinds == nil {
66- opts .SkipKinds = map [string ]bool {}
70+ opts .SkipKinds = map [string ]struct {} {}
6771 }
6872 if opts .RejectKinds == nil {
69- opts .RejectKinds = map [string ]bool {}
73+ opts .RejectKinds = map [string ]struct {} {}
7074 }
7175
7276 return & v {
@@ -88,8 +92,8 @@ type v struct {
8892// large resource streams using multiple Go Routines.
8993func (val * v ) ValidateResource (res resource.Resource ) Result {
9094 skip := func (signature resource.Signature ) bool {
91- isSkipKind , ok := val .opts .SkipKinds [signature .Kind ]
92- return ok && isSkipKind
95+ _ , ok := val .opts .SkipKinds [signature .Kind ]
96+ return ok
9397 }
9498
9599 reject := func (signature resource.Signature ) bool {
0 commit comments