Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python

feat: component and pod level annotation and labels (#1546)

mingbec448c8dff3
diff --git a/kubernetes/operator/api/v1alpha1/openrag_types.go b/kubernetes/operator/api/v1alpha1/openrag_types.go
index 7bc167b67..bdec6645b 100644
--- a/kubernetes/operator/api/v1alpha1/openrag_types.go
+++ b/kubernetes/operator/api/v1alpha1/openrag_types.go
@@ -38,6 +38,50 @@ type ComponentSpec struct {
// +optional
Affinity *corev1.Affinity `json:"affinity,omitempty"`
+
+ // Labels are custom labels to add to the Deployment/StatefulSet object metadata.
+ // These labels appear on the workload resource itself, not the pods.
+ // Useful for querying and grouping Deployment/StatefulSet objects.
+ // Label keys must be valid Kubernetes label keys: optional prefix (DNS subdomain) + name.
+ // Label values must be 63 characters or less, alphanumeric with '-', '_', '.'.
+ // +optional
+ // +kubebuilder:validation:MaxProperties=64
+ // +kubebuilder:validation:XValidation:rule="self.all(key, size(key) <= 253 && (key.contains('/') ? key.split('/')[0].matches('^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\\.)*[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$') && key.split('/')[1].matches('^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$') : key.matches('^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$')))",message="label keys must be valid Kubernetes label keys (prefix/name or name)"
+ // +kubebuilder:validation:XValidation:rule="self.all(key, size(self[key]) <= 63 && self[key].matches('^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$'))",message="label values must be 63 characters or less and match regex ^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$"
+ Labels map[string]string `json:"labels,omitempty"`
+
+ // Annotations are custom annotations to add to the Deployment/StatefulSet object metadata.
+ // These annotations appear on the workload resource itself, not the pods.
+ // Useful for GitOps metadata, deployment tracking, and automation tools.
+ // Annotation keys must be valid Kubernetes annotation keys: optional prefix (DNS subdomain) + name.
+ // Annotation values can be arbitrary strings.
+ // +optional
+ // +kubebuilder:validation:MaxProperties=64
+ // +kubebuilder:validation:XValidation:rule="self.all(key, size(key) <= 253 && (key.contains('/') ? key.split('/')[0].matches('^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\\.)*[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$') && key.split('/')[1].matches('^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$') : key.matches('^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$')))",message="annotation keys must be valid Kubernetes annotation keys (prefix/name or name)"
+ Annotations map[string]string `json:"annotations,omitempty"`
+
+ // PodLabels are custom labels to add to the pod template.
+ // These labels appear on the actual pods created by the Deployment/StatefulSet.
+ // Useful for pod selectors, monitoring queries, network policies, and service mesh.
+ // Merged with operator-managed labels (app.kubernetes.io/*).
+ // Cannot override operator-managed labels.
+ // Label keys must be valid Kubernetes label keys: optional prefix (DNS subdomain) + name.
+ // Label values must be 63 characters or less, alphanumeric with '-', '_', '.'.
+ // +optional
+ // +kubebuilder:validation:MaxProperties=64
+ // +kubebuilder:validation:XValidation:rule="self.all(key, size(key) <= 253 && (key.contains('/') ? key.split('/')[0].matches('^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\\.)*[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$') && key.split('/')[1].matches('^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$') : key.matches('^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$')))",message="label keys must be valid Kubernetes label keys (prefix/name or name)"
+ // +kubebuilder:validation:XValidation:rule="self.all(key, size(self[key]) <= 63 && self[key].matches('^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$'))",message="label values must be 63 characters or less and match regex ^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$"
+ PodLabels map[string]string `json:"podLabels,omitempty"`
+
+ // PodAnnotations are custom annotations to add to the pod template.
+ // These annotations appear on the actual pods created by the Deployment/StatefulSet.
+ // Useful for sidecar injection (Istio, Vault), monitoring (Prometheus), and backup (Velero).
+ // Annotation keys must be valid Kubernetes annotation keys: optional prefix (DNS subdomain) + name.
+ // Annotation values can be arbitrary strings.
+ // +optional
+ // +kubebuilder:validation:MaxProperties=64
+ // +kubebuilder:validation:XValidation:rule="self.all(key, size(key) <= 253 && (key.contains('/') ? key.split('/')[0].matches('^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\\.)*[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$') && key.split('/')[1].matches('^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$') : key.matches('^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$')))",message="annotation keys must be valid Kubernetes annotation keys (prefix/name or name)"
+ PodAnnotations map[string]string `json:"podAnnotations,omitempty"`
}
// FrontendSpec configures the OpenRAG frontend (Next.js).
diff --git a/kubernetes/operator/api/v1alpha1/zz_generated.deepcopy.go b/kubernetes/operator/api/v1alpha1/zz_generated.deepcopy.go
index 09143d7d5..5b20fb9be 100644
--- a/kubernetes/operator/api/v1alpha1/zz_generated.deepcopy.go
+++ b/kubernetes/operator/api/v1alpha1/zz_generated.deepcopy.go
@@ -97,6 +97,34 @@ func (in *ComponentSpec) DeepCopyInto(out *ComponentSpec) {
*out = new(v1.Affinity)
(*in).DeepCopyInto(*out)
}
+ if in.Labels != nil {
+ in, out := &in.Labels, &out.Labels
+ *out = make(map[string]string, len(*in))
+ for key, val := range *in {
+ (*out)[key] = val
+ }
+ }
+ if in.Annotations != nil {
+ in, out := &in.Annotations, &out.Annotations
+ *out = make(map[string]string, len(*in))
+ for key, val := range *in {
+ (*out)[key] = val
+ }
+ }
+ if in.PodLabels != nil {
+ in, out := &in.PodLabels, &out.PodLabels
+ *out = make(map[string]string, len(*in))
+ for key, val := range *in {
+ (*out)[key] = val
+ }
+ }
+ if in.PodAnnotations != nil {
+ in, out := &in.PodAnnotations, &out.PodAnnotations
+ *out = make(map[string]string, len(*in))
+ for key, val := range *in {
+ (*out)[key] = val
+ }
+ }
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ComponentSpec.
diff --git a/kubernetes/operator/config/crd/bases/openr.ag_openrags.yaml b/kubernetes/operator/config/crd/bases/openr.ag_openrags.yaml
index dcedd261e..060ce7eb6 100644
--- a/kubernetes/operator/config/crd/bases/openr.ag_openrags.yaml
+++ b/kubernetes/operator/config/crd/bases/openr.ag_openrags.yaml
@@ -979,6 +979,24 @@ spec:
x-kubernetes-list-type: atomic
type: object
type: object
+ annotations:
+ additionalProperties:
+ type: string
+ description: |-
+ Annotations are custom annotations to add to the Deployment/StatefulSet object metadata.
+ These annotations appear on the workload resource itself, not the pods.
+ Useful for GitOps metadata, deployment tracking, and automation tools.
+ Annotation keys must be valid Kubernetes annotation keys: optional prefix (DNS subdomain) + name.
+ Annotation values can be arbitrary strings.
+ maxProperties: 64
+ type: object
+ x-kubernetes-validations:
+ - message: annotation keys must be valid Kubernetes annotation
+ keys (prefix/name or name)
+ rule: 'self.all(key, size(key) <= 253 && (key.contains(''/'')
+ ? key.split(''/'')[0].matches(''^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$'')
+ && key.split(''/'')[1].matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')
+ : key.matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')))'
encryptionKeySecret:
description: |-
EncryptionKeySecret references the Secret key for OPENRAG_ENCRYPTION_KEY.
@@ -1162,6 +1180,27 @@ spec:
- key
type: object
x-kubernetes-map-type: atomic
+ labels:
+ additionalProperties:
+ type: string
+ description: |-
+ Labels are custom labels to add to the Deployment/StatefulSet object metadata.
+ These labels appear on the workload resource itself, not the pods.
+ Useful for querying and grouping Deployment/StatefulSet objects.
+ Label keys must be valid Kubernetes label keys: optional prefix (DNS subdomain) + name.
+ Label values must be 63 characters or less, alphanumeric with '-', '_', '.'.
+ maxProperties: 64
+ type: object
+ x-kubernetes-validations:
+ - message: label keys must be valid Kubernetes label keys (prefix/name
+ or name)
+ rule: 'self.all(key, size(key) <= 253 && (key.contains(''/'')
+ ? key.split(''/'')[0].matches(''^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$'')
+ && key.split(''/'')[1].matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')
+ : key.matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')))'
+ - message: label values must be 63 characters or less and match
+ regex ^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$
+ rule: self.all(key, size(self[key]) <= 63 && self[key].matches('^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$'))
nodeSelector:
additionalProperties:
type: string
@@ -1236,6 +1275,47 @@ spec:
oauthBrokerUrl:
description: OAuthBrokerURL is the OAuth callback URL (OAUTH_BROKER_URL).
type: string
+ podAnnotations:
+ additionalProperties:
+ type: string
+ description: |-
+ PodAnnotations are custom annotations to add to the pod template.
+ These annotations appear on the actual pods created by the Deployment/StatefulSet.
+ Useful for sidecar injection (Istio, Vault), monitoring (Prometheus), and backup (Velero).
+ Annotation keys must be valid Kubernetes annotation keys: optional prefix (DNS subdomain) + name.
+ Annotation values can be arbitrary strings.
+ maxProperties: 64
+ type: object
+ x-kubernetes-validations:
+ - message: annotation keys must be valid Kubernetes annotation
+ keys (prefix/name or name)
+ rule: 'self.all(key, size(key) <= 253 && (key.contains(''/'')
+ ? key.split(''/'')[0].matches(''^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$'')
+ && key.split(''/'')[1].matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')
+ : key.matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')))'
+ podLabels:
+ additionalProperties:
+ type: string
+ description: |-
+ PodLabels are custom labels to add to the pod template.
+ These labels appear on the actual pods created by the Deployment/StatefulSet.
+ Useful for pod selectors, monitoring queries, network policies, and service mesh.
+ Merged with operator-managed labels (app.kubernetes.io/*).
+ Cannot override operator-managed labels.
+ Label keys must be valid Kubernetes label keys: optional prefix (DNS subdomain) + name.
+ Label values must be 63 characters or less, alphanumeric with '-', '_', '.'.
+ maxProperties: 64
+ type: object
+ x-kubernetes-validations:
+ - message: label keys must be valid Kubernetes label keys (prefix/name
+ or name)
+ rule: 'self.all(key, size(key) <= 253 && (key.contains(''/'')
+ ? key.split(''/'')[0].matches(''^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$'')
+ && key.split(''/'')[1].matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')
+ : key.matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')))'
+ - message: label values must be 63 characters or less and match
+ regex ^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$
+ rule: self.all(key, size(self[key]) <= 63 && self[key].matches('^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$'))
replicas:
default: 1
format: int32
@@ -2313,6 +2393,24 @@ spec:
x-kubernetes-list-type: atomic
type: object
type: object
+ annotations:
+ additionalProperties:
+ type: string
+ description: |-
+ Annotations are custom annotations to add to the Deployment/StatefulSet object metadata.
+ These annotations appear on the workload resource itself, not the pods.
+ Useful for GitOps metadata, deployment tracking, and automation tools.
+ Annotation keys must be valid Kubernetes annotation keys: optional prefix (DNS subdomain) + name.
+ Annotation values can be arbitrary strings.
+ maxProperties: 64
+ type: object
+ x-kubernetes-validations:
+ - message: annotation keys must be valid Kubernetes annotation
+ keys (prefix/name or name)
+ rule: 'self.all(key, size(key) <= 253 && (key.contains(''/'')
+ ? key.split(''/'')[0].matches(''^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$'')
+ && key.split(''/'')[1].matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')
+ : key.matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')))'
env:
description: Additional environment variables injected into the
container.
@@ -2442,10 +2540,72 @@ spec:
description: PullPolicy describes a policy for if/when to pull
a container image
type: string
+ labels:
+ additionalProperties:
+ type: string
+ description: |-
+ Labels are custom labels to add to the Deployment/StatefulSet object metadata.
+ These labels appear on the workload resource itself, not the pods.
+ Useful for querying and grouping Deployment/StatefulSet objects.
+ Label keys must be valid Kubernetes label keys: optional prefix (DNS subdomain) + name.
+ Label values must be 63 characters or less, alphanumeric with '-', '_', '.'.
+ maxProperties: 64
+ type: object
+ x-kubernetes-validations:
+ - message: label keys must be valid Kubernetes label keys (prefix/name
+ or name)
+ rule: 'self.all(key, size(key) <= 253 && (key.contains(''/'')
+ ? key.split(''/'')[0].matches(''^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$'')
+ && key.split(''/'')[1].matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')
+ : key.matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')))'
+ - message: label values must be 63 characters or less and match
+ regex ^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$
+ rule: self.all(key, size(self[key]) <= 63 && self[key].matches('^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$'))
nodeSelector:
additionalProperties:
type: string
type: object
+ podAnnotations:
+ additionalProperties:
+ type: string
+ description: |-
+ PodAnnotations are custom annotations to add to the pod template.
+ These annotations appear on the actual pods created by the Deployment/StatefulSet.
+ Useful for sidecar injection (Istio, Vault), monitoring (Prometheus), and backup (Velero).
+ Annotation keys must be valid Kubernetes annotation keys: optional prefix (DNS subdomain) + name.
+ Annotation values can be arbitrary strings.
+ maxProperties: 64
+ type: object
+ x-kubernetes-validations:
+ - message: annotation keys must be valid Kubernetes annotation
+ keys (prefix/name or name)
+ rule: 'self.all(key, size(key) <= 253 && (key.contains(''/'')
+ ? key.split(''/'')[0].matches(''^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$'')
+ && key.split(''/'')[1].matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')
+ : key.matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')))'
+ podLabels:
+ additionalProperties:
+ type: string
+ description: |-
+ PodLabels are custom labels to add to the pod template.
+ These labels appear on the actual pods created by the Deployment/StatefulSet.
+ Useful for pod selectors, monitoring queries, network policies, and service mesh.
+ Merged with operator-managed labels (app.kubernetes.io/*).
+ Cannot override operator-managed labels.
+ Label keys must be valid Kubernetes label keys: optional prefix (DNS subdomain) + name.
+ Label values must be 63 characters or less, alphanumeric with '-', '_', '.'.
+ maxProperties: 64
+ type: object
+ x-kubernetes-validations:
+ - message: label keys must be valid Kubernetes label keys (prefix/name
+ or name)
+ rule: 'self.all(key, size(key) <= 253 && (key.contains(''/'')
+ ? key.split(''/'')[0].matches(''^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$'')
+ && key.split(''/'')[1].matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')
+ : key.matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')))'
+ - message: label values must be 63 characters or less and match
+ regex ^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$
+ rule: self.all(key, size(self[key]) <= 63 && self[key].matches('^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$'))
replicas:
default: 1
format: int32
@@ -3494,6 +3654,24 @@ spec:
x-kubernetes-list-type: atomic
type: object
type: object
+ annotations:
+ additionalProperties:
+ type: string
+ description: |-
+ Annotations are custom annotations to add to the Deployment/StatefulSet object metadata.
+ These annotations appear on the workload resource itself, not the pods.
+ Useful for GitOps metadata, deployment tracking, and automation tools.
+ Annotation keys must be valid Kubernetes annotation keys: optional prefix (DNS subdomain) + name.
+ Annotation values can be arbitrary strings.
+ maxProperties: 64
+ type: object
+ x-kubernetes-validations:
+ - message: annotation keys must be valid Kubernetes annotation
+ keys (prefix/name or name)
+ rule: 'self.all(key, size(key) <= 253 && (key.contains(''/'')
+ ? key.split(''/'')[0].matches(''^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$'')
+ && key.split(''/'')[1].matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')
+ : key.matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')))'
env:
description: Additional environment variables injected into the
container.
@@ -3635,10 +3813,72 @@ spec:
description: PullPolicy describes a policy for if/when to pull
a container image
type: string
+ labels:
+ additionalProperties:
+ type: string
+ description: |-
+ Labels are custom labels to add to the Deployment/StatefulSet object metadata.
+ These labels appear on the workload resource itself, not the pods.
+ Useful for querying and grouping Deployment/StatefulSet objects.
+ Label keys must be valid Kubernetes label keys: optional prefix (DNS subdomain) + name.
+ Label values must be 63 characters or less, alphanumeric with '-', '_', '.'.
+ maxProperties: 64
+ type: object
+ x-kubernetes-validations:
+ - message: label keys must be valid Kubernetes label keys (prefix/name
+ or name)
+ rule: 'self.all(key, size(key) <= 253 && (key.contains(''/'')
+ ? key.split(''/'')[0].matches(''^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$'')
+ && key.split(''/'')[1].matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')
+ : key.matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')))'
+ - message: label values must be 63 characters or less and match
+ regex ^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$
+ rule: self.all(key, size(self[key]) <= 63 && self[key].matches('^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$'))
nodeSelector:
additionalProperties:
type: string
type: object
+ podAnnotations:
+ additionalProperties:
+ type: string
+ description: |-
+ PodAnnotations are custom annotations to add to the pod template.
+ These annotations appear on the actual pods created by the Deployment/StatefulSet.
+ Useful for sidecar injection (Istio, Vault), monitoring (Prometheus), and backup (Velero).
+ Annotation keys must be valid Kubernetes annotation keys: optional prefix (DNS subdomain) + name.
+ Annotation values can be arbitrary strings.
+ maxProperties: 64
+ type: object
+ x-kubernetes-validations:
+ - message: annotation keys must be valid Kubernetes annotation
+ keys (prefix/name or name)
+ rule: 'self.all(key, size(key) <= 253 && (key.contains(''/'')
+ ? key.split(''/'')[0].matches(''^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$'')
+ && key.split(''/'')[1].matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')
+ : key.matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')))'
+ podLabels:
+ additionalProperties:
+ type: string
+ description: |-
+ PodLabels are custom labels to add to the pod template.
+ These labels appear on the actual pods created by the Deployment/StatefulSet.
+ Useful for pod selectors, monitoring queries, network policies, and service mesh.
+ Merged with operator-managed labels (app.kubernetes.io/*).
+ Cannot override operator-managed labels.
+ Label keys must be valid Kubernetes label keys: optional prefix (DNS subdomain) + name.
+ Label values must be 63 characters or less, alphanumeric with '-', '_', '.'.
+ maxProperties: 64
+ type: object
+ x-kubernetes-validations:
+ - message: label keys must be valid Kubernetes label keys (prefix/name
+ or name)
+ rule: 'self.all(key, size(key) <= 253 && (key.contains(''/'')
+ ? key.split(''/'')[0].matches(''^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$'')
+ && key.split(''/'')[1].matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')
+ : key.matches(''^([A-Za-z0-9][-A-Za-z0-9_.]{0,61})?[A-Za-z0-9]$'')))'
+ - message: label values must be 63 characters or less and match
+ regex ^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$
+ rule: self.all(key, size(self[key]) <= 63 && self[key].matches('^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$'))
replicas:
default: 1
format: int32
diff --git a/kubernetes/operator/internal/controller/openrag_controller.go b/kubernetes/operator/internal/controller/openrag_controller.go
index b6d11b3f0..5843041cd 100644
--- a/kubernetes/operator/internal/controller/openrag_controller.go
+++ b/kubernetes/operator/internal/controller/openrag_controller.go
@@ -164,7 +164,7 @@ func (r *OpenRAGReconciler) reconcileServiceAccounts(ctx context.Context, o *ope
for _, role := range []string{"fe", "be", "lf"} {
sa := &corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
- Name: saName(o.Name, role),
+ Name: saName(role),
Namespace: targetNS,
Labels: componentLabels(o.Name, role),
},
@@ -310,12 +310,12 @@ func (r *OpenRAGReconciler) getOrCreateLangflowSecretKey(ctx context.Context, o
// from CR fields and fixed runtime defaults.
func (r *OpenRAGReconciler) reconcileEnvSecrets(ctx context.Context, o *openragv1alpha1.OpenRAG, targetNS string) error {
// Get or create encryption keys
- backendEncryptionKey, err := r.getOrCreateEncryptionKey(ctx, o, targetNS, "openrag-be-encryption-key", "OPENRAG_ENCRYPTION_KEY", resourceName(o.Name, "be-env"))
+ backendEncryptionKey, err := r.getOrCreateEncryptionKey(ctx, o, targetNS, "openrag-be-encryption-key", "OPENRAG_ENCRYPTION_KEY", resourceName("be-env"))
if err != nil {
return fmt.Errorf("failed to get backend encryption key: %w", err)
}
- langflowSecretKey, err := r.getOrCreateLangflowSecretKey(ctx, o, targetNS, "langflow-secret-key", "LANGFLOW_SECRET_KEY", resourceName(o.Name, "lf-env"))
+ langflowSecretKey, err := r.getOrCreateLangflowSecretKey(ctx, o, targetNS, "langflow-secret-key", "LANGFLOW_SECRET_KEY", resourceName("lf-env"))
if err != nil {
return fmt.Errorf("failed to get langflow secret key: %w", err)
}
@@ -325,8 +325,8 @@ func (r *OpenRAGReconciler) reconcileEnvSecrets(ctx context.Context, o *openragv
content string
}
defs := []envDef{
- {resourceName(o.Name, "be-env"), r.buildBackendEnv(o, backendEncryptionKey)},
- {resourceName(o.Name, "lf-env"), r.buildLangflowEnv(o, langflowSecretKey)},
+ {resourceName("be-env"), r.buildBackendEnv(o, backendEncryptionKey)},
+ {resourceName("lf-env"), r.buildLangflowEnv(o, langflowSecretKey)},
}
for _, d := range defs {
secret := &corev1.Secret{
@@ -355,7 +355,7 @@ func (r *OpenRAGReconciler) buildBackendEnv(o *openragv1alpha1.OpenRAG, encrypti
envVars["OPENRAG_ENCRYPTION_KEY"] = encryptionKey
// Operator-derived values (always set)
- envVars["LANGFLOW_URL"] = "http://" + resourceName(o.Name, "lf") + ":7860"
+ envVars["LANGFLOW_URL"] = "http://" + resourceName("lf") + ":7860"
// Override with CR-specific configuration
if o.Spec.TenantID != "" {
@@ -518,8 +518,8 @@ func (r *OpenRAGReconciler) reconcilePVCs(ctx context.Context, o *openragv1alpha
storage *openragv1alpha1.PersistenceSpec
}
defs := []pvcDef{
- {resourceName(o.Name, "lf-data"), o.Spec.Langflow.Storage},
- {resourceName(o.Name, "be-data"), o.Spec.Backend.Storage},
+ {resourceName("lf-data"), o.Spec.Langflow.Storage},
+ {resourceName("be-data"), o.Spec.Backend.Storage},
}
for _, d := range defs {
if d.storage == nil || !d.storage.Enabled || d.storage.ExistingClaim != "" {
@@ -572,7 +572,7 @@ func (r *OpenRAGReconciler) reconcileServices(ctx context.Context, o *openragv1a
for _, d := range defs {
svc := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
- Name: resourceName(o.Name, d.role),
+ Name: resourceName(d.role),
Namespace: targetNS,
Labels: componentLabels(o.Name, d.role),
},
@@ -614,20 +614,29 @@ func (r *OpenRAGReconciler) reconcileDeployments(ctx context.Context, o *openrag
func (r *OpenRAGReconciler) frontendDeployment(o *openragv1alpha1.OpenRAG, targetNS string) *appsv1.Deployment {
spec := o.Spec.Frontend
replicas := replicasOrDefault(spec.Replicas)
+ baseLabels := componentLabels(o.Name, "fe")
+ deploymentLabels := mergeDeploymentLabels(baseLabels, spec.Labels)
+ deploymentAnnotations := mergeDeploymentAnnotations(spec.Annotations)
+ podLabels := mergePodLabels(baseLabels, spec.PodLabels)
+ podAnnotations := mergePodAnnotations(spec.PodAnnotations)
return &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
- Name: resourceName(o.Name, "fe"),
- Namespace: targetNS,
- Labels: componentLabels(o.Name, "fe"),
+ Name: resourceName("fe"),
+ Namespace: targetNS,
+ Labels: deploymentLabels,
+ Annotations: deploymentAnnotations,
},
Spec: appsv1.DeploymentSpec{
Replicas: &replicas,
- Selector: &metav1.LabelSelector{MatchLabels: componentLabels(o.Name, "fe")},
+ Selector: &metav1.LabelSelector{MatchLabels: baseLabels},
Strategy: appsv1.DeploymentStrategy{Type: appsv1.RecreateDeploymentStrategyType},
Template: corev1.PodTemplateSpec{
- ObjectMeta: metav1.ObjectMeta{Labels: componentLabels(o.Name, "fe")},
+ ObjectMeta: metav1.ObjectMeta{
+ Labels: podLabels,
+ Annotations: podAnnotations,
+ },
Spec: corev1.PodSpec{
- ServiceAccountName: saName(o.Name, "fe"),
+ ServiceAccountName: saName("fe"),
ImagePullSecrets: o.Spec.ImagePullSecrets,
NodeSelector: spec.NodeSelector,
Tolerations: spec.Tolerations,
@@ -639,7 +648,7 @@ func (r *OpenRAGReconciler) frontendDeployment(o *openragv1alpha1.OpenRAG, targe
ImagePullPolicy: spec.ImagePullPolicy,
Ports: []corev1.ContainerPort{{Name: "http", ContainerPort: 3000}},
Env: append([]corev1.EnvVar{
- {Name: "OPENRAG_BACKEND_HOST", Value: resourceName(o.Name, "be")},
+ {Name: "OPENRAG_BACKEND_HOST", Value: resourceName("be")},
}, spec.Env...),
Resources: spec.Resources,
LivenessProbe: httpProbe("/", 3000, 30, 10),
@@ -664,7 +673,7 @@ func (r *OpenRAGReconciler) backendDeployment(o *openragv1alpha1.OpenRAG, target
{
Name: "backend-env",
VolumeSource: corev1.VolumeSource{
- Secret: &corev1.SecretVolumeSource{SecretName: resourceName(o.Name, "be-env")},
+ Secret: &corev1.SecretVolumeSource{SecretName: resourceName("be-env")},
},
},
}
@@ -674,7 +683,7 @@ func (r *OpenRAGReconciler) backendDeployment(o *openragv1alpha1.OpenRAG, target
}
if spec.Storage != nil && spec.Storage.Enabled {
- pvcName := resourceName(o.Name, "be-data")
+ pvcName := resourceName("be-data")
if spec.Storage.ExistingClaim != "" {
pvcName = spec.Storage.ExistingClaim
}
@@ -696,20 +705,29 @@ func (r *OpenRAGReconciler) backendDeployment(o *openragv1alpha1.OpenRAG, target
}
envVars = append(envVars, spec.Env...)
+ baseLabels := componentLabels(o.Name, "be")
+ deploymentLabels := mergeDeploymentLabels(baseLabels, spec.Labels)
+ deploymentAnnotations := mergeDeploymentAnnotations(spec.Annotations)
+ podLabels := mergePodLabels(baseLabels, spec.PodLabels)
+ podAnnotations := mergePodAnnotations(spec.PodAnnotations)
return &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
- Name: resourceName(o.Name, "be"),
- Namespace: targetNS,
- Labels: componentLabels(o.Name, "be"),
+ Name: resourceName("be"),
+ Namespace: targetNS,
+ Labels: deploymentLabels,
+ Annotations: deploymentAnnotations,
},
Spec: appsv1.DeploymentSpec{
Replicas: &replicas,
- Selector: &metav1.LabelSelector{MatchLabels: componentLabels(o.Name, "be")},
+ Selector: &metav1.LabelSelector{MatchLabels: baseLabels},
Strategy: appsv1.DeploymentStrategy{Type: appsv1.RecreateDeploymentStrategyType},
Template: corev1.PodTemplateSpec{
- ObjectMeta: metav1.ObjectMeta{Labels: componentLabels(o.Name, "be")},
+ ObjectMeta: metav1.ObjectMeta{
+ Labels: podLabels,
+ Annotations: podAnnotations,
+ },
Spec: corev1.PodSpec{
- ServiceAccountName: saName(o.Name, "be"),
+ ServiceAccountName: saName("be"),
ImagePullSecrets: o.Spec.ImagePullSecrets,
NodeSelector: spec.NodeSelector,
Tolerations: spec.Tolerations,
@@ -808,7 +826,7 @@ func (r *OpenRAGReconciler) langflowDeployment(o *openragv1alpha1.OpenRAG, targe
{
Name: "langflow-env",
VolumeSource: corev1.VolumeSource{
- Secret: &corev1.SecretVolumeSource{SecretName: resourceName(o.Name, "lf-env")},
+ Secret: &corev1.SecretVolumeSource{SecretName: resourceName("lf-env")},
},
},
}
@@ -818,7 +836,7 @@ func (r *OpenRAGReconciler) langflowDeployment(o *openragv1alpha1.OpenRAG, targe
}
if spec.Storage != nil && spec.Storage.Enabled {
- pvcName := resourceName(o.Name, "lf-data")
+ pvcName := resourceName("lf-data")
if spec.Storage.ExistingClaim != "" {
pvcName = spec.Storage.ExistingClaim
}
@@ -861,20 +879,29 @@ func (r *OpenRAGReconciler) langflowDeployment(o *openragv1alpha1.OpenRAG, targe
envVars := r.langflowSensitiveEnvVars(o)
envVars = append(envVars, spec.Env...)
+ baseLabels := componentLabels(o.Name, "lf")
+ deploymentLabels := mergeDeploymentLabels(baseLabels, spec.Labels)
+ deploymentAnnotations := mergeDeploymentAnnotations(spec.Annotations)
+ podLabels := mergePodLabels(baseLabels, spec.PodLabels)
+ podAnnotations := mergePodAnnotations(spec.PodAnnotations)
return &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
- Name: resourceName(o.Name, "lf"),
- Namespace: targetNS,
- Labels: componentLabels(o.Name, "lf"),
+ Name: resourceName("lf"),
+ Namespace: targetNS,
+ Labels: deploymentLabels,
+ Annotations: deploymentAnnotations,
},
Spec: appsv1.DeploymentSpec{
Replicas: &replicas,
- Selector: &metav1.LabelSelector{MatchLabels: componentLabels(o.Name, "lf")},
+ Selector: &metav1.LabelSelector{MatchLabels: baseLabels},
Strategy: appsv1.DeploymentStrategy{Type: appsv1.RecreateDeploymentStrategyType},
Template: corev1.PodTemplateSpec{
- ObjectMeta: metav1.ObjectMeta{Labels: componentLabels(o.Name, "lf")},
+ ObjectMeta: metav1.ObjectMeta{
+ Labels: podLabels,
+ Annotations: podAnnotations,
+ },
Spec: corev1.PodSpec{
- ServiceAccountName: saName(o.Name, "lf"),
+ ServiceAccountName: saName("lf"),
ImagePullSecrets: o.Spec.ImagePullSecrets,
NodeSelector: spec.NodeSelector,
Tolerations: spec.Tolerations,
@@ -963,7 +990,7 @@ func (r *OpenRAGReconciler) reconcileNetworkPolicy(ctx context.Context, o *openr
np := &networkingv1.NetworkPolicy{
ObjectMeta: metav1.ObjectMeta{
- Name: resourceName(o.Name, "lf-netpol"),
+ Name: resourceName("lf-netpol"),
Namespace: targetNS,
Labels: labels,
},
@@ -1111,12 +1138,17 @@ func targetNamespace(o *openragv1alpha1.OpenRAG) string {
return o.Namespace
}
-func resourceName(crName, role string) string {
- return crName + "-openrag-" + role
+// resourceName generates a DNS-1035 compliant name for Kubernetes resources.
+// Since each namespace is tenant-exclusive, we don't need to include the CR name.
+// This provides clean, predictable names: openrag-fe, openrag-be, openrag-lf.
+func resourceName(role string) string {
+ return "openrag-" + role
}
-func saName(crName, role string) string {
- return "openrag-" + crName + "-" + role
+// saName generates service account names.
+// Since each namespace is tenant-exclusive, we don't need to include the CR name.
+func saName(role string) string {
+ return "openrag-" + role
}
func componentLabels(crName, role string) map[string]string {
@@ -1128,6 +1160,51 @@ func componentLabels(crName, role string) map[string]string {
}
}
+// mergeLabels merges custom labels with base labels.
+// Base labels always take precedence over custom labels.
+func mergeLabels(baseLabels, customLabels map[string]string) map[string]string {
+ merged := make(map[string]string)
+ // Start with custom labels
+ for k, v := range customLabels {
+ merged[k] = v
+ }
+ // Base labels always override
+ for k, v := range baseLabels {
+ merged[k] = v
+ }
+ return merged
+}
+
+// mergeAnnotations merges custom annotations.
+func mergeAnnotations(customAnnotations map[string]string) map[string]string {
+ merged := make(map[string]string)
+ for k, v := range customAnnotations {
+ merged[k] = v
+ }
+ return merged
+}
+
+// mergePodLabels merges custom user labels with operator-managed labels for pod templates.
+// Operator-managed labels (app.kubernetes.io/*) cannot be overridden.
+func mergePodLabels(baseLabels, customLabels map[string]string) map[string]string {
+ return mergeLabels(baseLabels, customLabels)
+}
+
+// mergePodAnnotations merges custom user annotations for pod templates.
+func mergePodAnnotations(customAnnotations map[string]string) map[string]string {
+ return mergeAnnotations(customAnnotations)
+}
+
+// mergeDeploymentLabels merges custom labels with base labels for Deployment/StatefulSet objects.
+func mergeDeploymentLabels(baseLabels, customLabels map[string]string) map[string]string {
+ return mergeLabels(baseLabels, customLabels)
+}
+
+// mergeDeploymentAnnotations merges custom annotations for Deployment/StatefulSet objects.
+func mergeDeploymentAnnotations(customAnnotations map[string]string) map[string]string {
+ return mergeAnnotations(customAnnotations)
+}
+
func replicasOrDefault(r *int32) int32 {
if r != nil {
return *r
diff --git a/kubernetes/operator/internal/controller/openrag_controller_test.go b/kubernetes/operator/internal/controller/openrag_controller_test.go
index e7ee3db79..05caa40a4 100644
--- a/kubernetes/operator/internal/controller/openrag_controller_test.go
+++ b/kubernetes/operator/internal/controller/openrag_controller_test.go
@@ -87,13 +87,20 @@ func TestTargetNamespace_UsesSpecField(t *testing.T) {
// ---------------------------------------------------------------------------
func TestResourceName(t *testing.T) {
- assert.Equal(t, "my-openrag-openrag-fe", resourceName("my-openrag", "fe"))
- assert.Equal(t, "my-openrag-openrag-be", resourceName("my-openrag", "be"))
- assert.Equal(t, "my-openrag-openrag-lf", resourceName("my-openrag", "lf"))
+ // Test simple, namespace-scoped names (no CR name prefix needed)
+ assert.Equal(t, "openrag-fe", resourceName("fe"))
+ assert.Equal(t, "openrag-be", resourceName("be"))
+ assert.Equal(t, "openrag-lf", resourceName("lf"))
+ // Test DNS-1035 compliance (must start with letter)
+ assert.Regexp(t, `^[a-z]([-a-z0-9]*[a-z0-9])?$`, resourceName("fe"))
+ assert.Regexp(t, `^[a-z]([-a-z0-9]*[a-z0-9])?$`, resourceName("be"))
}
func TestSAName(t *testing.T) {
- assert.Equal(t, "openrag-my-openrag-fe", saName("my-openrag", "fe"))
+ // Service accounts also use simple, namespace-scoped names
+ assert.Equal(t, "openrag-fe", saName("fe"))
+ assert.Equal(t, "openrag-be", saName("be"))
+ assert.Equal(t, "openrag-lf", saName("lf"))
}
// ---------------------------------------------------------------------------
@@ -110,7 +117,7 @@ func TestReconcile_CreatesDeployments(t *testing.T) {
for _, role := range []string{"fe", "be", "lf"} {
d := &appsv1.Deployment{}
require.NoError(t, c.Get(context.Background(),
- types.NamespacedName{Name: resourceName(cr.Name, role), Namespace: "my-ns"}, d),
+ types.NamespacedName{Name: resourceName(role), Namespace: "my-ns"}, d),
"deployment for role %s should exist", role)
}
}
@@ -126,7 +133,7 @@ func TestReconcile_CreatesServices(t *testing.T) {
for role, port := range ports {
svc := &corev1.Service{}
require.NoError(t, c.Get(context.Background(),
- types.NamespacedName{Name: resourceName(cr.Name, role), Namespace: "my-ns"}, svc))
+ types.NamespacedName{Name: resourceName(role), Namespace: "my-ns"}, svc))
assert.Equal(t, port, svc.Spec.Ports[0].Port, "service port for role %s", role)
}
}
@@ -141,7 +148,7 @@ func TestReconcile_CreatesServiceAccounts(t *testing.T) {
for _, role := range []string{"fe", "be", "lf"} {
sa := &corev1.ServiceAccount{}
require.NoError(t, c.Get(context.Background(),
- types.NamespacedName{Name: saName(cr.Name, role), Namespace: "my-ns"}, sa),
+ types.NamespacedName{Name: saName(role), Namespace: "my-ns"}, sa),
"service account for role %s should exist", role)
}
}
@@ -155,7 +162,7 @@ func TestReconcile_SetsOwnerReferences_SameNamespace(t *testing.T) {
d := &appsv1.Deployment{}
require.NoError(t, c.Get(context.Background(),
- types.NamespacedName{Name: resourceName(cr.Name, "fe"), Namespace: "my-ns"}, d))
+ types.NamespacedName{Name: resourceName("fe"), Namespace: "my-ns"}, d))
require.Len(t, d.OwnerReferences, 1)
assert.Equal(t, cr.Name, d.OwnerReferences[0].Name)
}
@@ -169,7 +176,7 @@ func TestReconcile_FrontendEnvContainsBackendHost(t *testing.T) {
d := &appsv1.Deployment{}
require.NoError(t, c.Get(context.Background(),
- types.NamespacedName{Name: resourceName(cr.Name, "fe"), Namespace: "my-ns"}, d))
+ types.NamespacedName{Name: resourceName("fe"), Namespace: "my-ns"}, d))
var backendHost string
for _, e := range d.Spec.Template.Spec.Containers[0].Env {
@@ -177,7 +184,7 @@ func TestReconcile_FrontendEnvContainsBackendHost(t *testing.T) {
backendHost = e.Value
}
}
- assert.Equal(t, resourceName(cr.Name, "be"), backendHost)
+ assert.Equal(t, resourceName("be"), backendHost)
}
func TestReconcile_BackendMountsOperatorManagedEnvSecret(t *testing.T) {
@@ -189,9 +196,9 @@ func TestReconcile_BackendMountsOperatorManagedEnvSecret(t *testing.T) {
d := &appsv1.Deployment{}
require.NoError(t, c.Get(context.Background(),
- types.NamespacedName{Name: resourceName(cr.Name, "be"), Namespace: "my-ns"}, d))
+ types.NamespacedName{Name: resourceName("be"), Namespace: "my-ns"}, d))
- expectedSecret := resourceName(cr.Name, "be-env")
+ expectedSecret := resourceName("be-env")
var found bool
for _, v := range d.Spec.Template.Spec.Volumes {
if v.Name == "backend-env" {
@@ -211,7 +218,7 @@ func TestReconcile_BackendEnvContainsLangflowURL(t *testing.T) {
sec := &corev1.Secret{}
require.NoError(t, c.Get(context.Background(),
- types.NamespacedName{Name: resourceName(cr.Name, "be-env"), Namespace: "my-ns"}, sec))
+ types.NamespacedName{Name: resourceName("be-env"), Namespace: "my-ns"}, sec))
// In the test environment, StringData is not converted to Data
// Use StringData if Data is empty (test env), otherwise use Data (real cluster)
@@ -219,7 +226,7 @@ func TestReconcile_BackendEnvContainsLangflowURL(t *testing.T) {
if envContent == "" && sec.StringData != nil {
envContent = sec.StringData[".env"]
}
- assert.Contains(t, envContent, "LANGFLOW_URL=http://"+resourceName(cr.Name, "lf")+":7860")
+ assert.Contains(t, envContent, "LANGFLOW_URL=http://"+resourceName("lf")+":7860")
}
func TestReconcile_LangflowMountsPVC(t *testing.T) {
@@ -233,12 +240,12 @@ func TestReconcile_LangflowMountsPVC(t *testing.T) {
d := &appsv1.Deployment{}
require.NoError(t, c.Get(context.Background(),
- types.NamespacedName{Name: resourceName(cr.Name, "lf"), Namespace: "my-ns"}, d))
+ types.NamespacedName{Name: resourceName("lf"), Namespace: "my-ns"}, d))
var found bool
for _, v := range d.Spec.Template.Spec.Volumes {
if v.Name == "langflow-data" {
- assert.Equal(t, resourceName(cr.Name, "lf-data"), v.PersistentVolumeClaim.ClaimName)
+ assert.Equal(t, resourceName("lf-data"), v.PersistentVolumeClaim.ClaimName)
found = true
}
}
@@ -305,7 +312,7 @@ func TestReconcile_ResourcesInTargetNamespace(t *testing.T) {
d := &appsv1.Deployment{}
require.NoError(t, c.Get(context.Background(),
- types.NamespacedName{Name: resourceName(cr.Name, "fe"), Namespace: "tenant-ns"}, d))
+ types.NamespacedName{Name: resourceName("fe"), Namespace: "tenant-ns"}, d))
// Cross-namespace: no owner references, managed-by label instead.
assert.Empty(t, d.OwnerReferences)
assert.Equal(t, cr.Name, d.Labels[managedByLabel])
@@ -390,3 +397,405 @@ func TestReconcile_Deletion_SkipsUnmanagedNamespace(t *testing.T) {
remaining := &corev1.Namespace{}
require.NoError(t, c.Get(context.Background(), types.NamespacedName{Name: "tenant-ns"}, remaining))
}
+
+// ---------------------------------------------------------------------------
+// Labels and Annotations (Deployment and Pod level)
+// ---------------------------------------------------------------------------
+
+func TestMergeDeploymentLabels_CustomLabelsAreMerged(t *testing.T) {
+ baseLabels := map[string]string{
+ "app.kubernetes.io/name": "openrag",
+ "app.kubernetes.io/instance": "test",
+ "app.kubernetes.io/component": "fe",
+ }
+ customLabels := map[string]string{
+ "deployment-label": "deployment-value",
+ "argocd.argoproj.io/instance": "my-app",
+ }
+
+ merged := mergeDeploymentLabels(baseLabels, customLabels)
+
+ // Custom labels should be present
+ assert.Equal(t, "deployment-value", merged["deployment-label"])
+ assert.Equal(t, "my-app", merged["argocd.argoproj.io/instance"])
+
+ // Operator-managed labels should be present
+ assert.Equal(t, "openrag", merged["app.kubernetes.io/name"])
+ assert.Equal(t, "test", merged["app.kubernetes.io/instance"])
+}
+
+func TestMergeDeploymentAnnotations_CustomAnnotationsAreMerged(t *testing.T) {
+ customAnnotations := map[string]string{
+ "deployment.kubernetes.io/revision": "5",
+ "meta.helm.sh/release-name": "my-release",
+ }
+
+ merged := mergeDeploymentAnnotations(customAnnotations)
+
+ assert.Equal(t, "5", merged["deployment.kubernetes.io/revision"])
+ assert.Equal(t, "my-release", merged["meta.helm.sh/release-name"])
+}
+
+func TestMergePodLabels_CustomLabelsAreMerged(t *testing.T) {
+ baseLabels := map[string]string{
+ "app.kubernetes.io/name": "openrag",
+ "app.kubernetes.io/instance": "test",
+ "app.kubernetes.io/component": "fe",
+ }
+ customLabels := map[string]string{
+ "custom-label": "custom-value",
+ "another-label": "another-value",
+ "prometheus.io/scrape": "true",
+ }
+
+ merged := mergePodLabels(baseLabels, customLabels)
+
+ // Custom labels should be present
+ assert.Equal(t, "custom-value", merged["custom-label"])
+ assert.Equal(t, "another-value", merged["another-label"])
+ assert.Equal(t, "true", merged["prometheus.io/scrape"])
+
+ // Operator-managed labels should be present
+ assert.Equal(t, "openrag", merged["app.kubernetes.io/name"])
+ assert.Equal(t, "test", merged["app.kubernetes.io/instance"])
+ assert.Equal(t, "fe", merged["app.kubernetes.io/component"])
+}
+
+func TestMergePodLabels_OperatorLabelsCannotBeOverridden(t *testing.T) {
+ baseLabels := map[string]string{
+ "app.kubernetes.io/name": "openrag",
+ "app.kubernetes.io/instance": "test",
+ }
+ customLabels := map[string]string{
+ "app.kubernetes.io/name": "hacked", // Try to override
+ "app.kubernetes.io/instance": "evil", // Try to override
+ }
+
+ merged := mergePodLabels(baseLabels, customLabels)
+
+ // Operator labels should win
+ assert.Equal(t, "openrag", merged["app.kubernetes.io/name"])
+ assert.Equal(t, "test", merged["app.kubernetes.io/instance"])
+}
+
+func TestMergePodAnnotations_CustomAnnotationsAreMerged(t *testing.T) {
+ customAnnotations := map[string]string{
+ "prometheus.io/scrape": "true",
+ "prometheus.io/port": "8080",
+ "custom-annotation": "value",
+ }
+
+ merged := mergePodAnnotations(customAnnotations)
+
+ assert.Equal(t, "true", merged["prometheus.io/scrape"])
+ assert.Equal(t, "8080", merged["prometheus.io/port"])
+ assert.Equal(t, "value", merged["custom-annotation"])
+}
+
+func TestReconcile_FrontendCustomPodLabels(t *testing.T) {
+ s := newScheme(t)
+ cr := minimalCR("my-openrag", "my-ns")
+ cr.Spec.Frontend.PodLabels = map[string]string{
+ "team": "platform",
+ "prometheus.io/scrape": "true",
+ }
+ r, c := reconciler(s, cr)
+
+ reconcileOnce(t, r, cr)
+
+ d := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("fe"), Namespace: "my-ns"}, d))
+
+ podLabels := d.Spec.Template.Labels
+
+ // Custom labels should be present
+ assert.Equal(t, "platform", podLabels["team"])
+ assert.Equal(t, "true", podLabels["prometheus.io/scrape"])
+
+ // Operator-managed labels should still be present
+ assert.Equal(t, "openrag", podLabels["app.kubernetes.io/name"])
+ assert.Equal(t, "my-openrag", podLabels["app.kubernetes.io/instance"])
+ assert.Equal(t, "fe", podLabels["app.kubernetes.io/component"])
+ assert.Equal(t, "openrag-operator", podLabels["app.kubernetes.io/managed-by"])
+}
+
+func TestReconcile_BackendCustomPodAnnotations(t *testing.T) {
+ s := newScheme(t)
+ cr := minimalCR("my-openrag", "my-ns")
+ cr.Spec.Backend.PodAnnotations = map[string]string{
+ "prometheus.io/scrape": "true",
+ "prometheus.io/port": "8000",
+ "custom-annotation": "backend-value",
+ }
+ r, c := reconciler(s, cr)
+
+ reconcileOnce(t, r, cr)
+
+ d := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("be"), Namespace: "my-ns"}, d))
+
+ podAnnotations := d.Spec.Template.Annotations
+
+ // Custom annotations should be present
+ assert.Equal(t, "true", podAnnotations["prometheus.io/scrape"])
+ assert.Equal(t, "8000", podAnnotations["prometheus.io/port"])
+ assert.Equal(t, "backend-value", podAnnotations["custom-annotation"])
+}
+
+func TestReconcile_LangflowCustomPodLabelsAndAnnotations(t *testing.T) {
+ s := newScheme(t)
+ cr := minimalCR("my-openrag", "my-ns")
+ cr.Spec.Langflow.PodLabels = map[string]string{
+ "version": "v1.0.0",
+ "monitoring": "enabled",
+ }
+ cr.Spec.Langflow.PodAnnotations = map[string]string{
+ "sidecar.istio.io/inject": "true",
+ "vault.hashicorp.com/inject": "false",
+ }
+ r, c := reconciler(s, cr)
+
+ reconcileOnce(t, r, cr)
+
+ d := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("lf"), Namespace: "my-ns"}, d))
+
+ podLabels := d.Spec.Template.Labels
+ podAnnotations := d.Spec.Template.Annotations
+
+ // Custom labels should be present
+ assert.Equal(t, "v1.0.0", podLabels["version"])
+ assert.Equal(t, "enabled", podLabels["monitoring"])
+
+ // Operator-managed labels should still be present
+ assert.Equal(t, "openrag", podLabels["app.kubernetes.io/name"])
+ assert.Equal(t, "lf", podLabels["app.kubernetes.io/component"])
+
+ // Custom annotations should be present
+ assert.Equal(t, "true", podAnnotations["sidecar.istio.io/inject"])
+ assert.Equal(t, "false", podAnnotations["vault.hashicorp.com/inject"])
+}
+
+func TestReconcile_SelectorLabelsAreNotAffectedByCustomPodLabels(t *testing.T) {
+ s := newScheme(t)
+ cr := minimalCR("my-openrag", "my-ns")
+ // Add custom pod labels
+ cr.Spec.Frontend.PodLabels = map[string]string{
+ "custom-label": "should-not-be-in-selector",
+ }
+ r, c := reconciler(s, cr)
+
+ reconcileOnce(t, r, cr)
+
+ d := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("fe"), Namespace: "my-ns"}, d))
+
+ // Selector should only have operator-managed labels
+ selectorLabels := d.Spec.Selector.MatchLabels
+ assert.Equal(t, 4, len(selectorLabels), "Selector should only have 4 operator-managed labels")
+ assert.Equal(t, "openrag", selectorLabels["app.kubernetes.io/name"])
+ assert.Equal(t, "my-openrag", selectorLabels["app.kubernetes.io/instance"])
+ assert.Equal(t, "fe", selectorLabels["app.kubernetes.io/component"])
+ assert.Equal(t, "openrag-operator", selectorLabels["app.kubernetes.io/managed-by"])
+
+ // Custom label should NOT be in selector
+ _, exists := selectorLabels["custom-label"]
+ assert.False(t, exists, "Custom labels should not be in selector")
+
+ // But pod labels should include both
+ podLabels := d.Spec.Template.Labels
+ assert.Equal(t, "should-not-be-in-selector", podLabels["custom-label"])
+}
+
+func TestReconcile_FrontendDeploymentLevelLabelsAndAnnotations(t *testing.T) {
+ s := newScheme(t)
+ cr := minimalCR("my-openrag", "my-ns")
+ cr.Spec.Frontend.Labels = map[string]string{
+ "deployment-label": "deployment-value",
+ "team": "frontend-team",
+ }
+ cr.Spec.Frontend.Annotations = map[string]string{
+ "deployment.kubernetes.io/revision": "1",
+ "meta.helm.sh/release-name": "my-release",
+ }
+ r, c := reconciler(s, cr)
+
+ reconcileOnce(t, r, cr)
+
+ d := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("fe"), Namespace: "my-ns"}, d))
+
+ // Deployment-level labels should be present
+ assert.Equal(t, "deployment-value", d.Labels["deployment-label"])
+ assert.Equal(t, "frontend-team", d.Labels["team"])
+
+ // Operator-managed labels should still be present on deployment
+ assert.Equal(t, "openrag", d.Labels["app.kubernetes.io/name"])
+ assert.Equal(t, "fe", d.Labels["app.kubernetes.io/component"])
+
+ // Deployment-level annotations should be present
+ assert.Equal(t, "1", d.Annotations["deployment.kubernetes.io/revision"])
+ assert.Equal(t, "my-release", d.Annotations["meta.helm.sh/release-name"])
+}
+
+func TestReconcile_DeploymentAndPodLabelsAreIndependent(t *testing.T) {
+ s := newScheme(t)
+ cr := minimalCR("my-openrag", "my-ns")
+ cr.Spec.Backend.Labels = map[string]string{
+ "deployment-only": "on-deployment",
+ }
+ cr.Spec.Backend.PodLabels = map[string]string{
+ "pod-only": "on-pod",
+ }
+ r, c := reconciler(s, cr)
+
+ reconcileOnce(t, r, cr)
+
+ d := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("be"), Namespace: "my-ns"}, d))
+
+ // Deployment should have deployment-only label
+ assert.Equal(t, "on-deployment", d.Labels["deployment-only"])
+ // Deployment should NOT have pod-only label
+ _, exists := d.Labels["pod-only"]
+ assert.False(t, exists, "Pod-only label should not be on deployment")
+
+ // Pod should have pod-only label
+ podLabels := d.Spec.Template.Labels
+ assert.Equal(t, "on-pod", podLabels["pod-only"])
+ // Pod should NOT have deployment-only label
+ _, exists = podLabels["deployment-only"]
+ assert.False(t, exists, "Deployment-only label should not be on pod")
+
+ // Both should have operator-managed labels
+ assert.Equal(t, "openrag", d.Labels["app.kubernetes.io/name"])
+ assert.Equal(t, "openrag", podLabels["app.kubernetes.io/name"])
+}
+
+func TestReconcile_AllThreeComponentsSupportBothLevels(t *testing.T) {
+ s := newScheme(t)
+ cr := minimalCR("my-openrag", "my-ns")
+
+ // Frontend with deployment annotations
+ cr.Spec.Frontend.Annotations = map[string]string{
+ "frontend-deploy-annotation": "fe-value",
+ }
+ cr.Spec.Frontend.PodAnnotations = map[string]string{
+ "frontend-pod-annotation": "fe-pod-value",
+ }
+
+ // Backend with deployment labels
+ cr.Spec.Backend.Labels = map[string]string{
+ "backend-deploy-label": "be-value",
+ }
+ cr.Spec.Backend.PodLabels = map[string]string{
+ "backend-pod-label": "be-pod-value",
+ }
+
+ // Langflow with both
+ cr.Spec.Langflow.Labels = map[string]string{
+ "langflow-deploy-label": "lf-value",
+ }
+ cr.Spec.Langflow.Annotations = map[string]string{
+ "langflow-deploy-annotation": "lf-annotation",
+ }
+ cr.Spec.Langflow.PodLabels = map[string]string{
+ "langflow-pod-label": "lf-pod-value",
+ }
+ cr.Spec.Langflow.PodAnnotations = map[string]string{
+ "langflow-pod-annotation": "lf-pod-annotation",
+ }
+
+ r, c := reconciler(s, cr)
+ reconcileOnce(t, r, cr)
+
+ // Check Frontend
+ feDeploy := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("fe"), Namespace: "my-ns"}, feDeploy))
+ assert.Equal(t, "fe-value", feDeploy.Annotations["frontend-deploy-annotation"])
+ assert.Equal(t, "fe-pod-value", feDeploy.Spec.Template.Annotations["frontend-pod-annotation"])
+
+ // Check Backend
+ beDeploy := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("be"), Namespace: "my-ns"}, beDeploy))
+ assert.Equal(t, "be-value", beDeploy.Labels["backend-deploy-label"])
+ assert.Equal(t, "be-pod-value", beDeploy.Spec.Template.Labels["backend-pod-label"])
+
+ // Check Langflow
+ lfDeploy := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("lf"), Namespace: "my-ns"}, lfDeploy))
+ assert.Equal(t, "lf-value", lfDeploy.Labels["langflow-deploy-label"])
+ assert.Equal(t, "lf-annotation", lfDeploy.Annotations["langflow-deploy-annotation"])
+ assert.Equal(t, "lf-pod-value", lfDeploy.Spec.Template.Labels["langflow-pod-label"])
+ assert.Equal(t, "lf-pod-annotation", lfDeploy.Spec.Template.Annotations["langflow-pod-annotation"])
+}
+
+// TestReconcile_UUIDNameDNS1035Compliance verifies that resources work correctly
+// even when CR names start with numbers (UUIDs). Since we use namespace-scoped
+// naming (openrag-fe, openrag-be, openrag-lf), the CR name doesn't affect resource names.
+func TestReconcile_UUIDNameDNS1035Compliance(t *testing.T) {
+ s := newScheme(t)
+ // Use the exact UUID from the production error - this should work fine now
+ uuidName := "9a826efa-112d-4e2d-9f8d-ce103880ab41"
+ cr := minimalCR(uuidName, "test-ns")
+
+ r, c := reconciler(s, cr)
+ reconcileOnce(t, r, cr)
+
+ // Verify all created resources have DNS-1035 compliant names
+ // DNS-1035: must start with letter, end with alphanumeric, contain only lowercase alphanumeric and hyphens
+ dns1035Regex := `^[a-z]([-a-z0-9]*[a-z0-9])?$`
+
+ // Check frontend deployment
+ feDeploy := &appsv1.Deployment{}
+ feName := resourceName("fe")
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: feName, Namespace: "test-ns"}, feDeploy))
+ assert.Regexp(t, dns1035Regex, feName, "Frontend deployment name must be DNS-1035 compliant")
+ assert.Regexp(t, dns1035Regex, feDeploy.Name, "Frontend deployment name must be DNS-1035 compliant")
+
+ // Check frontend service
+ feSvc := &corev1.Service{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: feName, Namespace: "test-ns"}, feSvc))
+ assert.Regexp(t, dns1035Regex, feSvc.Name, "Frontend service name must be DNS-1035 compliant")
+
+ // Check backend deployment
+ beDeploy := &appsv1.Deployment{}
+ beName := resourceName("be")
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: beName, Namespace: "test-ns"}, beDeploy))
+ assert.Regexp(t, dns1035Regex, beName, "Backend deployment name must be DNS-1035 compliant")
+
+ // Check backend service
+ beSvc := &corev1.Service{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: beName, Namespace: "test-ns"}, beSvc))
+ assert.Regexp(t, dns1035Regex, beSvc.Name, "Backend service name must be DNS-1035 compliant")
+
+ // Check langflow deployment
+ lfDeploy := &appsv1.Deployment{}
+ lfName := resourceName("lf")
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: lfName, Namespace: "test-ns"}, lfDeploy))
+ assert.Regexp(t, dns1035Regex, lfName, "Langflow deployment name must be DNS-1035 compliant")
+
+ // Verify the simple naming pattern: "openrag-{role}" (namespace-scoped)
+ assert.Equal(t, "openrag-fe", feName)
+ assert.Equal(t, "openrag-be", beName)
+ assert.Equal(t, "openrag-lf", lfName)
+
+ // Verify the CR UUID name is tracked in labels, not in resource names
+ assert.Equal(t, uuidName, feDeploy.Labels["app.kubernetes.io/instance"])
+ assert.Equal(t, uuidName, beDeploy.Labels["app.kubernetes.io/instance"])
+ assert.Equal(t, uuidName, lfDeploy.Labels["app.kubernetes.io/instance"])
+}