diff --git a/pkg/resource/resource.go b/pkg/resource/resource.go index 6bf9eed..102eabd 100644 --- a/pkg/resource/resource.go +++ b/pkg/resource/resource.go @@ -20,6 +20,18 @@ type Signature struct { Kind, Version, Namespace, Name string } +// GroupVersionKind returns a string with the GVK encoding of a resource signature. +// This encoding slightly differs from the Kubernetes upstream implementation +// in order to be suitable for being used in the kubeconform command-line arguments. +func (sig *Signature) GroupVersionKind() string { + return fmt.Sprintf("%s/%s", sig.Version, sig.Kind) +} + +// QualifiedName returns a string for a signature in the format version/kind/namespace/name +func (sig *Signature) QualifiedName() string { + return fmt.Sprintf("%s/%s/%s/%s", sig.Version, sig.Kind, sig.Namespace, sig.Name) +} + // Signature computes a signature for a resource, based on its Kind, Version, Namespace & Name func (res *Resource) Signature() (*Signature, error) { if res.sig != nil { @@ -119,8 +131,3 @@ func (res *Resource) Resources() []Resource { return []Resource{*res} } - -// QualifiedName returns a string for a signature in the format version/kind/namespace/name -func (sig *Signature) QualifiedName() string { - return fmt.Sprintf("%s/%s/%s/%s", sig.Version, sig.Kind, sig.Namespace, sig.Name) -} diff --git a/pkg/validator/validator.go b/pkg/validator/validator.go index f1ae723..09eeb53 100644 --- a/pkg/validator/validator.go +++ b/pkg/validator/validator.go @@ -98,12 +98,23 @@ type v struct { // ValidateResource validates a single resource. This allows to validate // large resource streams using multiple Go Routines. func (val *v) ValidateResource(res resource.Resource) Result { + // For backward compatibility reasons when determining whether + // a resource should be skipped or rejected we use both + // the GVK encoding of the resource signatures (the recommended method + // for skipping/rejecting resources) and the raw Kind. + skip := func(signature resource.Signature) bool { + if _, ok := val.opts.SkipKinds[signature.GroupVersionKind()]; ok { + return ok + } _, ok := val.opts.SkipKinds[signature.Kind] return ok } reject := func(signature resource.Signature) bool { + if _, ok := val.opts.RejectKinds[signature.GroupVersionKind()]; ok { + return ok + } _, ok := val.opts.RejectKinds[signature.Kind] return ok } diff --git a/pkg/validator/validator_test.go b/pkg/validator/validator_test.go index f78548a..f6fcd15 100644 --- a/pkg/validator/validator_test.go +++ b/pkg/validator/validator_test.go @@ -1,9 +1,10 @@ package validator import ( - "github.com/yannh/kubeconform/pkg/registry" "testing" + "github.com/yannh/kubeconform/pkg/registry" + "github.com/yannh/kubeconform/pkg/resource" )