Skip to content

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

Python

feat: CRD updates (#1555)

ming0213c7ffa056
diff --git a/kubernetes/operator/api/v1alpha1/openrag_types.go b/kubernetes/operator/api/v1alpha1/openrag_types.go
index bdec6645b..13f636c99 100644
--- a/kubernetes/operator/api/v1alpha1/openrag_types.go
+++ b/kubernetes/operator/api/v1alpha1/openrag_types.go
@@ -18,6 +18,12 @@ type ComponentSpec struct {
// +kubebuilder:default=IfNotPresent
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
+ // ImagePullSecrets for private registries, specific to this component.
+ // These are merged with the global imagePullSecrets from the OpenRAG spec.
+ // +optional
+ // +kubebuilder:validation:XValidation:rule="self.all(x, x.name != '')",message="imagePullSecret name cannot be empty"
+ ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
+
// +optional
// +kubebuilder:default=1
// +kubebuilder:validation:Minimum=0
@@ -42,22 +48,15 @@ type ComponentSpec struct {
// 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.
@@ -65,23 +64,44 @@ type ComponentSpec struct {
// 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"`
+
+ // ServiceAccountName is the name of the ServiceAccount to use for this component's pod.
+ // When CreateServiceAccount is true, the operator will create a ServiceAccount with this name.
+ // When CreateServiceAccount is false, the ServiceAccount must already exist in the target namespace.
+ // If not specified, defaults to "openrag-{role}" (e.g., "openrag-fe", "openrag-be", "openrag-lf").
+ // +optional
+ ServiceAccountName string `json:"serviceAccountName,omitempty"`
+
+ // CreateServiceAccount indicates whether the operator should create the ServiceAccount.
+ // If true (default), the operator creates a ServiceAccount with the name specified in ServiceAccountName.
+ // If false, the operator assumes the ServiceAccount already exists and will only reference it.
+ // +optional
+ // +kubebuilder:default=true
+ CreateServiceAccount *bool `json:"createServiceAccount,omitempty"`
+
+ // ServiceName is the name of the Service to use for this component.
+ // When CreateService is true, the operator will create a Service with this name.
+ // When CreateService is false, the Service must already exist in the target namespace.
+ // If not specified, defaults to "openrag-{role}" (e.g., "openrag-fe", "openrag-be", "openrag-lf").
+ // +optional
+ ServiceName string `json:"serviceName,omitempty"`
+
+ // CreateService indicates whether the operator should create the Service.
+ // If true (default), the operator creates a Service with the name specified in ServiceName.
+ // If false, the operator assumes the Service already exists and will only reference it.
+ // +optional
+ // +kubebuilder:default=true
+ CreateService *bool `json:"createService,omitempty"`
}
// FrontendSpec configures the OpenRAG frontend (Next.js).
@@ -281,6 +301,7 @@ type OpenRAGSpec struct {
// ImagePullSecrets for private registries, applied to all component pods.
// +optional
+ // +kubebuilder:validation:XValidation:rule="self.all(x, x.name != '')",message="imagePullSecret name cannot be empty"
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
// Frontend configures the OpenRAG Next.js frontend.
diff --git a/kubernetes/operator/api/v1alpha1/zz_generated.deepcopy.go b/kubernetes/operator/api/v1alpha1/zz_generated.deepcopy.go
index 5b20fb9be..a26cc9ef5 100644
--- a/kubernetes/operator/api/v1alpha1/zz_generated.deepcopy.go
+++ b/kubernetes/operator/api/v1alpha1/zz_generated.deepcopy.go
@@ -65,6 +65,11 @@ func (in *BackendSpec) DeepCopy() *BackendSpec {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ComponentSpec) DeepCopyInto(out *ComponentSpec) {
*out = *in
+ if in.ImagePullSecrets != nil {
+ in, out := &in.ImagePullSecrets, &out.ImagePullSecrets
+ *out = make([]v1.LocalObjectReference, len(*in))
+ copy(*out, *in)
+ }
if in.Replicas != nil {
in, out := &in.Replicas, &out.Replicas
*out = new(int32)
@@ -125,6 +130,16 @@ func (in *ComponentSpec) DeepCopyInto(out *ComponentSpec) {
(*out)[key] = val
}
}
+ if in.CreateServiceAccount != nil {
+ in, out := &in.CreateServiceAccount, &out.CreateServiceAccount
+ *out = new(bool)
+ **out = **in
+ }
+ if in.CreateService != nil {
+ in, out := &in.CreateService, &out.CreateService
+ *out = new(bool)
+ **out = **in
+ }
}
// 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 060ce7eb6..23015c281 100644
--- a/kubernetes/operator/config/crd/bases/openr.ag_openrags.yaml
+++ b/kubernetes/operator/config/crd/bases/openr.ag_openrags.yaml
@@ -986,17 +986,22 @@ spec:
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]$'')))'
+ createService:
+ default: true
+ description: |-
+ CreateService indicates whether the operator should create the Service.
+ If true (default), the operator creates a Service with the name specified in ServiceName.
+ If false, the operator assumes the Service already exists and will only reference it.
+ type: boolean
+ createServiceAccount:
+ default: true
+ description: |-
+ CreateServiceAccount indicates whether the operator should create the ServiceAccount.
+ If true (default), the operator creates a ServiceAccount with the name specified in ServiceAccountName.
+ If false, the operator assumes the ServiceAccount already exists and will only reference it.
+ type: boolean
encryptionKeySecret:
description: |-
EncryptionKeySecret references the Secret key for OPENRAG_ENCRYPTION_KEY.
@@ -1155,6 +1160,30 @@ spec:
description: PullPolicy describes a policy for if/when to pull
a container image
type: string
+ imagePullSecrets:
+ description: |-
+ ImagePullSecrets for private registries, specific to this component.
+ These are merged with the global imagePullSecrets from the OpenRAG spec.
+ items:
+ description: |-
+ LocalObjectReference contains enough information to let you locate the
+ referenced object inside the same namespace.
+ properties:
+ name:
+ default: ""
+ description: |-
+ Name of the referent.
+ This field is effectively required, but due to backwards compatibility is
+ allowed to be empty. Instances of this type with an empty value here are
+ almost certainly wrong.
+ More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
+ type: string
+ type: object
+ x-kubernetes-map-type: atomic
+ type: array
+ x-kubernetes-validations:
+ - message: imagePullSecret name cannot be empty
+ rule: self.all(x, x.name != '')
jwtSigningKeySecret:
description: JWTSigningKeySecret references the Secret key that
holds the JWT signing key.
@@ -1187,20 +1216,8 @@ spec:
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
@@ -1282,17 +1299,8 @@ spec:
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
@@ -1302,20 +1310,8 @@ spec:
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
@@ -1381,6 +1377,20 @@ spec:
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
type: object
type: object
+ serviceAccountName:
+ description: |-
+ ServiceAccountName is the name of the ServiceAccount to use for this component's pod.
+ When CreateServiceAccount is true, the operator will create a ServiceAccount with this name.
+ When CreateServiceAccount is false, the ServiceAccount must already exist in the target namespace.
+ If not specified, defaults to "openrag-{role}" (e.g., "openrag-fe", "openrag-be", "openrag-lf").
+ type: string
+ serviceName:
+ description: |-
+ ServiceName is the name of the Service to use for this component.
+ When CreateService is true, the operator will create a Service with this name.
+ When CreateService is false, the Service must already exist in the target namespace.
+ If not specified, defaults to "openrag-{role}" (e.g., "openrag-fe", "openrag-be", "openrag-lf").
+ type: string
storage:
description: Storage configures a PVC mounted at /app/backend-data.
properties:
@@ -2400,17 +2410,22 @@ spec:
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]$'')))'
+ createService:
+ default: true
+ description: |-
+ CreateService indicates whether the operator should create the Service.
+ If true (default), the operator creates a Service with the name specified in ServiceName.
+ If false, the operator assumes the Service already exists and will only reference it.
+ type: boolean
+ createServiceAccount:
+ default: true
+ description: |-
+ CreateServiceAccount indicates whether the operator should create the ServiceAccount.
+ If true (default), the operator creates a ServiceAccount with the name specified in ServiceAccountName.
+ If false, the operator assumes the ServiceAccount already exists and will only reference it.
+ type: boolean
env:
description: Additional environment variables injected into the
container.
@@ -2540,6 +2555,30 @@ spec:
description: PullPolicy describes a policy for if/when to pull
a container image
type: string
+ imagePullSecrets:
+ description: |-
+ ImagePullSecrets for private registries, specific to this component.
+ These are merged with the global imagePullSecrets from the OpenRAG spec.
+ items:
+ description: |-
+ LocalObjectReference contains enough information to let you locate the
+ referenced object inside the same namespace.
+ properties:
+ name:
+ default: ""
+ description: |-
+ Name of the referent.
+ This field is effectively required, but due to backwards compatibility is
+ allowed to be empty. Instances of this type with an empty value here are
+ almost certainly wrong.
+ More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
+ type: string
+ type: object
+ x-kubernetes-map-type: atomic
+ type: array
+ x-kubernetes-validations:
+ - message: imagePullSecret name cannot be empty
+ rule: self.all(x, x.name != '')
labels:
additionalProperties:
type: string
@@ -2547,20 +2586,8 @@ spec:
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
@@ -2572,17 +2599,8 @@ spec:
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
@@ -2592,20 +2610,8 @@ spec:
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
@@ -2671,6 +2677,20 @@ spec:
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
type: object
type: object
+ serviceAccountName:
+ description: |-
+ ServiceAccountName is the name of the ServiceAccount to use for this component's pod.
+ When CreateServiceAccount is true, the operator will create a ServiceAccount with this name.
+ When CreateServiceAccount is false, the ServiceAccount must already exist in the target namespace.
+ If not specified, defaults to "openrag-{role}" (e.g., "openrag-fe", "openrag-be", "openrag-lf").
+ type: string
+ serviceName:
+ description: |-
+ ServiceName is the name of the Service to use for this component.
+ When CreateService is true, the operator will create a Service with this name.
+ When CreateService is false, the Service must already exist in the target namespace.
+ If not specified, defaults to "openrag-{role}" (e.g., "openrag-fe", "openrag-be", "openrag-lf").
+ type: string
tolerations:
items:
description: |-
@@ -2732,6 +2752,9 @@ spec:
type: object
x-kubernetes-map-type: atomic
type: array
+ x-kubernetes-validations:
+ - message: imagePullSecret name cannot be empty
+ rule: self.all(x, x.name != '')
langflow:
description: Langflow configures the Langflow workflow engine.
properties:
@@ -3661,17 +3684,22 @@ spec:
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]$'')))'
+ createService:
+ default: true
+ description: |-
+ CreateService indicates whether the operator should create the Service.
+ If true (default), the operator creates a Service with the name specified in ServiceName.
+ If false, the operator assumes the Service already exists and will only reference it.
+ type: boolean
+ createServiceAccount:
+ default: true
+ description: |-
+ CreateServiceAccount indicates whether the operator should create the ServiceAccount.
+ If true (default), the operator creates a ServiceAccount with the name specified in ServiceAccountName.
+ If false, the operator assumes the ServiceAccount already exists and will only reference it.
+ type: boolean
env:
description: Additional environment variables injected into the
container.
@@ -3813,6 +3841,30 @@ spec:
description: PullPolicy describes a policy for if/when to pull
a container image
type: string
+ imagePullSecrets:
+ description: |-
+ ImagePullSecrets for private registries, specific to this component.
+ These are merged with the global imagePullSecrets from the OpenRAG spec.
+ items:
+ description: |-
+ LocalObjectReference contains enough information to let you locate the
+ referenced object inside the same namespace.
+ properties:
+ name:
+ default: ""
+ description: |-
+ Name of the referent.
+ This field is effectively required, but due to backwards compatibility is
+ allowed to be empty. Instances of this type with an empty value here are
+ almost certainly wrong.
+ More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
+ type: string
+ type: object
+ x-kubernetes-map-type: atomic
+ type: array
+ x-kubernetes-validations:
+ - message: imagePullSecret name cannot be empty
+ rule: self.all(x, x.name != '')
labels:
additionalProperties:
type: string
@@ -3820,20 +3872,8 @@ spec:
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
@@ -3845,17 +3885,8 @@ spec:
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
@@ -3865,20 +3896,8 @@ spec:
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
@@ -3971,6 +3990,20 @@ spec:
- key
type: object
x-kubernetes-map-type: atomic
+ serviceAccountName:
+ description: |-
+ ServiceAccountName is the name of the ServiceAccount to use for this component's pod.
+ When CreateServiceAccount is true, the operator will create a ServiceAccount with this name.
+ When CreateServiceAccount is false, the ServiceAccount must already exist in the target namespace.
+ If not specified, defaults to "openrag-{role}" (e.g., "openrag-fe", "openrag-be", "openrag-lf").
+ type: string
+ serviceName:
+ description: |-
+ ServiceName is the name of the Service to use for this component.
+ When CreateService is true, the operator will create a Service with this name.
+ When CreateService is false, the Service must already exist in the target namespace.
+ If not specified, defaults to "openrag-{role}" (e.g., "openrag-fe", "openrag-be", "openrag-lf").
+ type: string
storage:
description: Storage configures a PVC mounted at /app/data (Langflow
SQLite + flows).
diff --git a/kubernetes/operator/internal/controller/openrag_controller.go b/kubernetes/operator/internal/controller/openrag_controller.go
index 9cfec3cec..2f5b29fbd 100644
--- a/kubernetes/operator/internal/controller/openrag_controller.go
+++ b/kubernetes/operator/internal/controller/openrag_controller.go
@@ -73,7 +73,8 @@ func (r *OpenRAGReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
return ctrl.Result{}, r.handleDeletion(ctx, instance)
}
- if instance.Spec.TargetNamespace != "" && instance.Spec.TargetNamespace != instance.Namespace {
+ targetNS := targetNamespace(instance)
+ if targetNS != instance.Namespace {
if !controllerutil.ContainsFinalizer(instance, finalizer) {
controllerutil.AddFinalizer(instance, finalizer)
if err := r.Update(ctx, instance); err != nil {
@@ -86,8 +87,6 @@ func (r *OpenRAGReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
}
}
- targetNS := targetNamespace(instance)
-
if err := r.reconcileNamespace(ctx, instance, targetNS); err != nil {
return ctrl.Result{}, fmt.Errorf("namespace: %w", err)
}
@@ -121,8 +120,9 @@ func (r *OpenRAGReconciler) handleDeletion(ctx context.Context, o *openragv1alph
return nil
}
+ targetNS := targetNamespace(o)
ns := &corev1.Namespace{}
- err := r.Get(ctx, client.ObjectKey{Name: o.Spec.TargetNamespace}, ns)
+ err := r.Get(ctx, client.ObjectKey{Name: targetNS}, ns)
if err != nil && !errors.IsNotFound(err) {
return err
}
@@ -162,9 +162,14 @@ func (r *OpenRAGReconciler) reconcileNamespace(ctx context.Context, o *openragv1
func (r *OpenRAGReconciler) reconcileServiceAccounts(ctx context.Context, o *openragv1alpha1.OpenRAG, targetNS string) error {
for _, role := range []string{"fe", "be", "lf"} {
+ // Only create ServiceAccount if flag is true
+ if !shouldCreateServiceAccount(o, role) {
+ continue
+ }
+
sa := &corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
- Name: saName(role),
+ Name: getServiceAccountName(o, role), // Use custom name if specified
Namespace: targetNS,
Labels: componentLabels(o.Name, role),
},
@@ -192,132 +197,20 @@ func parseEnvValue(envContent, key string) string {
return ""
}
-// getOrCreateEncryptionKey retrieves the OPENRAG_ENCRYPTION_KEY from:
-// 1. Existing .env secret (highest priority - never regenerate)
-// 2. Dedicated kubernetes secret (secretName)
-// 3. Generate new key and store in dedicated secret
-func (r *OpenRAGReconciler) getOrCreateEncryptionKey(ctx context.Context, o *openragv1alpha1.OpenRAG, targetNS, secretName, keyName, envSecretName string) (string, error) {
- // First check if key exists in the existing .env secret
- existingEnvSecret := &corev1.Secret{}
- err := r.Get(ctx, client.ObjectKey{Name: envSecretName, Namespace: targetNS}, existingEnvSecret)
- if err == nil {
- // Parse the .env file content
- envContent := string(existingEnvSecret.Data[".env"])
- if envContent == "" && existingEnvSecret.StringData != nil {
- envContent = existingEnvSecret.StringData[".env"]
- }
- if value := parseEnvValue(envContent, keyName); value != "" {
- return value, nil // Never regenerate existing key
- }
- }
-
- // Check if key exists in dedicated kubernetes secret
- dedicatedSecret := &corev1.Secret{}
- err = r.Get(ctx, client.ObjectKey{Name: secretName, Namespace: targetNS}, dedicatedSecret)
- if err == nil {
- if key, ok := dedicatedSecret.Data[keyName]; ok && len(key) > 0 {
- return string(key), nil
- }
- if dedicatedSecret.StringData != nil {
- if key, ok := dedicatedSecret.StringData[keyName]; ok && key != "" {
- return key, nil
- }
- }
- }
-
- // Generate new key and store in dedicated secret
- newKey, err := GenerateAESKeyString32()
- if err != nil {
- return "", fmt.Errorf("failed to generate encryption key: %w", err)
- }
-
- secret := &corev1.Secret{
- ObjectMeta: metav1.ObjectMeta{
- Name: secretName,
- Namespace: targetNS,
- Labels: map[string]string{"app.kubernetes.io/managed-by": "openrag-operator"},
- },
- StringData: map[string]string{keyName: newKey},
- }
- if err := r.setOwnerOrLabel(o, secret, targetNS); err != nil {
- return "", err
- }
- if err := r.createOrUpdate(ctx, secret); err != nil {
- return "", err
- }
-
- return newKey, nil
-}
-
-// getOrCreateLangflowSecretKey retrieves the LANGFLOW_SECRET_KEY from:
-// 1. Existing .env secret (highest priority - never regenerate)
-// 2. Dedicated kubernetes secret (secretName)
-// 3. Generate new key and store in dedicated secret
-func (r *OpenRAGReconciler) getOrCreateLangflowSecretKey(ctx context.Context, o *openragv1alpha1.OpenRAG, targetNS, secretName, keyName, envSecretName string) (string, error) {
- // First check if key exists in the existing .env secret
- existingEnvSecret := &corev1.Secret{}
- err := r.Get(ctx, client.ObjectKey{Name: envSecretName, Namespace: targetNS}, existingEnvSecret)
- if err == nil {
- // Parse the .env file content
- envContent := string(existingEnvSecret.Data[".env"])
- if envContent == "" && existingEnvSecret.StringData != nil {
- envContent = existingEnvSecret.StringData[".env"]
- }
- if value := parseEnvValue(envContent, keyName); value != "" {
- return value, nil // Never regenerate existing key
- }
- }
-
- // Check if key exists in dedicated kubernetes secret
- dedicatedSecret := &corev1.Secret{}
- err = r.Get(ctx, client.ObjectKey{Name: secretName, Namespace: targetNS}, dedicatedSecret)
- if err == nil {
- if key, ok := dedicatedSecret.Data[keyName]; ok && len(key) > 0 {
- return string(key), nil
- }
- if dedicatedSecret.StringData != nil {
- if key, ok := dedicatedSecret.StringData[keyName]; ok && key != "" {
- return key, nil
- }
- }
- }
-
- // Generate new key and store in dedicated secret
- newKey, err := generateBase64SecretKey()
- if err != nil {
- return "", fmt.Errorf("failed to generate langflow secret key: %w", err)
- }
-
- secret := &corev1.Secret{
- ObjectMeta: metav1.ObjectMeta{
- Name: secretName,
- Namespace: targetNS,
- Labels: map[string]string{"app.kubernetes.io/managed-by": "openrag-operator"},
- },
- StringData: map[string]string{keyName: newKey},
- }
- if err := r.setOwnerOrLabel(o, secret, targetNS); err != nil {
- return "", err
- }
- if err := r.createOrUpdate(ctx, secret); err != nil {
- return "", err
- }
-
- return newKey, nil
-}
-
// reconcileEnvSecrets creates / updates the backend and Langflow .env Secrets
// from CR fields and fixed runtime defaults.
+// All sensitive values (whether user-provided or generated) are consolidated into .env files.
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("be-env"))
+ // Build backend .env content with all secrets consolidated
+ backendEnvContent, err := r.buildBackendEnv(ctx, o, targetNS)
if err != nil {
- return fmt.Errorf("failed to get backend encryption key: %w", err)
+ return fmt.Errorf("failed to build backend env: %w", err)
}
- langflowSecretKey, err := r.getOrCreateLangflowSecretKey(ctx, o, targetNS, "langflow-secret-key", "LANGFLOW_SECRET_KEY", resourceName("lf-env"))
+ // Build langflow .env content with all secrets consolidated
+ langflowEnvContent, err := r.buildLangflowEnv(ctx, o, targetNS)
if err != nil {
- return fmt.Errorf("failed to get langflow secret key: %w", err)
+ return fmt.Errorf("failed to build langflow env: %w", err)
}
type envDef struct {
@@ -325,8 +218,8 @@ func (r *OpenRAGReconciler) reconcileEnvSecrets(ctx context.Context, o *openragv
content string
}
defs := []envDef{
- {resourceName("be-env"), r.buildBackendEnv(o, backendEncryptionKey)},
- {resourceName("lf-env"), r.buildLangflowEnv(o, langflowSecretKey)},
+ {resourceName("be-env"), backendEnvContent},
+ {resourceName("lf-env"), langflowEnvContent},
}
for _, d := range defs {
secret := &corev1.Secret{
@@ -347,15 +240,27 @@ func (r *OpenRAGReconciler) reconcileEnvSecrets(ctx context.Context, o *openragv
return nil
}
-func (r *OpenRAGReconciler) buildBackendEnv(o *openragv1alpha1.OpenRAG, encryptionKey string) string {
+func (r *OpenRAGReconciler) buildBackendEnv(ctx context.Context, o *openragv1alpha1.OpenRAG, targetNS string) (string, error) {
// Start with defaults, operator env, and CR env (three-level priority)
envVars := r.EnvVarManager.GetBackendEnvVars(o.Spec.Backend.Env)
- // Set encryption key (always preserved, never regenerated)
+ // Get or generate encryption key (AES-256)
+ // Priority: 1) User-provided secret in CR, 2) Existing value in .env, 3) Generate new
+ encryptionKey, err := r.getOrGenerateSecret(ctx, o, targetNS, o.Spec.Backend.EncryptionKeySecret, "OPENRAG_ENCRYPTION_KEY", resourceName("be-env"), GenerateAESKeyString32)
+ if err != nil {
+ return "", fmt.Errorf("failed to get encryption key: %w", err)
+ }
envVars["OPENRAG_ENCRYPTION_KEY"] = encryptionKey
+ // Get or generate JWT signing key (base64 secret)
+ jwtSigningKey, err := r.getOrGenerateSecret(ctx, o, targetNS, o.Spec.Backend.JWTSigningKeySecret, "JWT_PRIVATE_KEY", resourceName("be-env"), generateBase64SecretKey)
+ if err != nil {
+ return "", fmt.Errorf("failed to get JWT signing key: %w", err)
+ }
+ envVars["JWT_PRIVATE_KEY"] = jwtSigningKey
+
// Operator-derived values (always set)
- envVars["LANGFLOW_URL"] = "http://" + resourceName("lf") + ":7860"
+ envVars["LANGFLOW_URL"] = "http://" + getServiceName(o, "lf") + ":7860"
// Override with CR-specific configuration
if o.Spec.TenantID != "" {
@@ -378,9 +283,36 @@ func (r *OpenRAGReconciler) buildBackendEnv(o *openragv1alpha1.OpenRAG, encrypti
if os.IndexName != "" {
envVars["OPENSEARCH_INDEX_NAME"] = os.IndexName
}
- // Username injected as env var from credentials secret when set;
- // fall back to the common default.
- if os.CredentialsSecret == "" {
+
+ // Read OpenSearch credentials from user-provided secret
+ if os.CredentialsSecret != "" {
+ // Read username
+ usernameSecret := &corev1.SecretKeySelector{
+ LocalObjectReference: corev1.LocalObjectReference{Name: os.CredentialsSecret},
+ Key: "username",
+ }
+ username, err := r.readSecretValue(ctx, targetNS, usernameSecret)
+ if err != nil {
+ return "", fmt.Errorf("failed to read OpenSearch username: %w", err)
+ }
+ if username != "" {
+ envVars["OPENSEARCH_USERNAME"] = username
+ }
+
+ // Read password
+ passwordSecret := &corev1.SecretKeySelector{
+ LocalObjectReference: corev1.LocalObjectReference{Name: os.CredentialsSecret},
+ Key: "password",
+ }
+ password, err := r.readSecretValue(ctx, targetNS, passwordSecret)
+ if err != nil {
+ return "", fmt.Errorf("failed to read OpenSearch password: %w", err)
+ }
+ if password != "" {
+ envVars["OPENSEARCH_PASSWORD"] = password
+ }
+ } else {
+ // Default username when no credentials secret is provided
envVars["OPENSEARCH_USERNAME"] = "admin"
}
}
@@ -393,6 +325,17 @@ func (r *OpenRAGReconciler) buildBackendEnv(o *openragv1alpha1.OpenRAG, encrypti
if wx.ProjectID != "" {
envVars["WATSONX_PROJECT_ID"] = wx.ProjectID
}
+
+ // Read WatsonX API key from user-provided secret
+ if wx.APIKeySecret != nil {
+ apiKey, err := r.readSecretValue(ctx, targetNS, wx.APIKeySecret)
+ if err != nil {
+ return "", fmt.Errorf("failed to read WatsonX API key: %w", err)
+ }
+ if apiKey != "" {
+ envVars["WATSONX_API_KEY"] = apiKey
+ }
+ }
}
// LLM configuration from CR spec
@@ -423,11 +366,36 @@ func (r *OpenRAGReconciler) buildBackendEnv(o *openragv1alpha1.OpenRAG, encrypti
envVars["OAUTH_BROKER_URL"] = o.Spec.Backend.OAuthBrokerURL
}
if oa := o.Spec.Backend.OAuth; oa != nil {
- if oa.Google != nil && oa.Google.ClientID != "" {
- envVars["GOOGLE_OAUTH_CLIENT_ID"] = oa.Google.ClientID
+ // Google OAuth
+ if oa.Google != nil {
+ if oa.Google.ClientID != "" {
+ envVars["GOOGLE_OAUTH_CLIENT_ID"] = oa.Google.ClientID
+ }
+ if oa.Google.ClientSecret != nil {
+ clientSecret, err := r.readSecretValue(ctx, targetNS, oa.Google.ClientSecret)
+ if err != nil {
+ return "", fmt.Errorf("failed to read Google OAuth client secret: %w", err)
+ }
+ if clientSecret != "" {
+ envVars["GOOGLE_OAUTH_CLIENT_SECRET"] = clientSecret
+ }
+ }
}
- if oa.Microsoft != nil && oa.Microsoft.ClientID != "" {
- envVars["MICROSOFT_GRAPH_OAUTH_CLIENT_ID"] = oa.Microsoft.ClientID
+
+ // Microsoft OAuth
+ if oa.Microsoft != nil {
+ if oa.Microsoft.ClientID != "" {
+ envVars["MICROSOFT_GRAPH_OAUTH_CLIENT_ID"] = oa.Microsoft.ClientID
+ }
+ if oa.Microsoft.ClientSecret != nil {
+ clientSecret, err := r.readSecretValue(ctx, targetNS, oa.Microsoft.ClientSecret)
+ if err != nil {
+ return "", fmt.Errorf("failed to read Microsoft OAuth client secret: %w", err)
+ }
+ if clientSecret != "" {
+ envVars["MICROSOFT_GRAPH_OAUTH_CLIENT_SECRET"] = clientSecret
+ }
+ }
}
}
@@ -445,15 +413,19 @@ func (r *OpenRAGReconciler) buildBackendEnv(o *openragv1alpha1.OpenRAG, encrypti
}
// Convert map to .env file format
- return r.EnvVarManager.BuildEnvFileContent(envVars)
+ return r.EnvVarManager.BuildEnvFileContent(envVars), nil
}
-func (r *OpenRAGReconciler) buildLangflowEnv(o *openragv1alpha1.OpenRAG, secretKey string) string {
+func (r *OpenRAGReconciler) buildLangflowEnv(ctx context.Context, o *openragv1alpha1.OpenRAG, targetNS string) (string, error) {
// Start with defaults, operator env, and CR env (three-level priority)
envVars := r.EnvVarManager.GetLangflowEnvVars(o.Spec.Langflow.Env)
- // Set secret key (always preserved, never regenerated)
- envVars["LANGFLOW_SECRET_KEY"] = secretKey
+ // Get or generate Langflow secret key (Fernet key - base64, shared with backend)
+ langflowSecretKey, err := r.getOrGenerateSecret(ctx, o, targetNS, o.Spec.Langflow.SecretKeySecret, "LANGFLOW_SECRET_KEY", resourceName("lf-env"), generateBase64SecretKey)
+ if err != nil {
+ return "", fmt.Errorf("failed to get langflow secret key: %w", err)
+ }
+ envVars["LANGFLOW_SECRET_KEY"] = langflowSecretKey
// Override with CR-specific configuration
if o.Spec.TenantID != "" {
@@ -522,7 +494,7 @@ func (r *OpenRAGReconciler) buildLangflowEnv(o *openragv1alpha1.OpenRAG, secretK
}
// Convert map to .env file format
- return r.EnvVarManager.BuildEnvFileContent(envVars)
+ return r.EnvVarManager.BuildEnvFileContent(envVars), nil
}
func (r *OpenRAGReconciler) reconcilePVCs(ctx context.Context, o *openragv1alpha1.OpenRAG, targetNS string) error {
@@ -583,9 +555,14 @@ func (r *OpenRAGReconciler) reconcileServices(ctx context.Context, o *openragv1a
{"lf", 7860},
}
for _, d := range defs {
+ // Only create Service if flag is true
+ if !shouldCreateService(o, d.role) {
+ continue
+ }
+
svc := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
- Name: resourceName(d.role),
+ Name: getServiceName(o, d.role), // Use custom name if specified
Namespace: targetNS,
Labels: componentLabels(o.Name, d.role),
},
@@ -649,8 +626,8 @@ func (r *OpenRAGReconciler) frontendDeployment(o *openragv1alpha1.OpenRAG, targe
Annotations: podAnnotations,
},
Spec: corev1.PodSpec{
- ServiceAccountName: saName("fe"),
- ImagePullSecrets: o.Spec.ImagePullSecrets,
+ ServiceAccountName: getServiceAccountName(o, "fe"),
+ ImagePullSecrets: mergeImagePullSecrets(o.Spec.ImagePullSecrets, spec.ImagePullSecrets),
NodeSelector: spec.NodeSelector,
Tolerations: spec.Tolerations,
Affinity: spec.Affinity,
@@ -661,7 +638,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("be")},
+ {Name: "OPENRAG_BACKEND_HOST", Value: getServiceName(o, "be")},
}, spec.Env...),
Resources: spec.Resources,
LivenessProbe: httpProbe("/", 3000, 30, 10),
@@ -709,14 +686,9 @@ func (r *OpenRAGReconciler) backendDeployment(o *openragv1alpha1.OpenRAG, target
mounts = append(mounts, corev1.VolumeMount{Name: "backend-data", MountPath: "/app/backend-data"})
}
- envVars := r.backendSensitiveEnvVars(o)
- if spec.JWTSigningKeySecret != nil {
- envVars = append(envVars, corev1.EnvVar{
- Name: "JWT_SIGNING_KEY",
- ValueFrom: &corev1.EnvVarSource{SecretKeyRef: spec.JWTSigningKeySecret},
- })
- }
- envVars = append(envVars, spec.Env...)
+ // All sensitive values are now consolidated in the .env file
+ // Only use additional env vars from the CR spec
+ envVars := spec.Env
baseLabels := componentLabels(o.Name, "be")
deploymentLabels := mergeDeploymentLabels(baseLabels, spec.Labels)
@@ -740,8 +712,8 @@ func (r *OpenRAGReconciler) backendDeployment(o *openragv1alpha1.OpenRAG, target
Annotations: podAnnotations,
},
Spec: corev1.PodSpec{
- ServiceAccountName: saName("be"),
- ImagePullSecrets: o.Spec.ImagePullSecrets,
+ ServiceAccountName: getServiceAccountName(o, "be"),
+ ImagePullSecrets: mergeImagePullSecrets(o.Spec.ImagePullSecrets, spec.ImagePullSecrets),
NodeSelector: spec.NodeSelector,
Tolerations: spec.Tolerations,
Affinity: spec.Affinity,
@@ -771,62 +743,6 @@ func (r *OpenRAGReconciler) backendDeployment(o *openragv1alpha1.OpenRAG, target
}
}
-// backendSensitiveEnvVars returns env vars sourced from Secrets for the backend pod.
-// These override any matching keys in the mounted .env file.
-func (r *OpenRAGReconciler) backendSensitiveEnvVars(o *openragv1alpha1.OpenRAG) []corev1.EnvVar {
- var ev []corev1.EnvVar
-
- // LANGFLOW_SECRET_KEY - reference the secret, don't embed the value
- if o.Spec.Langflow.SecretKeySecret != nil {
- ev = append(ev, secretEnvVar("LANGFLOW_SECRET_KEY", o.Spec.Langflow.SecretKeySecret))
- } else {
- ev = append(ev, secretEnvVar("LANGFLOW_SECRET_KEY", &corev1.SecretKeySelector{
- LocalObjectReference: corev1.LocalObjectReference{Name: "langflow-secret-key"},
- Key: "LANGFLOW_SECRET_KEY",
- }))
- }
-
- // OPENRAG_ENCRYPTION_KEY - reference the secret, don't embed the value
- if o.Spec.Backend.EncryptionKeySecret != nil {
- ev = append(ev, secretEnvVar("OPENRAG_ENCRYPTION_KEY", o.Spec.Backend.EncryptionKeySecret))
- } else {
- ev = append(ev, secretEnvVar("OPENRAG_ENCRYPTION_KEY", &corev1.SecretKeySelector{
- LocalObjectReference: corev1.LocalObjectReference{Name: "openrag-be-encryption-key"},
- Key: "OPENRAG_ENCRYPTION_KEY",
- }))
- }
-
- // OpenSearch credentials
- if o.Spec.OpenSearch != nil && o.Spec.OpenSearch.CredentialsSecret != "" {
- cred := o.Spec.OpenSearch.CredentialsSecret
- ev = append(ev,
- secretEnvVar("OPENSEARCH_USERNAME", &corev1.SecretKeySelector{
- LocalObjectReference: corev1.LocalObjectReference{Name: cred}, Key: "username",
- }),
- secretEnvVar("OPENSEARCH_PASSWORD", &corev1.SecretKeySelector{
- LocalObjectReference: corev1.LocalObjectReference{Name: cred}, Key: "password",
- }),
- )
- }
-
- // WatsonX API key
- if o.Spec.WatsonX != nil && o.Spec.WatsonX.APIKeySecret != nil {
- ev = append(ev, secretEnvVar("WATSONX_API_KEY", o.Spec.WatsonX.APIKeySecret))
- }
-
- // OAuth secrets
- if oa := o.Spec.Backend.OAuth; oa != nil {
- if oa.Google != nil && oa.Google.ClientSecret != nil {
- ev = append(ev, secretEnvVar("GOOGLE_OAUTH_CLIENT_SECRET", oa.Google.ClientSecret))
- }
- if oa.Microsoft != nil && oa.Microsoft.ClientSecret != nil {
- ev = append(ev, secretEnvVar("MICROSOFT_GRAPH_OAUTH_CLIENT_SECRET", oa.Microsoft.ClientSecret))
- }
- }
-
- return ev
-}
-
func (r *OpenRAGReconciler) langflowDeployment(o *openragv1alpha1.OpenRAG, targetNS string) *appsv1.Deployment {
spec := o.Spec.Langflow
replicas := replicasOrDefault(spec.Replicas)
@@ -889,8 +805,9 @@ func (r *OpenRAGReconciler) langflowDeployment(o *openragv1alpha1.OpenRAG, targe
}
}
- envVars := r.langflowSensitiveEnvVars(o)
- envVars = append(envVars, spec.Env...)
+ // All sensitive values are now consolidated in the .env file
+ // Only use additional env vars from the CR spec
+ envVars := spec.Env
baseLabels := componentLabels(o.Name, "lf")
deploymentLabels := mergeDeploymentLabels(baseLabels, spec.Labels)
@@ -914,8 +831,8 @@ func (r *OpenRAGReconciler) langflowDeployment(o *openragv1alpha1.OpenRAG, targe
Annotations: podAnnotations,
},
Spec: corev1.PodSpec{
- ServiceAccountName: saName("lf"),
- ImagePullSecrets: o.Spec.ImagePullSecrets,
+ ServiceAccountName: getServiceAccountName(o, "lf"),
+ ImagePullSecrets: mergeImagePullSecrets(o.Spec.ImagePullSecrets, spec.ImagePullSecrets),
NodeSelector: spec.NodeSelector,
Tolerations: spec.Tolerations,
Affinity: spec.Affinity,
@@ -948,41 +865,6 @@ func (r *OpenRAGReconciler) langflowDeployment(o *openragv1alpha1.OpenRAG, targe
}
}
-// langflowSensitiveEnvVars returns env vars sourced from Secrets for the Langflow pod.
-func (r *OpenRAGReconciler) langflowSensitiveEnvVars(o *openragv1alpha1.OpenRAG) []corev1.EnvVar {
- var ev []corev1.EnvVar
-
- // LANGFLOW_SECRET_KEY - reference the secret, don't embed the value
- if o.Spec.Langflow.SecretKeySecret != nil {
- ev = append(ev, secretEnvVar("LANGFLOW_SECRET_KEY", o.Spec.Langflow.SecretKeySecret))
- } else {
- ev = append(ev, secretEnvVar("LANGFLOW_SECRET_KEY", &corev1.SecretKeySelector{
- LocalObjectReference: corev1.LocalObjectReference{Name: "langflow-secret-key"},
- Key: "LANGFLOW_SECRET_KEY",
- }))
- }
-
- // OpenSearch credentials
- if o.Spec.OpenSearch != nil && o.Spec.OpenSearch.CredentialsSecret != "" {
- cred := o.Spec.OpenSearch.CredentialsSecret
- ev = append(ev,
- secretEnvVar("OPENSEARCH_USERNAME", &corev1.SecretKeySelector{
- LocalObjectReference: corev1.LocalObjectReference{Name: cred}, Key: "username",
- }),
- secretEnvVar("OPENSEARCH_PASSWORD", &corev1.SecretKeySelector{
- LocalObjectReference: corev1.LocalObjectReference{Name: cred}, Key: "password",
- }),
- )
- }
-
- // WatsonX API key
- if o.Spec.WatsonX != nil && o.Spec.WatsonX.APIKeySecret != nil {
- ev = append(ev, secretEnvVar("WATSONX_API_KEY", o.Spec.WatsonX.APIKeySecret))
- }
-
- return ev
-}
-
func (r *OpenRAGReconciler) reconcileNetworkPolicy(ctx context.Context, o *openragv1alpha1.OpenRAG, targetNS string) error {
labels := componentLabels(o.Name, "lf")
@@ -1164,6 +1046,80 @@ func saName(role string) string {
return "openrag-" + role
}
+// getServiceAccountName returns the ServiceAccount name for a component.
+// If a custom name is specified in the spec, returns that; otherwise returns the default.
+func getServiceAccountName(o *openragv1alpha1.OpenRAG, role string) string {
+ var customName string
+ switch role {
+ case "fe":
+ customName = o.Spec.Frontend.ServiceAccountName
+ case "be":
+ customName = o.Spec.Backend.ServiceAccountName
+ case "lf":
+ customName = o.Spec.Langflow.ServiceAccountName
+ }
+ if customName != "" {
+ return customName
+ }
+ return saName(role)
+}
+
+// shouldCreateServiceAccount returns true if the operator should create the ServiceAccount.
+// Checks the CreateServiceAccount boolean flag (defaults to true if not specified).
+func shouldCreateServiceAccount(o *openragv1alpha1.OpenRAG, role string) bool {
+ var createFlag *bool
+ switch role {
+ case "fe":
+ createFlag = o.Spec.Frontend.CreateServiceAccount
+ case "be":
+ createFlag = o.Spec.Backend.CreateServiceAccount
+ case "lf":
+ createFlag = o.Spec.Langflow.CreateServiceAccount
+ }
+ // Default to true if not specified
+ if createFlag == nil {
+ return true
+ }
+ return *createFlag
+}
+
+// getServiceName returns the Service name for a component.
+// If a custom name is specified in the spec, returns that; otherwise returns the default.
+func getServiceName(o *openragv1alpha1.OpenRAG, role string) string {
+ var customName string
+ switch role {
+ case "fe":
+ customName = o.Spec.Frontend.ServiceName
+ case "be":
+ customName = o.Spec.Backend.ServiceName
+ case "lf":
+ customName = o.Spec.Langflow.ServiceName
+ }
+ if customName != "" {
+ return customName
+ }
+ return resourceName(role)
+}
+
+// shouldCreateService returns true if the operator should create the Service.
+// Checks the CreateService boolean flag (defaults to true if not specified).
+func shouldCreateService(o *openragv1alpha1.OpenRAG, role string) bool {
+ var createFlag *bool
+ switch role {
+ case "fe":
+ createFlag = o.Spec.Frontend.CreateService
+ case "be":
+ createFlag = o.Spec.Backend.CreateService
+ case "lf":
+ createFlag = o.Spec.Langflow.CreateService
+ }
+ // Default to true if not specified
+ if createFlag == nil {
+ return true
+ }
+ return *createFlag
+}
+
func componentLabels(crName, role string) map[string]string {
return map[string]string{
"app.kubernetes.io/name": "openrag",
@@ -1188,6 +1144,36 @@ func mergeLabels(baseLabels, customLabels map[string]string) map[string]string {
return merged
}
+// mergeImagePullSecrets merges global and component-specific imagePullSecrets.
+// Component-level secrets are added first, followed by global secrets.
+// Duplicates (same name) are automatically deduplicated, keeping the first occurrence.
+func mergeImagePullSecrets(global, component []corev1.LocalObjectReference) []corev1.LocalObjectReference {
+ if len(component) == 0 && len(global) == 0 {
+ return nil
+ }
+
+ seen := make(map[string]bool)
+ var merged []corev1.LocalObjectReference
+
+ // Add component secrets first
+ for _, secret := range component {
+ if !seen[secret.Name] {
+ merged = append(merged, secret)
+ seen[secret.Name] = true
+ }
+ }
+
+ // Add global secrets
+ for _, secret := range global {
+ if !seen[secret.Name] {
+ merged = append(merged, secret)
+ seen[secret.Name] = true
+ }
+ }
+
+ return merged
+}
+
// mergeAnnotations merges custom annotations.
func mergeAnnotations(customAnnotations map[string]string) map[string]string {
merged := make(map[string]string)
@@ -1254,9 +1240,70 @@ func udpPort(p int32) networkingv1.NetworkPolicyPort {
return networkingv1.NetworkPolicyPort{Port: &v, Protocol: &proto}
}
-func secretEnvVar(name string, sel *corev1.SecretKeySelector) corev1.EnvVar {
- return corev1.EnvVar{
- Name: name,
- ValueFrom: &corev1.EnvVarSource{SecretKeyRef: sel},
+// readSecretValue reads a secret value from a Kubernetes secret.
+// Returns the value and nil error if found, empty string and error otherwise.
+func (r *OpenRAGReconciler) readSecretValue(ctx context.Context, namespace string, sel *corev1.SecretKeySelector) (string, error) {
+ if sel == nil {
+ return "", nil
}
+
+ secret := &corev1.Secret{}
+ err := r.Get(ctx, client.ObjectKey{Namespace: namespace, Name: sel.Name}, secret)
+ if err != nil {
+ return "", err
+ }
+
+ value, ok := secret.Data[sel.Key]
+ if !ok {
+ return "", fmt.Errorf("key %s not found in secret %s", sel.Key, sel.Name)
+ }
+
+ return string(value), nil
+}
+
+// getOrGenerateSecret retrieves a secret value following this priority:
+// 1. If userSecretRef is provided in CR, read from that secret
+// 2. If value exists in existing .env secret, use that (for stability - never regenerate)
+// 3. Generate a new secret using the appropriate generation function
+// This consolidates all secrets into .env files without creating separate Kubernetes secrets.
+func (r *OpenRAGReconciler) getOrGenerateSecret(ctx context.Context, o *openragv1alpha1.OpenRAG, targetNS string, userSecretRef *corev1.SecretKeySelector, envKeyName, envSecretName string, genFunc func() (string, error)) (string, error) {
+ // Priority 1: User-provided secret in CR
+ if userSecretRef != nil {
+ value, err := r.readSecretValue(ctx, targetNS, userSecretRef)
+ if err != nil {
+ return "", fmt.Errorf("failed to read user-provided secret for %s: %w", envKeyName, err)
+ }
+ if value != "" {
+ return value, nil
+ }
+ }
+
+ // Priority 2: Check if key exists in the existing .env secret (for stability)
+ existingEnvSecret := &corev1.Secret{}
+ err := r.Get(ctx, client.ObjectKey{Name: envSecretName, Namespace: targetNS}, existingEnvSecret)
+ switch {
+ case err == nil:
+ if value := parseEnvValue(string(existingEnvSecret.Data[".env"]), envKeyName); value != "" {
+ return value, nil // Never regenerate existing key
+ }
+ case !errors.IsNotFound(err):
+ return "", fmt.Errorf("failed to read existing env secret %s for %s: %w", envSecretName, envKeyName, err)
+ }
+
+ // Priority 3: Generate new secret using the provided generation function
+ newSecret, err := genFunc()
+ if err != nil {
+ return "", fmt.Errorf("failed to generate secret for %s: %w", envKeyName, err)
+ }
+
+ // Log the secret generation for auditing and debugging
+ logger := log.FromContext(ctx)
+ logger.Info("Generated new secret",
+ "secretKey", envKeyName,
+ "openragName", o.Name,
+ "namespace", o.Namespace,
+ "tenantId", o.Spec.TenantID,
+ "targetNamespace", targetNS)
+
+ return newSecret, nil
}
diff --git a/kubernetes/operator/internal/controller/openrag_controller_test.go b/kubernetes/operator/internal/controller/openrag_controller_test.go
index 05caa40a4..59644afa7 100644
--- a/kubernetes/operator/internal/controller/openrag_controller_test.go
+++ b/kubernetes/operator/internal/controller/openrag_controller_test.go
@@ -8,6 +8,7 @@ import (
"github.com/stretchr/testify/require"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
+ "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
@@ -799,3 +800,467 @@ func TestReconcile_UUIDNameDNS1035Compliance(t *testing.T) {
assert.Equal(t, uuidName, beDeploy.Labels["app.kubernetes.io/instance"])
assert.Equal(t, uuidName, lfDeploy.Labels["app.kubernetes.io/instance"])
}
+
+// ---------------------------------------------------------------------------
+// ImagePullSecrets tests
+// ---------------------------------------------------------------------------
+
+func TestMergeImagePullSecrets_BothEmpty(t *testing.T) {
+ result := mergeImagePullSecrets(nil, nil)
+ assert.Nil(t, result)
+}
+
+func TestMergeImagePullSecrets_OnlyGlobal(t *testing.T) {
+ global := []corev1.LocalObjectReference{
+ {Name: "global-secret"},
+ }
+ result := mergeImagePullSecrets(global, nil)
+ assert.Equal(t, []corev1.LocalObjectReference{{Name: "global-secret"}}, result)
+}
+
+func TestMergeImagePullSecrets_OnlyComponent(t *testing.T) {
+ component := []corev1.LocalObjectReference{
+ {Name: "component-secret"},
+ }
+ result := mergeImagePullSecrets(nil, component)
+ assert.Equal(t, []corev1.LocalObjectReference{{Name: "component-secret"}}, result)
+}
+
+func TestMergeImagePullSecrets_BothPresent(t *testing.T) {
+ global := []corev1.LocalObjectReference{
+ {Name: "global-secret"},
+ }
+ component := []corev1.LocalObjectReference{
+ {Name: "component-secret"},
+ }
+ result := mergeImagePullSecrets(global, component)
+ expected := []corev1.LocalObjectReference{
+ {Name: "component-secret"},
+ {Name: "global-secret"},
+ }
+ assert.Equal(t, expected, result)
+}
+
+func TestMergeImagePullSecrets_Deduplication(t *testing.T) {
+ global := []corev1.LocalObjectReference{
+ {Name: "shared-secret"},
+ {Name: "global-only"},
+ }
+ component := []corev1.LocalObjectReference{
+ {Name: "component-only"},
+ {Name: "shared-secret"}, // Duplicate
+ }
+ result := mergeImagePullSecrets(global, component)
+ // Component secrets come first, dedup keeps first occurrence
+ expected := []corev1.LocalObjectReference{
+ {Name: "component-only"},
+ {Name: "shared-secret"}, // From component (first occurrence)
+ {Name: "global-only"},
+ }
+ assert.Equal(t, expected, result)
+}
+
+func TestReconcile_ComponentImagePullSecrets_Frontend(t *testing.T) {
+ s := newScheme(t)
+ cr := minimalCR("test-cr", "test-ns")
+ cr.Spec.Frontend.ImagePullSecrets = []corev1.LocalObjectReference{
+ {Name: "frontend-secret"},
+ }
+
+ r, c := reconciler(s, cr)
+ reconcileOnce(t, r, cr)
+
+ deploy := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("fe"), Namespace: "test-ns"}, deploy))
+
+ assert.Equal(t, []corev1.LocalObjectReference{{Name: "frontend-secret"}},
+ deploy.Spec.Template.Spec.ImagePullSecrets)
+}
+
+func TestReconcile_ComponentImagePullSecrets_Backend(t *testing.T) {
+ s := newScheme(t)
+ cr := minimalCR("test-cr", "test-ns")
+ cr.Spec.Backend.ImagePullSecrets = []corev1.LocalObjectReference{
+ {Name: "backend-secret"},
+ }
+
+ r, c := reconciler(s, cr)
+ reconcileOnce(t, r, cr)
+
+ deploy := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("be"), Namespace: "test-ns"}, deploy))
+
+ assert.Equal(t, []corev1.LocalObjectReference{{Name: "backend-secret"}},
+ deploy.Spec.Template.Spec.ImagePullSecrets)
+}
+
+func TestReconcile_ComponentImagePullSecrets_Langflow(t *testing.T) {
+ s := newScheme(t)
+ cr := minimalCR("test-cr", "test-ns")
+ cr.Spec.Langflow.ImagePullSecrets = []corev1.LocalObjectReference{
+ {Name: "langflow-secret"},
+ }
+
+ r, c := reconciler(s, cr)
+ reconcileOnce(t, r, cr)
+
+ deploy := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("lf"), Namespace: "test-ns"}, deploy))
+
+ assert.Equal(t, []corev1.LocalObjectReference{{Name: "langflow-secret"}},
+ deploy.Spec.Template.Spec.ImagePullSecrets)
+}
+
+func TestReconcile_GlobalAndComponentImagePullSecrets(t *testing.T) {
+ s := newScheme(t)
+ cr := minimalCR("test-cr", "test-ns")
+ // Set global secrets
+ cr.Spec.ImagePullSecrets = []corev1.LocalObjectReference{
+ {Name: "global-secret"},
+ }
+ // Set component-specific secrets
+ cr.Spec.Frontend.ImagePullSecrets = []corev1.LocalObjectReference{
+ {Name: "frontend-secret"},
+ }
+ cr.Spec.Backend.ImagePullSecrets = []corev1.LocalObjectReference{
+ {Name: "backend-secret"},
+ }
+ cr.Spec.Langflow.ImagePullSecrets = []corev1.LocalObjectReference{
+ {Name: "langflow-secret"},
+ }
+
+ r, c := reconciler(s, cr)
+ reconcileOnce(t, r, cr)
+
+ // Check frontend: should have both frontend-specific and global
+ feDeploy := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("fe"), Namespace: "test-ns"}, feDeploy))
+ assert.Equal(t, []corev1.LocalObjectReference{
+ {Name: "frontend-secret"},
+ {Name: "global-secret"},
+ }, feDeploy.Spec.Template.Spec.ImagePullSecrets)
+
+ // Check backend: should have both backend-specific and global
+ beDeploy := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("be"), Namespace: "test-ns"}, beDeploy))
+ assert.Equal(t, []corev1.LocalObjectReference{
+ {Name: "backend-secret"},
+ {Name: "global-secret"},
+ }, beDeploy.Spec.Template.Spec.ImagePullSecrets)
+
+ // Check langflow: should have both langflow-specific and global
+ lfDeploy := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("lf"), Namespace: "test-ns"}, lfDeploy))
+ assert.Equal(t, []corev1.LocalObjectReference{
+ {Name: "langflow-secret"},
+ {Name: "global-secret"},
+ }, lfDeploy.Spec.Template.Spec.ImagePullSecrets)
+}
+
+func TestReconcile_OnlyGlobalImagePullSecrets(t *testing.T) {
+ s := newScheme(t)
+ cr := minimalCR("test-cr", "test-ns")
+ cr.Spec.ImagePullSecrets = []corev1.LocalObjectReference{
+ {Name: "global-secret"},
+ }
+
+ r, c := reconciler(s, cr)
+ reconcileOnce(t, r, cr)
+
+ // All components should use the global secret
+ feDeploy := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("fe"), Namespace: "test-ns"}, feDeploy))
+ assert.Equal(t, []corev1.LocalObjectReference{{Name: "global-secret"}},
+ feDeploy.Spec.Template.Spec.ImagePullSecrets)
+
+ beDeploy := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("be"), Namespace: "test-ns"}, beDeploy))
+ assert.Equal(t, []corev1.LocalObjectReference{{Name: "global-secret"}},
+ beDeploy.Spec.Template.Spec.ImagePullSecrets)
+
+ lfDeploy := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("lf"), Namespace: "test-ns"}, lfDeploy))
+ assert.Equal(t, []corev1.LocalObjectReference{{Name: "global-secret"}},
+ lfDeploy.Spec.Template.Spec.ImagePullSecrets)
+}
+
+// ---------------------------------------------------------------------------
+// Custom ServiceAccount and Service Name tests
+// ---------------------------------------------------------------------------
+
+func TestReconcile_CustomServiceAccountName_OperatorCreates(t *testing.T) {
+ s := newScheme(t)
+ cr := minimalCR("test-cr", "test-ns")
+ cr.Spec.Frontend.ServiceAccountName = "my-custom-sa"
+ // CreateServiceAccount defaults to true, so operator will create it
+
+ r, c := reconciler(s, cr)
+ reconcileOnce(t, r, cr)
+
+ // Verify operator created the SA with custom name
+ customSA := &corev1.ServiceAccount{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: "my-custom-sa", Namespace: "test-ns"}, customSA))
+
+ // Verify deployment uses the custom SA
+ deploy := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("fe"), Namespace: "test-ns"}, deploy))
+ assert.Equal(t, "my-custom-sa", deploy.Spec.Template.Spec.ServiceAccountName)
+
+ // Verify operator did NOT create the default SA
+ defaultSA := &corev1.ServiceAccount{}
+ err := c.Get(context.Background(),
+ types.NamespacedName{Name: saName("fe"), Namespace: "test-ns"}, defaultSA)
+ assert.True(t, errors.IsNotFound(err), "Default SA should not be created when custom name is specified")
+}
+
+func TestReconcile_CustomServiceAccountName_UserManaged(t *testing.T) {
+ s := newScheme(t)
+ cr := minimalCR("test-cr", "test-ns")
+ cr.Spec.Frontend.ServiceAccountName = "my-custom-sa"
+ createSA := false
+ cr.Spec.Frontend.CreateServiceAccount = &createSA // User manages the SA
+
+ // Pre-create the user-managed service account
+ customSA := &corev1.ServiceAccount{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "my-custom-sa",
+ Namespace: "test-ns",
+ },
+ }
+
+ r, c := reconciler(s, cr, customSA)
+ reconcileOnce(t, r, cr)
+
+ // Verify deployment uses the custom SA
+ deploy := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("fe"), Namespace: "test-ns"}, deploy))
+ assert.Equal(t, "my-custom-sa", deploy.Spec.Template.Spec.ServiceAccountName)
+
+ // Verify the SA still exists and wasn't recreated (check it's the pre-created one)
+ sa := &corev1.ServiceAccount{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: "my-custom-sa", Namespace: "test-ns"}, sa))
+}
+
+func TestReconcile_DefaultServiceAccountName(t *testing.T) {
+ s := newScheme(t)
+ cr := minimalCR("test-cr", "test-ns")
+ // No custom SA specified
+
+ r, c := reconciler(s, cr)
+ reconcileOnce(t, r, cr)
+
+ // Verify operator creates the default SA
+ defaultSA := &corev1.ServiceAccount{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: saName("fe"), Namespace: "test-ns"}, defaultSA))
+
+ // Verify deployment uses the default SA
+ deploy := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("fe"), Namespace: "test-ns"}, deploy))
+ assert.Equal(t, saName("fe"), deploy.Spec.Template.Spec.ServiceAccountName)
+}
+
+func TestReconcile_CustomServiceName_OperatorCreates(t *testing.T) {
+ s := newScheme(t)
+ cr := minimalCR("test-cr", "test-ns")
+ cr.Spec.Backend.ServiceName = "my-backend-svc"
+ // CreateService defaults to true, so operator will create it
+
+ r, c := reconciler(s, cr)
+ reconcileOnce(t, r, cr)
+
+ // Verify operator created the Service with custom name
+ customSvc := &corev1.Service{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: "my-backend-svc", Namespace: "test-ns"}, customSvc))
+ assert.Equal(t, int32(8000), customSvc.Spec.Ports[0].Port)
+
+ // Verify operator did NOT create the default Service
+ defaultSvc := &corev1.Service{}
+ err := c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("be"), Namespace: "test-ns"}, defaultSvc)
+ assert.True(t, errors.IsNotFound(err), "Default Service should not be created when custom name is specified")
+
+ // Verify backend env secret references the custom service name
+ secret := &corev1.Secret{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("be-env"), Namespace: "test-ns"}, secret))
+
+ envContent := string(secret.Data[".env"])
+ if envContent == "" && secret.StringData != nil {
+ envContent = secret.StringData[".env"]
+ }
+ assert.Contains(t, envContent, "LANGFLOW_URL=http://"+resourceName("lf")+":7860",
+ "Backend env should reference default langflow service")
+}
+
+func TestReconcile_CustomServiceName_UserManaged(t *testing.T) {
+ s := newScheme(t)
+ cr := minimalCR("test-cr", "test-ns")
+ cr.Spec.Backend.ServiceName = "my-backend-svc"
+ createSvc := false
+ cr.Spec.Backend.CreateService = &createSvc // User manages the Service
+
+ // Pre-create the user-managed service
+ customSvc := &corev1.Service{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "my-backend-svc",
+ Namespace: "test-ns",
+ },
+ Spec: corev1.ServiceSpec{
+ Ports: []corev1.ServicePort{
+ {Name: "http", Port: 8000, Protocol: corev1.ProtocolTCP},
+ },
+ },
+ }
+
+ r, c := reconciler(s, cr, customSvc)
+ reconcileOnce(t, r, cr)
+
+ // Verify the Service still exists and wasn't recreated
+ svc := &corev1.Service{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: "my-backend-svc", Namespace: "test-ns"}, svc))
+
+ // Verify operator did NOT create the default Service
+ defaultSvc := &corev1.Service{}
+ err := c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("be"), Namespace: "test-ns"}, defaultSvc)
+ assert.True(t, errors.IsNotFound(err), "Default Service should not be created when custom name is specified")
+}
+
+func TestReconcile_CustomServiceName_UsedInFrontendEnv(t *testing.T) {
+ s := newScheme(t)
+ cr := minimalCR("test-cr", "test-ns")
+ cr.Spec.Backend.ServiceName = "custom-be-svc"
+
+ // Pre-create the custom service
+ customSvc := &corev1.Service{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "custom-be-svc",
+ Namespace: "test-ns",
+ },
+ Spec: corev1.ServiceSpec{
+ Ports: []corev1.ServicePort{
+ {Name: "http", Port: 8000, Protocol: corev1.ProtocolTCP},
+ },
+ },
+ }
+
+ r, c := reconciler(s, cr, customSvc)
+ reconcileOnce(t, r, cr)
+
+ // Verify frontend deployment references the custom backend service name
+ deploy := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("fe"), Namespace: "test-ns"}, deploy))
+
+ var backendHost string
+ for _, env := range deploy.Spec.Template.Spec.Containers[0].Env {
+ if env.Name == "OPENRAG_BACKEND_HOST" {
+ backendHost = env.Value
+ break
+ }
+ }
+ assert.Equal(t, "custom-be-svc", backendHost,
+ "Frontend should reference custom backend service name")
+}
+
+func TestReconcile_CustomServiceName_Langflow_UsedInBackendEnv(t *testing.T) {
+ s := newScheme(t)
+ cr := minimalCR("test-cr", "test-ns")
+ cr.Spec.Langflow.ServiceName = "custom-lf-svc"
+
+ // Pre-create the custom service
+ customSvc := &corev1.Service{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "custom-lf-svc",
+ Namespace: "test-ns",
+ },
+ Spec: corev1.ServiceSpec{
+ Ports: []corev1.ServicePort{
+ {Name: "http", Port: 7860, Protocol: corev1.ProtocolTCP},
+ },
+ },
+ }
+
+ r, c := reconciler(s, cr, customSvc)
+ reconcileOnce(t, r, cr)
+
+ // Verify backend env secret references the custom langflow service name
+ secret := &corev1.Secret{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("be-env"), Namespace: "test-ns"}, secret))
+
+ envContent := string(secret.Data[".env"])
+ if envContent == "" && secret.StringData != nil {
+ envContent = secret.StringData[".env"]
+ }
+ assert.Contains(t, envContent, "LANGFLOW_URL=http://custom-lf-svc:7860",
+ "Backend env should reference custom langflow service name")
+}
+
+func TestReconcile_AllComponentsWithCustomNames_OperatorCreates(t *testing.T) {
+ s := newScheme(t)
+ cr := minimalCR("test-cr", "test-ns")
+
+ // Set custom names for all components (operator will create them by default)
+ cr.Spec.Frontend.ServiceAccountName = "custom-fe-sa"
+ cr.Spec.Frontend.ServiceName = "custom-fe-svc"
+ cr.Spec.Backend.ServiceAccountName = "custom-be-sa"
+ cr.Spec.Backend.ServiceName = "custom-be-svc"
+ cr.Spec.Langflow.ServiceAccountName = "custom-lf-sa"
+ cr.Spec.Langflow.ServiceName = "custom-lf-svc"
+
+ r, c := reconciler(s, cr)
+ reconcileOnce(t, r, cr)
+
+ // Verify operator created all custom SAs
+ for _, name := range []string{"custom-fe-sa", "custom-be-sa", "custom-lf-sa"} {
+ sa := &corev1.ServiceAccount{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: name, Namespace: "test-ns"}, sa),
+ "Operator should create SA %s", name)
+ }
+
+ // Verify operator created all custom Services
+ for _, name := range []string{"custom-fe-svc", "custom-be-svc", "custom-lf-svc"} {
+ svc := &corev1.Service{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: name, Namespace: "test-ns"}, svc),
+ "Operator should create Service %s", name)
+ }
+
+ // Verify all deployments use custom names
+ feDeploy := &appsv1.Deployment{}
+ require.NoError(t, c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName("fe"), Namespace: "test-ns"}, feDeploy))
+ assert.Equal(t, "custom-fe-sa", feDeploy.Spec.Template.Spec.ServiceAccountName)
+
+ // Verify no default SAs or Services were created
+ for _, role := range []string{"fe", "be", "lf"} {
+ defaultSA := &corev1.ServiceAccount{}
+ err := c.Get(context.Background(),
+ types.NamespacedName{Name: saName(role), Namespace: "test-ns"}, defaultSA)
+ assert.True(t, errors.IsNotFound(err), "Default SA for %s should not be created", role)
+
+ defaultSvc := &corev1.Service{}
+ err = c.Get(context.Background(),
+ types.NamespacedName{Name: resourceName(role), Namespace: "test-ns"}, defaultSvc)
+ assert.True(t, errors.IsNotFound(err), "Default Service for %s should not be created", role)
+ }
+}