matcher

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package matcher provides functionality for building and composing functions for matching against various properties of resources.Resource objects based on user input.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AllMatcher

type AllMatcher struct {
	// contains filtered or unexported fields
}

AllMatcher wraps a sequence of Matcher instances and returns true if each of the wrapped Matcher instances returns true.

func (*AllMatcher) Append

func (m *AllMatcher) Append(matcher Matcher)

Append adds the given Matcher to the sequence of wrapped Matcher instances.

func (*AllMatcher) Matches

func (m *AllMatcher) Matches(item resources.Resource) bool

Matches returns true if each of the wrapped Matcher instances returns true.

type AnyMatcher

type AnyMatcher struct {
	// contains filtered or unexported fields
}

AnyMatcher wraps a sequence of Matcher instances and returns true if any of the wrapped Matcher instances returns true. An empty AnyMatcher will also return true.

func (*AnyMatcher) Append

func (m *AnyMatcher) Append(matcher Matcher)

Append adds the given Matcher to the sequence of wrapped Matcher instances.

func (*AnyMatcher) Matches

func (m *AnyMatcher) Matches(item resources.Resource) bool

Matches returns true if any of the wrapped Matcher instances returns true. An empty AnyMatcher will also return true.

type Matcher

type Matcher interface {
	// Matches returns true if the given resources.Resource object matches based
	// on the logic and inputs for a concrete matcher.
	Matches(item resources.Resource) bool
}

Matcher represents the logic for matching against the properties of a resources.Resource based on some inputs.

func NewAPIVersionMatcher

func NewAPIVersionMatcher(apiVersion string) (Matcher, error)

NewAPIVersionMatcher matches resources.Resource instances based on the given apiversion glob.

func NewAnnotationMatcher

func NewAnnotationMatcher(selector string) (Matcher, error)

NewAnnotationMatcher matches resources.Resource instances that contain the given annotation, and optionally matching a value for that annotation.

func NewCELMatcher added in v0.4.0

func NewCELMatcher(expression string) (Matcher, error)

NewCELMatcher matches resources.Resource instances based on the results of evaluating a boolean CEL expression.

func NewClusterScopedMatcher

func NewClusterScopedMatcher() Matcher

NewClusterScopedMatcher matches resources.Resource instances that are known (via the resolver) to be cluster-scoped. As a caveat, this matcher will not match unresolved resources even if they are cluster-scoped in reality.

func NewContainsMatcher

func NewContainsMatcher(substring string) (Matcher, error)

NewContainsMatcher matches resources.Resource instances that contain the given substring after being re-marshalled back into YAML. This also applies to resources that were originally decoded from JSON files. Additionally, these re-marshalled YAML documents no longer contain any of the original comments or other formatting.

func NewDiffMatcher

func NewDiffMatcher(filename string) (Matcher, error)

NewDiffMatcher matches resources.Resource instances that differ from companion resources decoded from the given filename. An example usage would be to save the output of `kustomize build` to a file, make refactors to the kustomize code, then rerun `kustomize build` to check if resources were changed.

func NewExecMatcher

func NewExecMatcher(command string) (Matcher, error)

NewExecMatcher matches resources.Resource instances based on the results of executing an external program.

func NewFieldPathMatcher added in v0.3.0

func NewFieldPathMatcher(selector string) (Matcher, error)

NewFieldPathMatcher matches resources.Resource instances that contain the given Kustomize-style fieldpath, and optionally matching a target value at that path.

func NewGitMatcher added in v0.4.0

func NewGitMatcher(pattern string) (Matcher, error)

NewGitMatcher matches resources.Resource instances based on the current git status of the underlying resource file.

func NewJsonpathMatcher

func NewJsonpathMatcher(selector string) (Matcher, error)

NewJsonpathMatcher matches resources.Resource instances that contain the given jsonpath, and optionally matching a target value at that path.

func NewKindMatcher

func NewKindMatcher(kind string) (Matcher, error)

NewKindMatcher matches resources.Resource instances based on the given kind which might be the kind verbatim, a glob, or a kind alias.

For example, a resource of kind `Service` would be matched by the input "Service", "svc", or "sv*".

func NewLabelMatcher

func NewLabelMatcher(selector string) (Matcher, error)

NewLabelMatcher matches resources.Resource instances that contain the given label, and optionally matching a value for that label.

func NewNameMatcher

func NewNameMatcher(name string) (Matcher, error)

NewNameMatcher matches resources.Resource instances based on the given name.

func NewNamespaceMatcher

func NewNamespaceMatcher(namespace string) (Matcher, error)

NewNamespaceMatcher matches resources.Resource instances based on the given namespace.

func NewNamespaceScopedMatcher

func NewNamespaceScopedMatcher() Matcher

NewNamespaceScopedMatcher matches resources.Resource instances that are known (via the resolver) to be namespace-scoped. As a caveat, this matcher will not match unresolved resources even if they are namespace-scoped in reality.

func NewPatchMatcher

func NewPatchMatcher() Matcher

NewPatchMatcher matches resources.Resource instances that were decoded from a kustomize patch file (the convention being a filename with the suffix `.patch.yaml`).

For example, a resource decoded from the file `kustomize/environments/production/deployment.patch.yaml` would be matched.

func NewPathMatcher

func NewPathMatcher(path string) (Matcher, error)

NewPathMatcher matches resources.Resource instances based on the given file path substring.

For example, a resource decoded from the file `kustomize/environments/production/deployment.yaml` would be matched by the input `environments/production` or `deployment.yaml`.

func NewReferenceMatcher

func NewReferenceMatcher(reference string) (Matcher, error)

NewReferenceMatcher matches resources.Resource instances that reference the given named resource. A name glob like "my-secret-*" can be used to match any reference to a resource with that name, or can include a kind like "cm/my-configmap-*" to match any reference to a resource with that kind and name.

func NewRegoMatcher added in v0.4.0

func NewRegoMatcher(filename string) (Matcher, error)

NewRegoMatcher matches resources.Resource instances based on an evaluation of the given rego file.

The rego file must have a package value of `krf.joshdk.github.com` and provide a rule named `matches` in order to match a resource.

func NewSelectorMatcher added in v0.4.0

func NewSelectorMatcher(selector string) (Matcher, error)

NewSelectorMatcher matches resources.Resource instances that match the given Kubernetes label selector.

func NotMatcher

func NotMatcher(matcher Matcher) Matcher

NotMatcher wraps the given Matcher instances and inverts its value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL