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 887fa36 Add ability to set enableServiceLinks on PodSpec (#790)
887fa36 is described below
commit 887fa3670d9ae730f6cbf1cf67e02b68bf665448
Author: jd252387 <[email protected]>
AuthorDate: Wed Jun 17 02:54:54 2026 +0300
Add ability to set enableServiceLinks on PodSpec (#790)
---
api/v1beta1/common_types.go | 4 ++++
api/v1beta1/zz_generated.deepcopy.go | 5 +++++
config/crd/bases/solr.apache.org_solrclouds.yaml | 4 ++++
.../bases/solr.apache.org_solrprometheusexporters.yaml | 4 ++++
controllers/solrcloud_controller_test.go | 9 +++++++--
controllers/util/common.go | 15 ++++++++++++++-
controllers/util/solr_util.go | 3 +++
helm/solr-operator/Chart.yaml | 5 +++++
helm/solr-operator/crds/crds.yaml | 8 ++++++++
helm/solr/README.md | 1 +
helm/solr/templates/_custom_option_helpers.tpl | 3 +++
helm/solr/values.yaml | 2 ++
12 files changed, 60 insertions(+), 3 deletions(-)
diff --git a/api/v1beta1/common_types.go b/api/v1beta1/common_types.go
index 2200224..d5c82a3 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 service environment variables be created on containers
+ // +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/api/v1beta1/zz_generated.deepcopy.go
b/api/v1beta1/zz_generated.deepcopy.go
index d48f048..a9edeac 100644
--- a/api/v1beta1/zz_generated.deepcopy.go
+++ b/api/v1beta1/zz_generated.deepcopy.go
@@ -523,6 +523,11 @@ func (in *PodOptions) DeepCopyInto(out *PodOptions) {
*out = new(int64)
**out = **in
}
+ if in.EnableServiceLinks != nil {
+ in, out := &in.EnableServiceLinks, &out.EnableServiceLinks
+ *out = new(bool)
+ **out = **in
+ }
if in.TopologySpreadConstraints != nil {
in, out := &in.TopologySpreadConstraints,
&out.TopologySpreadConstraints
*out = make([]v1.TopologySpreadConstraint, len(*in))
diff --git a/config/crd/bases/solr.apache.org_solrclouds.yaml
b/config/crd/bases/solr.apache.org_solrclouds.yaml
index 20a9a33..c560410 100644
--- a/config/crd/bases/solr.apache.org_solrclouds.yaml
+++ b/config/crd/bases/solr.apache.org_solrclouds.yaml
@@ -3403,6 +3403,10 @@ spec:
More info:
https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
type: object
type: object
+ enableServiceLinks:
+ description: Should service environment variables be
created
+ on containers
+ type: boolean
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 766b888..ad5d9b2 100644
--- a/config/crd/bases/solr.apache.org_solrprometheusexporters.yaml
+++ b/config/crd/bases/solr.apache.org_solrprometheusexporters.yaml
@@ -1319,6 +1319,10 @@ spec:
More info:
https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
type: object
type: object
+ enableServiceLinks:
+ description: Should service environment variables be
created
+ on containers
+ type: boolean
envVars:
description: Additional environment variables to pass
to the
default container.
diff --git a/controllers/solrcloud_controller_test.go
b/controllers/solrcloud_controller_test.go
index b41f052..78a0725 100644
--- a/controllers/solrcloud_controller_test.go
+++ b/controllers/solrcloud_controller_test.go
@@ -21,6 +21,9 @@ import (
"context"
"crypto/md5"
"fmt"
+ "strconv"
+ "strings"
+
solrv1beta1 "github.com/apache/solr-operator/api/v1beta1"
"github.com/apache/solr-operator/controllers/util"
. "github.com/onsi/ginkgo/v2"
@@ -31,8 +34,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
pointer "k8s.io/utils/pointer"
- "strconv"
- "strings"
)
func newBoolPtr(value bool) *bool {
@@ -150,6 +151,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(BeNil())
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 +176,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 +230,7 @@ var _ = FDescribe("SolrCloud controller - General", func() {
},
},
ShareProcessNamespace:
testShareProcessNamespace,
+ EnableServiceLinks:
&testEnableServiceLinks,
},
StatefulSetOptions:
&solrv1beta1.StatefulSetOptions{
Annotations:
testSSAnnotations,
@@ -305,6 +309,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/common.go b/controllers/util/common.go
index 0f7fdaa..f857adf 100644
--- a/controllers/util/common.go
+++ b/controllers/util/common.go
@@ -18,12 +18,13 @@
package util
import (
- policyv1 "k8s.io/api/policy/v1"
"reflect"
"strconv"
"strings"
"time"
+ policyv1 "k8s.io/api/policy/v1"
+
"github.com/go-logr/logr"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
@@ -522,6 +523,18 @@ func CopyPodTemplates(from, to *corev1.PodTemplateSpec,
basePath string, logger
to.Spec.ReadinessGates = from.Spec.ReadinessGates
}
+ if !DeepEqualWithNils(to.Spec.ShareProcessNamespace,
from.Spec.ShareProcessNamespace) {
+ requireUpdate = true
+ logger.Info("Update required because field changed", "field",
basePath+"Spec.ShareProcessNamespace", "from", to.Spec.ShareProcessNamespace,
"to", from.Spec.ShareProcessNamespace)
+ to.Spec.ShareProcessNamespace = from.Spec.ShareProcessNamespace
+ }
+
+ if !DeepEqualWithNils(to.Spec.EnableServiceLinks,
from.Spec.EnableServiceLinks) {
+ requireUpdate = true
+ logger.Info("Update required because field changed", "field",
basePath+"Spec.EnableServiceLinks", "from", to.Spec.EnableServiceLinks, "to",
from.Spec.EnableServiceLinks)
+ to.Spec.EnableServiceLinks = from.Spec.EnableServiceLinks
+ }
+
return requireUpdate
}
diff --git a/controllers/util/solr_util.go b/controllers/util/solr_util.go
index a3101c3..7f90b76 100644
--- a/controllers/util/solr_util.go
+++ b/controllers/util/solr_util.go
@@ -89,6 +89,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
+ var enableServiceLinks *bool
solrPodPort := solrCloud.Spec.SolrAddressability.PodPort
defaultFSGroup := int64(DefaultSolrGroup)
@@ -130,6 +131,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)
@@ -558,6 +560,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 90794fb..ca45651 100644
--- a/helm/solr-operator/Chart.yaml
+++ b/helm/solr-operator/Chart.yaml
@@ -100,6 +100,11 @@ annotations:
url: https://github.com/apache/solr-operator/issues/717
- name: Github PR
url: https://github.com/apache/solr-operator/pull/804
+ - kind: added
+ description: Ability 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
diff --git a/helm/solr-operator/crds/crds.yaml
b/helm/solr-operator/crds/crds.yaml
index 931fbb7..674b257 100644
--- a/helm/solr-operator/crds/crds.yaml
+++ b/helm/solr-operator/crds/crds.yaml
@@ -3661,6 +3661,10 @@ spec:
More info:
https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
type: object
type: object
+ enableServiceLinks:
+ description: Should service environment variables be
created
+ on containers
+ type: boolean
envVars:
description: Additional environment variables to pass
to the
default container.
@@ -19173,6 +19177,10 @@ spec:
More info:
https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
type: object
type: object
+ enableServiceLinks:
+ description: Should service environment variables be
created
+ on containers
+ type: boolean
envVars:
description: Additional environment variables to pass
to the
default container.
diff --git a/helm/solr/README.md b/helm/solr/README.md
index 791c446..e1de157 100644
--- a/helm/solr/README.md
+++ b/helm/solr/README.md
@@ -287,6 +287,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 34f7298..b7f3d1c 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 hasKey .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 4b1d162..f72bdd4 100644
--- a/helm/solr/values.yaml
+++ b/helm/solr/values.yaml
@@ -304,6 +304,8 @@ podOptions:
shareProcessNamespace: false
+ enableServiceLinks: true
+
# Manage where the Solr pods are scheduled
affinity: {}
tolerations: []