This is an automated email from the ASF dual-hosted git repository.
HoustonPutman pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr-operator.git
The following commit(s) were added to refs/heads/main by this push:
new 6637b437 feat: support envFrom on Solr pods (#877)
6637b437 is described below
commit 6637b437ca0aa1848fd73fa32b94ff001b89142a
Author: Anurag-S1ngh <[email protected]>
AuthorDate: Tue Nov 17 01:35:07 2026 +0530
feat: support envFrom on Solr pods (#877)
Co-authored-by: Houston Putman <[email protected]>
---
api/v1beta1/common_types.go | 5 +
api/v1beta1/zz_generated.deepcopy.go | 7 ++
config/crd/bases/solr.apache.org_solrclouds.yaml | 51 +++++++++++
.../solr.apache.org_solrprometheusexporters.yaml | 51 +++++++++++
controllers/controller_utils_test.go | 7 ++
controllers/solrcloud_controller_test.go | 2 +
controllers/util/common.go | 6 ++
controllers/util/solr_util.go | 5 +-
.../solr-cloud/pages/custom-kube-options.adoc | 33 +++++++
helm/solr-operator/Chart.yaml | 7 ++
helm/solr-operator/crds/crds.yaml | 102 +++++++++++++++++++++
helm/solr/README.md | 1 +
helm/solr/templates/_custom_option_helpers.tpl | 4 +
helm/solr/values.yaml | 1 +
14 files changed, 281 insertions(+), 1 deletion(-)
diff --git a/api/v1beta1/common_types.go b/api/v1beta1/common_types.go
index c125b759..32a13d69 100644
--- a/api/v1beta1/common_types.go
+++ b/api/v1beta1/common_types.go
@@ -81,6 +81,11 @@ type PodOptions struct {
// +optional
EnvVariables []corev1.EnvVar `json:"envVars,omitempty"`
+ // Additional environment variables to load into the default container
from
+ // ConfigMaps or Secrets.
+ // +optional
+ EnvFrom []corev1.EnvFromSource `json:"envFrom,omitempty"`
+
// Annotations to be added for pods.
// +optional
Annotations map[string]string `json:"annotations,omitempty"`
diff --git a/api/v1beta1/zz_generated.deepcopy.go
b/api/v1beta1/zz_generated.deepcopy.go
index b3e4dc64..5018ffa8 100644
--- a/api/v1beta1/zz_generated.deepcopy.go
+++ b/api/v1beta1/zz_generated.deepcopy.go
@@ -451,6 +451,13 @@ func (in *PodOptions) DeepCopyInto(out *PodOptions) {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
+ if in.EnvFrom != nil {
+ in, out := &in.EnvFrom, &out.EnvFrom
+ *out = make([]v1.EnvFromSource, len(*in))
+ for i := range *in {
+ (*in)[i].DeepCopyInto(&(*out)[i])
+ }
+ }
if in.Annotations != nil {
in, out := &in.Annotations, &out.Annotations
*out = make(map[string]string, len(*in))
diff --git a/config/crd/bases/solr.apache.org_solrclouds.yaml
b/config/crd/bases/solr.apache.org_solrclouds.yaml
index 52174c97..570d78ec 100644
--- a/config/crd/bases/solr.apache.org_solrclouds.yaml
+++ b/config/crd/bases/solr.apache.org_solrclouds.yaml
@@ -3913,6 +3913,57 @@ spec:
description: Should service environment variables be
created
on containers
type: boolean
+ envFrom:
+ description: |-
+ Additional environment variables to load into the
default container from
+ ConfigMaps or Secrets.
+ items:
+ description: EnvFromSource represents the source of
a set
+ of ConfigMaps or Secrets
+ properties:
+ configMapRef:
+ description: The ConfigMap to select from
+ 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
+ optional:
+ description: Specify whether the ConfigMap
must
+ be defined
+ type: boolean
+ type: object
+ x-kubernetes-map-type: atomic
+ prefix:
+ description: |-
+ Optional text to prepend to the name of each
environment variable.
+ May consist of any printable ASCII characters
except '='.
+ type: string
+ secretRef:
+ description: The Secret to select from
+ 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
+ optional:
+ description: Specify whether the Secret must
be
+ defined
+ type: boolean
+ type: object
+ x-kubernetes-map-type: atomic
+ type: object
+ type: array
envVars:
description: Additional environment variables to pass
to the
default container.
diff --git a/config/crd/bases/solr.apache.org_solrprometheusexporters.yaml
b/config/crd/bases/solr.apache.org_solrprometheusexporters.yaml
index e427710f..e48b1e89 100644
--- a/config/crd/bases/solr.apache.org_solrprometheusexporters.yaml
+++ b/config/crd/bases/solr.apache.org_solrprometheusexporters.yaml
@@ -1507,6 +1507,57 @@ spec:
description: Should service environment variables be
created
on containers
type: boolean
+ envFrom:
+ description: |-
+ Additional environment variables to load into the
default container from
+ ConfigMaps or Secrets.
+ items:
+ description: EnvFromSource represents the source of
a set
+ of ConfigMaps or Secrets
+ properties:
+ configMapRef:
+ description: The ConfigMap to select from
+ 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
+ optional:
+ description: Specify whether the ConfigMap
must
+ be defined
+ type: boolean
+ type: object
+ x-kubernetes-map-type: atomic
+ prefix:
+ description: |-
+ Optional text to prepend to the name of each
environment variable.
+ May consist of any printable ASCII characters
except '='.
+ type: string
+ secretRef:
+ description: The Secret to select from
+ 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
+ optional:
+ description: Specify whether the Secret must
be
+ defined
+ type: boolean
+ type: object
+ x-kubernetes-map-type: atomic
+ type: object
+ type: array
envVars:
description: Additional environment variables to pass
to the
default container.
diff --git a/controllers/controller_utils_test.go
b/controllers/controller_utils_test.go
index 79041f80..747671d8 100644
--- a/controllers/controller_utils_test.go
+++ b/controllers/controller_utils_test.go
@@ -923,6 +923,13 @@ var (
},
},
}
+ extraEnvFrom = []corev1.EnvFromSource{
+ {
+ ConfigMapRef: &corev1.ConfigMapEnvSource{
+ LocalObjectReference:
corev1.LocalObjectReference{Name: "extra-config"},
+ },
+ },
+ }
one = int64(1)
two = int64(2)
three = int64(3)
diff --git a/controllers/solrcloud_controller_test.go
b/controllers/solrcloud_controller_test.go
index a56a8206..6cadfea6 100644
--- a/controllers/solrcloud_controller_test.go
+++ b/controllers/solrcloud_controller_test.go
@@ -84,6 +84,7 @@ var _ = FDescribe("SolrCloud controller - General", func() {
CustomSolrKubeOptions:
solrv1beta1.CustomSolrKubeOptions{
PodOptions: &solrv1beta1.PodOptions{
EnvVariables: extraVars,
+ EnvFrom:
extraEnvFrom,
PodSecurityContext:
&testPodSecurityContext,
Volumes:
extraVolumes,
Affinity:
testAffinity,
@@ -138,6 +139,7 @@ var _ = FDescribe("SolrCloud controller - General", func() {
// Other Pod Options Checks
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PostStart).To(BeNil(),
"Post-start command should be nil.")
+
Expect(statefulSet.Spec.Template.Spec.Containers[0].EnvFrom).To(Equal(extraEnvFrom),
"EnvFrom is not the same as the one provided in podOptions")
Expect(statefulSet.Spec.Template.Spec.SecurityContext).To(Not(BeNil()),
"PodSecurityContext is not the same as the one provided in podOptions")
Expect(*statefulSet.Spec.Template.Spec.SecurityContext).To(Equal(testPodSecurityContext),
"PodSecurityContext is not the same as the one provided in podOptions")
Expect(statefulSet.Spec.Template.Spec.Affinity).To(Equal(testAffinity),
"Affinity is not the same as the one provided in podOptions")
diff --git a/controllers/util/common.go b/controllers/util/common.go
index 600abb68..c8ef59c7 100644
--- a/controllers/util/common.go
+++ b/controllers/util/common.go
@@ -601,6 +601,12 @@ func CopyPodContainers(fromPtr, toPtr *[]corev1.Container,
basePath string, logg
to[i].Env = from[i].Env
}
+ if !DeepEqualWithNils(to[i].EnvFrom, from[i].EnvFrom) {
+ requireUpdate = true
+ logger.Info("Update required because field
changed", "field", containerBasePath+"EnvFrom", "from", to[i].EnvFrom, "to",
from[i].EnvFrom)
+ to[i].EnvFrom = from[i].EnvFrom
+ }
+
requireUpdate = CopyResources(&from[i].Resources,
&to[i].Resources, containerBasePath+"Resources.", logger) || requireUpdate
if !DeepEqualWithNils(to[i].VolumeMounts,
from[i].VolumeMounts) {
diff --git a/controllers/util/solr_util.go b/controllers/util/solr_util.go
index 89fddae1..b0cf8a88 100644
--- a/controllers/util/solr_util.go
+++ b/controllers/util/solr_util.go
@@ -329,6 +329,7 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud,
solrCloudStatus *solr.SolrCl
}
// Environment Variables
+ var envFrom []corev1.EnvFromSource
envVars := []corev1.EnvVar{
{
Name: "SOLR_JAVA_MEM",
@@ -449,9 +450,10 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud,
solrCloudStatus *solr.SolrCl
},
}
- // Add Custom EnvironmentVariables to the solr container
+ // Add Custom EnvironmentVariables and EnvFrom to the solr container
if nil != customPodOptions {
envVars = append(envVars, customPodOptions.EnvVariables...)
+ envFrom = append(envFrom, customPodOptions.EnvFrom...)
}
// Did the user provide a custom log config?
@@ -537,6 +539,7 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud,
solrCloudStatus *solr.SolrCl
},
VolumeMounts: volumeMounts,
Env: envVars,
+ EnvFrom: envFrom,
Lifecycle: &corev1.Lifecycle{
PreStop: preStop,
},
diff --git a/docs/modules/solr-cloud/pages/custom-kube-options.adoc
b/docs/modules/solr-cloud/pages/custom-kube-options.adoc
index 02be794c..0cbbcf48 100644
--- a/docs/modules/solr-cloud/pages/custom-kube-options.adoc
+++ b/docs/modules/solr-cloud/pages/custom-kube-options.adoc
@@ -68,6 +68,39 @@ spec:
A complete, runnable example (including the backing `ConfigMap`) is available
in
https://github.com/apache/solr-operator/blob/main/example/test_solrcloud_additional_volume.yaml[`example/test_solrcloud_additional_volume.yaml`].
+== Environment Variables
+
+Additional environment variables can be added to the Solr container in two
ways, both under `SolrCloud.spec.customSolrKubeOptions.podOptions`:
+
+* **`envVars`** - A list of individual
https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/[environment
variables], each either a literal `value` or a `valueFrom` reference to a
single key.
+* **`envFrom`** - A list of
https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#configure-all-key-value-pairs-in-a-configmap-as-container-environment-variables[`envFrom`
sources], each loading every key of a `ConfigMap` (`configMapRef`) or `Secret`
(`secretRef`) as an environment variable.
+An optional `prefix` is prepended to each variable name, and `optional: true`
lets the pod start even if the referenced resource does not exist.
+
+Variables set by the operator and by `envVars` take precedence over those
loaded via `envFrom`, since Kubernetes gives `env` priority over `envFrom` when
the same name is defined in both.
+This means `envFrom` cannot be used to override the environment variables the
operator sets, such as `SOLR_JAVA_MEM` or `ZK_HOST`.
+
+Kubernetes only reads the referenced `ConfigMaps` and `Secrets` when a
container starts.
+Changing their contents does not restart the Solr pods, so the new values are
only picked up once the pods are restarted for another reason.
+
+The following example sets a single variable directly, and loads all keys of a
`ConfigMap`, and all keys of a `Secret` with a `SOLR_` prefix, into the Solr
container:
+
+[source,yaml]
+----
+spec:
+ customSolrKubeOptions:
+ podOptions:
+ envVars:
+ - name: SOLR_LOG_LEVEL
+ value: WARN
+ envFrom:
+ - configMapRef:
+ name: solr-env-config
+ - prefix: SOLR_
+ secretRef:
+ name: solr-env-secrets
+ optional: true
+----
+
== Service Session Affinity
The Services that the operator creates for a SolrCloud
(`commonServiceOptions`, `headlessServiceOptions`, and `nodeServiceOptions`)
can be configured with
https://kubernetes.io/docs/reference/networking/virtual-ips/#session-affinity[session
affinity].
diff --git a/helm/solr-operator/Chart.yaml b/helm/solr-operator/Chart.yaml
index 25878ea8..ad6a8b68 100644
--- a/helm/solr-operator/Chart.yaml
+++ b/helm/solr-operator/Chart.yaml
@@ -167,6 +167,13 @@ annotations:
url: https://github.com/apache/solr-operator/issues/707
- name: Github PR
url: https://github.com/apache/solr-operator/pull/876
+ - kind: added
+ description: Ability to load environment variables into the Solr
container from ConfigMaps or Secrets via `podOptions.envFrom`
+ links:
+ - name: GitHub Issue
+ url: https://github.com/apache/solr-operator/issues/677
+ - name: GitHub PR
+ url: https://github.com/apache/solr-operator/pull/877
- kind: added
description: Solr pods now get the availability_zone system property,
used by Solr's AffinityPlacementFactory, from the topology.kubernetes.io/zone
label of their Kubernetes node. The label is copied onto pods by Kubernetes
v1.35+, and the property is empty on older versions. Solr pods also get the
spread_domain system property, set to the name of their Kubernetes node
links:
diff --git a/helm/solr-operator/crds/crds.yaml
b/helm/solr-operator/crds/crds.yaml
index 5756983f..c270b9b5 100644
--- a/helm/solr-operator/crds/crds.yaml
+++ b/helm/solr-operator/crds/crds.yaml
@@ -4171,6 +4171,57 @@ spec:
description: Should service environment variables be
created
on containers
type: boolean
+ envFrom:
+ description: |-
+ Additional environment variables to load into the
default container from
+ ConfigMaps or Secrets.
+ items:
+ description: EnvFromSource represents the source of
a set
+ of ConfigMaps or Secrets
+ properties:
+ configMapRef:
+ description: The ConfigMap to select from
+ 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
+ optional:
+ description: Specify whether the ConfigMap
must
+ be defined
+ type: boolean
+ type: object
+ x-kubernetes-map-type: atomic
+ prefix:
+ description: |-
+ Optional text to prepend to the name of each
environment variable.
+ May consist of any printable ASCII characters
except '='.
+ type: string
+ secretRef:
+ description: The Secret to select from
+ 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
+ optional:
+ description: Specify whether the Secret must
be
+ defined
+ type: boolean
+ type: object
+ x-kubernetes-map-type: atomic
+ type: object
+ type: array
envVars:
description: Additional environment variables to pass
to the
default container.
@@ -21205,6 +21256,57 @@ spec:
description: Should service environment variables be
created
on containers
type: boolean
+ envFrom:
+ description: |-
+ Additional environment variables to load into the
default container from
+ ConfigMaps or Secrets.
+ items:
+ description: EnvFromSource represents the source of
a set
+ of ConfigMaps or Secrets
+ properties:
+ configMapRef:
+ description: The ConfigMap to select from
+ 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
+ optional:
+ description: Specify whether the ConfigMap
must
+ be defined
+ type: boolean
+ type: object
+ x-kubernetes-map-type: atomic
+ prefix:
+ description: |-
+ Optional text to prepend to the name of each
environment variable.
+ May consist of any printable ASCII characters
except '='.
+ type: string
+ secretRef:
+ description: The Secret to select from
+ 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
+ optional:
+ description: Specify whether the Secret must
be
+ defined
+ type: boolean
+ type: object
+ x-kubernetes-map-type: atomic
+ type: object
+ type: array
envVars:
description: Additional environment variables to pass
to the
default container.
diff --git a/helm/solr/README.md b/helm/solr/README.md
index 02bce33e..6b649d67 100644
--- a/helm/solr/README.md
+++ b/helm/solr/README.md
@@ -293,6 +293,7 @@ When using the helm chart, omit `customSolrKubeOptions.`
| podOptions.sidecarContainers | []object | | An optional list of additional
containers to run along side the Solr in its pod |
| podOptions.initContainers | []object | | An optional list of additional
initContainers to run before the Solr container starts |
| podOptions.envVars | []object | | List of additional environment variables
for the Solr container |
+| podOptions.envFrom | []object | | List of ConfigMap or Secret sources to
load as environment variables in the Solr container. Variables set via
`envVars` or by the operator take precedence |
| podOptions.podSecurityContext | object | | Security context for the Solr
pod |
| podOptions.containerSecurityContext | object | | Security context for the
Solr container in each pod |
| podOptions.terminationGracePeriodSeconds | int | | Optional amount of time
to wait for Solr to stop on its own, before manually killing it |
diff --git a/helm/solr/templates/_custom_option_helpers.tpl
b/helm/solr/templates/_custom_option_helpers.tpl
index cfe1dc9c..6b37e670 100644
--- a/helm/solr/templates/_custom_option_helpers.tpl
+++ b/helm/solr/templates/_custom_option_helpers.tpl
@@ -49,6 +49,10 @@ priorityClassName: {{ .Values.podOptions.priorityClassName }}
envVars:
{{- toYaml .Values.podOptions.envVars | nindent 2 }}
{{ end }}
+{{- if .Values.podOptions.envFrom -}}
+envFrom:
+ {{- toYaml .Values.podOptions.envFrom | nindent 2 }}
+{{ end }}
{{- if .Values.podOptions.affinity -}}
affinity:
{{- toYaml .Values.podOptions.affinity | nindent 2 }}
diff --git a/helm/solr/values.yaml b/helm/solr/values.yaml
index 07599d99..7a7b85b1 100644
--- a/helm/solr/values.yaml
+++ b/helm/solr/values.yaml
@@ -298,6 +298,7 @@ podOptions:
priorityClassName: ""
envVars: []
+ envFrom: []
podSecurityContext: {}
containerSecurityContext: {}
terminationGracePeriodSeconds: null