mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-10 16:42:51 +00:00
Add RNode implementation of label and annotation selectors.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user