From c8220e96d237315d6ddc75849f1d5ff93329910c Mon Sep 17 00:00:00 2001 From: jd252387 Date: Fri, 20 Jun 2025 16:52:40 +0000 Subject: [PATCH 1/3] fix: Add abillity to set enableServiceLinks --- api/v1beta1/common_types.go | 4 ++++ config/crd/bases/solr.apache.org_solrclouds.yaml | 5 +++++ .../bases/solr.apache.org_solrprometheusexporters.yaml | 5 +++++ controllers/solrcloud_controller_test.go | 4 ++++ controllers/util/solr_util.go | 3 +++ helm/solr-operator/Chart.yaml | 2 ++ helm/solr-operator/crds/crds.yaml | 10 ++++++++++ helm/solr/README.md | 1 + helm/solr/templates/_custom_option_helpers.tpl | 3 +++ helm/solr/values.yaml | 2 ++ 10 files changed, 39 insertions(+) diff --git a/api/v1beta1/common_types.go b/api/v1beta1/common_types.go index 22002243..d62e7dd6 100644 --- a/api/v1beta1/common_types.go +++ b/api/v1beta1/common_types.go @@ -145,6 +145,10 @@ type PodOptions struct { // +optional ShareProcessNamespace bool `json:"shareProcessNamespace,omitempty"` + // Should process namespace sharing be enabled on created pods + // +optional + EnableServiceLinks bool `json:"enableServiceLinks,omitempty"` + // Optional PodSpreadTopologyConstraints to use when scheduling pods. // More information here: https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/ // diff --git a/config/crd/bases/solr.apache.org_solrclouds.yaml b/config/crd/bases/solr.apache.org_solrclouds.yaml index 76809b56..bb4e2b72 100644 --- a/config/crd/bases/solr.apache.org_solrclouds.yaml +++ b/config/crd/bases/solr.apache.org_solrclouds.yaml @@ -5800,6 +5800,11 @@ spec: description: Should process namespace sharing be enabled on created pods type: boolean + enableServiceLinks: + description: |- + Should service environment variables be created on containers. + More info: https://kubernetes.io/docs/tutorials/services/connect-applications-service/#accessing-the-service + type: boolean sidecarContainers: description: Sidecar containers to run in the pod. These are in addition to the Solr Container diff --git a/config/crd/bases/solr.apache.org_solrprometheusexporters.yaml b/config/crd/bases/solr.apache.org_solrprometheusexporters.yaml index 766b8884..ffe6e9c8 100644 --- a/config/crd/bases/solr.apache.org_solrprometheusexporters.yaml +++ b/config/crd/bases/solr.apache.org_solrprometheusexporters.yaml @@ -3717,6 +3717,11 @@ spec: description: Should process namespace sharing be enabled on created pods type: boolean + enableServiceLinks: + description: |- + Should service environment variables be created on containers. + More info: https://kubernetes.io/docs/tutorials/services/connect-applications-service/#accessing-the-service + type: boolean sidecarContainers: description: Sidecar containers to run in the pod. These are in addition to the Solr Container diff --git a/controllers/solrcloud_controller_test.go b/controllers/solrcloud_controller_test.go index b41f0527..5e06f5f1 100644 --- a/controllers/solrcloud_controller_test.go +++ b/controllers/solrcloud_controller_test.go @@ -150,6 +150,7 @@ var _ = FDescribe("SolrCloud controller - General", func() { Expect(statefulSet.Spec.Template.Spec.Volumes[3].Name).To(Equal(extraVolumes[0].Name), "Additional Volume from podOptions not loaded into pod properly.") Expect(statefulSet.Spec.Template.Spec.Volumes[3].VolumeSource).To(Equal(extraVolumes[0].Source), "Additional Volume from podOptions not loaded into pod properly.") Expect(statefulSet.Spec.Template.Spec.ShareProcessNamespace).Should(PointTo(BeFalse())) + Expect(statefulSet.Spec.Template.Spec.EnableServiceLinks).Should(PointTo(BeTrue())) Expect(statefulSet.Spec.Template.Spec.ReadinessGates).To(ContainElement(corev1.PodReadinessGate{ConditionType: util.SolrIsNotStoppedReadinessCondition}), "All pods should contain the isNotStopped readinessGate.") By("testing the Solr Common Service") @@ -174,6 +175,7 @@ var _ = FDescribe("SolrCloud controller - General", func() { FContext("Solr Cloud with Custom Kube Options", func() { three := intstr.FromInt(3) testShareProcessNamespace := true + testEnableServiceLinks := false BeforeEach(func() { replicas := int32(4) solrCloud.Spec = solrv1beta1.SolrCloudSpec{ @@ -227,6 +229,7 @@ var _ = FDescribe("SolrCloud controller - General", func() { }, }, ShareProcessNamespace: testShareProcessNamespace, + EnableServiceLinks: testEnableServiceLinks, }, StatefulSetOptions: &solrv1beta1.StatefulSetOptions{ Annotations: testSSAnnotations, @@ -305,6 +308,7 @@ var _ = FDescribe("SolrCloud controller - General", func() { Expect(statefulSet.Spec.Template.Spec.TopologySpreadConstraints).To(HaveLen(len(testTopologySpreadConstraints)), "Wrong number of topologySpreadConstraints") Expect(statefulSet.Spec.Template.Spec.TopologySpreadConstraints[0]).To(Equal(testTopologySpreadConstraints[0]), "Wrong first topologySpreadConstraint") Expect(statefulSet.Spec.Template.Spec.ShareProcessNamespace).To(Equal(&testShareProcessNamespace), "Wrong shareProcessNamespace value") + Expect(statefulSet.Spec.Template.Spec.EnableServiceLinks).To(Equal(&testEnableServiceLinks), "Wrong enableServiceLinks value") expectedSecondTopologyConstraint := testTopologySpreadConstraints[1].DeepCopy() expectedSecondTopologyConstraint.LabelSelector = statefulSet.Spec.Selector Expect(statefulSet.Spec.Template.Spec.TopologySpreadConstraints[1]).To(Equal(*expectedSecondTopologyConstraint), "Wrong second topologySpreadConstraint") diff --git a/controllers/util/solr_util.go b/controllers/util/solr_util.go index 50fdbc48..7e67e651 100644 --- a/controllers/util/solr_util.go +++ b/controllers/util/solr_util.go @@ -87,6 +87,7 @@ var ( func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCloudStatus, hostNameIPs map[string]string, reconcileConfigInfo map[string]string, tls *TLSCerts, security *SecurityConfig) *appsv1.StatefulSet { terminationGracePeriod := int64(60) shareProcessNamespace := false + enableServiceLinks := true solrPodPort := solrCloud.Spec.SolrAddressability.PodPort defaultFSGroup := int64(DefaultSolrGroup) @@ -128,6 +129,7 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl terminationGracePeriod = *customPodOptions.TerminationGracePeriodSeconds } shareProcessNamespace = customPodOptions.ShareProcessNamespace + enableServiceLinks = customPodOptions.EnableServiceLinks } if podAnnotations == nil { podAnnotations = make(map[string]string, 1) @@ -549,6 +551,7 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl Spec: corev1.PodSpec{ TerminationGracePeriodSeconds: &terminationGracePeriod, ShareProcessNamespace: &shareProcessNamespace, + EnableServiceLinks: &enableServiceLinks, SecurityContext: &corev1.PodSecurityContext{ FSGroup: &defaultFSGroup, }, diff --git a/helm/solr-operator/Chart.yaml b/helm/solr-operator/Chart.yaml index fb16b8e8..3416bf3c 100644 --- a/helm/solr-operator/Chart.yaml +++ b/helm/solr-operator/Chart.yaml @@ -72,6 +72,8 @@ annotations: url: https://github.com/apache/solr-operator/issues/778 - name: Github PR url: https://github.com/apache/solr-operator/pull/779 + - kind: added + description: Abillity to set the `enableServiceLinks` field on pods. artifacthub.io/images: | - name: solr-operator image: apache/solr-operator:v0.10.0-prerelease diff --git a/helm/solr-operator/crds/crds.yaml b/helm/solr-operator/crds/crds.yaml index a1229dcf..cf3807a4 100644 --- a/helm/solr-operator/crds/crds.yaml +++ b/helm/solr-operator/crds/crds.yaml @@ -6058,6 +6058,11 @@ spec: description: Should process namespace sharing be enabled on created pods type: boolean + enableServiceLinks: + description: |- + Should service environment variables be created on containers. + More info: https://kubernetes.io/docs/tutorials/services/connect-applications-service/#accessing-the-service + type: boolean sidecarContainers: description: Sidecar containers to run in the pod. These are in addition to the Solr Container @@ -21570,6 +21575,11 @@ spec: description: Should process namespace sharing be enabled on created pods type: boolean + enableServiceLinks: + description: |- + Should service environment variables be created on containers. + More info: https://kubernetes.io/docs/tutorials/services/connect-applications-service/#accessing-the-service + type: boolean sidecarContainers: description: Sidecar containers to run in the pod. These are in addition to the Solr Container diff --git a/helm/solr/README.md b/helm/solr/README.md index a02cfa10..511b1d97 100644 --- a/helm/solr/README.md +++ b/helm/solr/README.md @@ -286,6 +286,7 @@ When using the helm chart, omit `customSolrKubeOptions.` | podOptions.topologySpreadConstraints | []object | | Specify a list of Kubernetes topologySpreadConstraints for the Solr pod. No need to provide a `labelSelector`, as the Solr Operator will default that for you. More information can be found in [the documentation](https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/). | | podOptions.serviceAccountName | string | | Optional serviceAccount to run the Solr pods under | | podOptions.shareProcessNamespace | boolean | false | Whether containers in a pod should share the same process namespace. | +| podOptions.enableServiceLinks | boolean | true | Whether service environment variables be created containers. | | podOptions.priorityClassName | string | | Optional priorityClassName for the Solr pod | | 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 | diff --git a/helm/solr/templates/_custom_option_helpers.tpl b/helm/solr/templates/_custom_option_helpers.tpl index 34f72981..679cc8dc 100644 --- a/helm/solr/templates/_custom_option_helpers.tpl +++ b/helm/solr/templates/_custom_option_helpers.tpl @@ -39,6 +39,9 @@ serviceAccountName: {{ include "solr.serviceAccountName.solr" . }} {{- if .Values.podOptions.shareProcessNamespace -}} shareProcessNamespace: {{ .Values.podOptions.shareProcessNamespace }} {{ end }} +{{- if .Values.podOptions.enableServiceLinks -}} +enableServiceLinks: {{ .Values.podOptions.enableServiceLinks }} +{{ end }} {{- if .Values.podOptions.priorityClassName -}} priorityClassName: {{ .Values.podOptions.priorityClassName }} {{ end }} diff --git a/helm/solr/values.yaml b/helm/solr/values.yaml index e6addba7..c4aeb2bd 100644 --- a/helm/solr/values.yaml +++ b/helm/solr/values.yaml @@ -303,6 +303,8 @@ podOptions: shareProcessNamespace: false + enableServiceLinks: true + # Manage where the Solr pods are scheduled affinity: {} tolerations: [] From 4167fec089fc4c212b5596fc5f96adc078dbd71a Mon Sep 17 00:00:00 2001 From: jd252387 Date: Fri, 20 Jun 2025 17:04:40 +0000 Subject: [PATCH 2/3] fix: Add links to changelog, correct comment --- api/v1beta1/common_types.go | 2 +- helm/solr-operator/Chart.yaml | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/api/v1beta1/common_types.go b/api/v1beta1/common_types.go index d62e7dd6..06d98499 100644 --- a/api/v1beta1/common_types.go +++ b/api/v1beta1/common_types.go @@ -145,7 +145,7 @@ type PodOptions struct { // +optional ShareProcessNamespace bool `json:"shareProcessNamespace,omitempty"` - // Should process namespace sharing be enabled on created pods + // Should service environment variables be created on containers // +optional EnableServiceLinks bool `json:"enableServiceLinks,omitempty"` diff --git a/helm/solr-operator/Chart.yaml b/helm/solr-operator/Chart.yaml index 3416bf3c..ee654c41 100644 --- a/helm/solr-operator/Chart.yaml +++ b/helm/solr-operator/Chart.yaml @@ -74,6 +74,9 @@ annotations: url: https://github.com/apache/solr-operator/pull/779 - kind: added description: Abillity to set the `enableServiceLinks` field on pods. + links: + - name: Github PR + url: https://github.com/apache/solr-operator/pull/790 artifacthub.io/images: | - name: solr-operator image: apache/solr-operator:v0.10.0-prerelease From 293d1d4862950653e298a59bf00a864cfff6d470 Mon Sep 17 00:00:00 2001 From: John Doe Date: Wed, 30 Jul 2025 14:23:40 +0300 Subject: [PATCH 3/3] fix: check enableServiceLinks value with hasKey --- helm/solr/templates/_custom_option_helpers.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm/solr/templates/_custom_option_helpers.tpl b/helm/solr/templates/_custom_option_helpers.tpl index 679cc8dc..b7f3d1cc 100644 --- a/helm/solr/templates/_custom_option_helpers.tpl +++ b/helm/solr/templates/_custom_option_helpers.tpl @@ -39,7 +39,7 @@ serviceAccountName: {{ include "solr.serviceAccountName.solr" . }} {{- if .Values.podOptions.shareProcessNamespace -}} shareProcessNamespace: {{ .Values.podOptions.shareProcessNamespace }} {{ end }} -{{- if .Values.podOptions.enableServiceLinks -}} +{{- if hasKey .Values.podOptions "enableServiceLinks" -}} enableServiceLinks: {{ .Values.podOptions.enableServiceLinks }} {{ end }} {{- if .Values.podOptions.priorityClassName -}}