Add RNode implementation of label and annotation selectors.

This commit is contained in:
jregan
2020-11-26 14:47:23 -08:00
parent a51e4234c4
commit 56c8df7b85
17 changed files with 2853 additions and 5 deletions

View File

@@ -12,6 +12,7 @@ import (
"gopkg.in/yaml.v3"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/yaml/internal/k8sgen/pkg/labels"
)
// MakeNullNode returns an RNode that represents an empty document.
@@ -690,6 +691,32 @@ func (rn *RNode) GetValidatedMetadata() (ResourceMeta, error) {
return m, nil
}
// MatchesAnnotationSelector implements ifc.Kunstructured.
func (rn *RNode) MatchesAnnotationSelector(selector string) (bool, error) {
s, err := labels.Parse(selector)
if err != nil {
return false, err
}
slice, err := rn.GetAnnotations()
if err != nil {
return false, err
}
return s.Matches(labels.Set(slice)), nil
}
// MatchesLabelSelector implements ifc.Kunstructured.
func (rn *RNode) MatchesLabelSelector(selector string) (bool, error) {
s, err := labels.Parse(selector)
if err != nil {
return false, err
}
slice, err := rn.GetLabels()
if err != nil {
return false, err
}
return s.Matches(labels.Set(slice)), nil
}
// HasNilEntryInList returns true if the RNode contains a list which has
// a nil item, along with the path to the missing item.
// TODO(broken): This was copied from