Skip to content

Commit 38b56b8

Browse files
Don't use post start hook for zk chroot creation (#774)
1 parent efb7d98 commit 38b56b8

4 files changed

Lines changed: 10 additions & 25 deletions

File tree

controllers/solrcloud_controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ var _ = FDescribe("SolrCloud controller - General", func() {
136136
testPodEnvVariables(expectedEnvVars, append(foundEnv[:len(foundEnv)-3], foundEnv[len(foundEnv)-1]))
137137

138138
// Other Pod Options Checks
139-
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PostStart).To(BeNil(), "Post-start command should be nil since there is no chRoot to ensure exists.")
139+
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PostStart).To(BeNil(), "Post-start command should be nil.")
140140
Expect(statefulSet.Spec.Template.Spec.SecurityContext).To(Not(BeNil()), "PodSecurityContext is not the same as the one provided in podOptions")
141141
Expect(*statefulSet.Spec.Template.Spec.SecurityContext).To(Equal(testPodSecurityContext), "PodSecurityContext is not the same as the one provided in podOptions")
142142
Expect(statefulSet.Spec.Template.Spec.Affinity).To(Equal(testAffinity), "Affinity is not the same as the one provided in podOptions")
@@ -372,7 +372,7 @@ var _ = FDescribe("SolrCloud controller - General", func() {
372372
expectedStatefulSetAnnotations := map[string]string{util.SolrZKConnectionStringAnnotation: expectedZKHost}
373373
testPodEnvVariables(expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env)
374374
Expect(statefulSet.Annotations).To(Equal(expectedStatefulSetAnnotations), "Incorrect statefulSet annotations")
375-
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PostStart.Exec.Command).To(ConsistOf("sh", "-c", "solr zk ls ${ZK_CHROOT} -z ${ZK_SERVER} || solr zk mkroot ${ZK_CHROOT} -z ${ZK_SERVER}"), "Incorrect post-start command")
375+
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PostStart).To(BeNil(), "There should be no postStart command, even if there is a chRoot for ZK")
376376
Expect(statefulSet.Spec.Template.Spec.ServiceAccountName).To(BeEmpty(), "No custom serviceAccountName specified, so the field should be empty.")
377377

378378
// PodDisruptionBudget creation should be enabled by default

controllers/solrcloud_controller_zk_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ var _ = FDescribe("SolrCloud controller - Zookeeper", func() {
255255
By("testing the Solr StatefulSet")
256256
statefulSet := expectStatefulSet(ctx, solrCloud, solrCloud.StatefulSetName())
257257

258-
Expect(len(statefulSet.Spec.Template.Spec.Containers)).To(Equal(1), "Solr StatefulSet requires a container.")
258+
Expect(statefulSet.Spec.Template.Spec.Containers).To(HaveLen(1), "Solr StatefulSet requires a container.")
259259
expectedZKHost := expectedZkConnStr + "/a-ch/root"
260260
expectedEnvVars := map[string]string{
261261
"ZK_HOST": expectedZKHost,
@@ -268,8 +268,10 @@ var _ = FDescribe("SolrCloud controller - Zookeeper", func() {
268268
expectedStatefulSetAnnotations := map[string]string{util.SolrZKConnectionStringAnnotation: expectedZKHost}
269269
testPodEnvVariables(expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env)
270270
Expect(statefulSet.Annotations).To(Equal(util.MergeLabelsOrAnnotations(testSSAnnotations, expectedStatefulSetAnnotations)), "Wrong statefulSet annotations")
271-
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PostStart.Exec.Command).To(Equal([]string{"sh", "-c", "solr zk ls ${ZK_CHROOT} -z ${ZK_SERVER} || solr zk mkroot ${ZK_CHROOT} -z ${ZK_SERVER}"}), "Incorrect post-start command")
271+
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PostStart).To(BeNil(), "There should be no postStart command, even if there is a chRoot for ZK")
272272
Expect(statefulSet.Spec.Template.Spec.ServiceAccountName).To(BeEmpty(), "No custom serviceAccountName specified, so the field should be empty.")
273+
Expect(statefulSet.Spec.Template.Spec.InitContainers).To(HaveLen(2), "Solr StatefulSet requires 2 init containers, one for the solr.xml and one for ZK.")
274+
Expect(statefulSet.Spec.Template.Spec.InitContainers[1].Command).To(Equal([]string{"sh", "-c", "solr zk ls ${ZK_CHROOT} -z ${ZK_SERVER} || solr zk mkroot ${ZK_CHROOT} -z ${ZK_SERVER}; "}), "Wrong command for the ZK init container")
273275

274276
// Check the update strategy
275277
Expect(statefulSet.Spec.UpdateStrategy.Type).To(Equal(appsv1.OnDeleteStatefulSetStrategyType), "Incorrect statefulset update strategy")

controllers/util/solr_util.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl
391391
}
392392

393393
// Add all necessary information for connection to Zookeeper
394-
zkEnvVars, zkSolrOpt, hasChroot := createZkConnectionEnvVars(solrCloud, solrCloudStatus)
394+
zkEnvVars, zkSolrOpt, _ := createZkConnectionEnvVars(solrCloud, solrCloudStatus)
395395
if zkSolrOpt != "" {
396396
allSolrOpts = append(allSolrOpts, zkSolrOpt)
397397
}
@@ -402,16 +402,6 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl
402402
envVars = append(envVars, backupEnvVars...)
403403
}
404404

405-
// Only have a postStart command to create the chRoot, if it is not '/' (which does not need to be created)
406-
var postStart *corev1.LifecycleHandler
407-
if hasChroot {
408-
postStart = &corev1.LifecycleHandler{
409-
Exec: &corev1.ExecAction{
410-
Command: []string{"sh", "-c", "solr zk ls ${ZK_CHROOT} -z ${ZK_SERVER} || solr zk mkroot ${ZK_CHROOT} -z ${ZK_SERVER}"},
411-
},
412-
}
413-
}
414-
415405
// Default preStop hook
416406
preStop := &corev1.LifecycleHandler{
417407
Exec: &corev1.ExecAction{
@@ -508,8 +498,7 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl
508498
VolumeMounts: volumeMounts,
509499
Env: envVars,
510500
Lifecycle: &corev1.Lifecycle{
511-
PostStart: postStart,
512-
PreStop: preStop,
501+
PreStop: preStop,
513502
},
514503
SecurityContext: containerSecurityContext,
515504
},
@@ -1229,7 +1218,6 @@ func CreateNodeIngressRule(solrCloud *solr.SolrCloud, nodeName string, domainNam
12291218
return ingressRule
12301219
}
12311220

1232-
// TODO: Have this replace the postStart hook for creating the chroot
12331221
func generateZKInteractionInitContainer(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCloudStatus, security *SecurityConfig) (bool, corev1.Container) {
12341222
allSolrOpts := make([]string, 0)
12351223

helm/solr-operator/Chart.yaml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,11 @@ annotations:
5555
# Allowed syntax is described at: https://artifacthub.io/docs/topics/annotations/helm/#example
5656
# 'kind' accepts values: "added", "changed", "deprecated", "removed", "fixed" and "security"
5757
artifacthub.io/changes: |
58-
- kind: added
59-
description: Addition 1
60-
links:
61-
- name: Github Issue
62-
url: https://github.com/issue-url
6358
- kind: changed
64-
description: Change 2
59+
description: A container PostStart Hook is no longer used to create the ZooKeeper ChRoot, instead the initContainer will manage this
6560
links:
6661
- name: Github PR
67-
url: https://github.com/pr-url
62+
url: https://github.com/apache/solr-operator/pull/774
6863
artifacthub.io/images: |
6964
- name: solr-operator
7065
image: apache/solr-operator:v0.10.0-prerelease

0 commit comments

Comments
 (0)