Skip to content

Resource Name Patterns

Source: hello-pepr-regex-name

.WithNameRegex() filters resources by their name using regular expressions instead of namespace names. This is useful for matching resources based on naming conventions without explicitly listing each name. Note that this matches the resource name itself, not the namespace name.

Use .WithNameRegex() to match resource names, not namespace names.

Do not use to match resource namespace names. To match with namespace names, see regex namespace-all.

View full example on Github

Match Resource Names Starting with “default”

Section titled “Match Resource Names Starting with “default””
When(a.ConfigMap)
.IsCreated()
.WithNameRegex(/^default/)
.Mutate(function mutateDef(request) {
request.SetAnnotation("def", "seen");
});

Match Resource Names Ending with “-default”

Section titled “Match Resource Names Ending with “-default””
When(a.ConfigMap)
.IsCreated()
.WithNameRegex(/-default$/)
.Mutate(function mutateNs(request) {
request.SetAnnotation("obviously", "seen");
});