Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/
//
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions config/crd/bases/solr.apache.org_solrclouds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/solr.apache.org_solrprometheusexporters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions controllers/solrcloud_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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")
Expand All @@ -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{
Expand Down Expand Up @@ -227,6 +230,7 @@ var _ = FDescribe("SolrCloud controller - General", func() {
},
},
ShareProcessNamespace: testShareProcessNamespace,
EnableServiceLinks: &testEnableServiceLinks,
},
StatefulSetOptions: &solrv1beta1.StatefulSetOptions{
Annotations: testSSAnnotations,
Expand Down Expand Up @@ -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")
Expand Down
15 changes: 14 additions & 1 deletion controllers/util/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions controllers/util/solr_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
},
Expand Down
5 changes: 5 additions & 0 deletions helm/solr-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions helm/solr-operator/crds/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions helm/solr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
3 changes: 3 additions & 0 deletions helm/solr/templates/_custom_option_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 2 additions & 0 deletions helm/solr/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ podOptions:

shareProcessNamespace: false

enableServiceLinks: true

# Manage where the Solr pods are scheduled
affinity: {}
tolerations: []
Expand Down
Loading