-
Notifications
You must be signed in to change notification settings - Fork 57
Open
Description
Use case
When creating namespace configurations, there are scenarios where we want to match labels/annotations based on dynamic values derived from the namespace itself.
For example, a common pattern is to have ArgoCD instances managing namespaces where the instance name is derived from the namespace name:
metadata:
name: my-project
labels:
argocd.argoproj.io/managed-by: my-project-argo
Currently, we can't create a NamespaceConfig that matches based on this pattern without requiring additional trigger labels.
Proposed solution
Add a new field to the NamespaceConfig spec for template-based matching:
apiVersion: redhatcop.redhat.io/v1alpha1
kind: NamespaceConfig
metadata:
name: gitops-config
spec:
labelMatchTemplate:
argocd.argoproj.io/managed-by: "{{ .Name }}-argo"
templates:
- objectTemplate: |
apiVersion: v1
kind: Namespace
metadata:
name: {{ .Name }}-argo
This would allow the operator to:
- Evaluate the template expressions against the namespace
- Check if the resulting key-value pairs match the namespace's actual labels/annotations
Benefits
- More intuitive configurations that can use self-referential patterns
- Reduction in redundant labeling (no need for separate trigger labels)
- Better support for common patterns like ArgoCD management where instance names follow a convention
- More maintainable configurations as relationships are more explicit
Alternatives considered
- Using standard label selectors with
Exists
operator - less precise, can't validate naming convention - Using separate trigger labels - works but adds unnecessary complexity
- Using regexp matching - possible but less intuitive and harder to maintain
Would this feature be valuable to the project? Happy to provide more details or discuss alternative approaches.
Metadata
Metadata
Assignees
Labels
No labels