This is an automated email from the ASF dual-hosted git repository.

houston 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 38b56b8  Don't use post start hook for zk chroot creation (#774)
38b56b8 is described below

commit 38b56b84de4e6ed3a10bde9a3fd5ade6bf0e258b
Author: Houston Putman <[email protected]>
AuthorDate: Thu Mar 27 12:32:04 2025 -0500

    Don't use post start hook for zk chroot creation (#774)
---
 controllers/solrcloud_controller_test.go    |  4 ++--
 controllers/solrcloud_controller_zk_test.go |  6 ++++--
 controllers/util/solr_util.go               | 16 ++--------------
 helm/solr-operator/Chart.yaml               |  9 ++-------
 4 files changed, 10 insertions(+), 25 deletions(-)

diff --git a/controllers/solrcloud_controller_test.go 
b/controllers/solrcloud_controller_test.go
index 5dca7f0..b41f052 100644
--- a/controllers/solrcloud_controller_test.go
+++ b/controllers/solrcloud_controller_test.go
@@ -136,7 +136,7 @@ var _ = FDescribe("SolrCloud controller - General", func() {
                        testPodEnvVariables(expectedEnvVars, 
append(foundEnv[:len(foundEnv)-3], foundEnv[len(foundEnv)-1]))
 
                        // Other Pod Options Checks
-                       
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.")
+                       
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PostStart).To(BeNil(),
 "Post-start command should be nil.")
                        
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")
@@ -372,7 +372,7 @@ var _ = FDescribe("SolrCloud controller - General", func() {
                        expectedStatefulSetAnnotations := 
map[string]string{util.SolrZKConnectionStringAnnotation: expectedZKHost}
                        testPodEnvVariables(expectedEnvVars, 
statefulSet.Spec.Template.Spec.Containers[0].Env)
                        
Expect(statefulSet.Annotations).To(Equal(expectedStatefulSetAnnotations), 
"Incorrect statefulSet annotations")
-                       
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")
+                       
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")
                        
Expect(statefulSet.Spec.Template.Spec.ServiceAccountName).To(BeEmpty(), "No 
custom serviceAccountName specified, so the field should be empty.")
 
                        // PodDisruptionBudget creation should be enabled by 
default
diff --git a/controllers/solrcloud_controller_zk_test.go 
b/controllers/solrcloud_controller_zk_test.go
index 57917fb..78d070d 100644
--- a/controllers/solrcloud_controller_zk_test.go
+++ b/controllers/solrcloud_controller_zk_test.go
@@ -255,7 +255,7 @@ var _ = FDescribe("SolrCloud controller - Zookeeper", 
func() {
                        By("testing the Solr StatefulSet")
                        statefulSet := expectStatefulSet(ctx, solrCloud, 
solrCloud.StatefulSetName())
 
-                       
Expect(len(statefulSet.Spec.Template.Spec.Containers)).To(Equal(1), "Solr 
StatefulSet requires a container.")
+                       
Expect(statefulSet.Spec.Template.Spec.Containers).To(HaveLen(1), "Solr 
StatefulSet requires a container.")
                        expectedZKHost := expectedZkConnStr + "/a-ch/root"
                        expectedEnvVars := map[string]string{
                                "ZK_HOST":   expectedZKHost,
@@ -268,8 +268,10 @@ var _ = FDescribe("SolrCloud controller - Zookeeper", 
func() {
                        expectedStatefulSetAnnotations := 
map[string]string{util.SolrZKConnectionStringAnnotation: expectedZKHost}
                        testPodEnvVariables(expectedEnvVars, 
statefulSet.Spec.Template.Spec.Containers[0].Env)
                        
Expect(statefulSet.Annotations).To(Equal(util.MergeLabelsOrAnnotations(testSSAnnotations,
 expectedStatefulSetAnnotations)), "Wrong statefulSet annotations")
-                       
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")
+                       
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")
                        
Expect(statefulSet.Spec.Template.Spec.ServiceAccountName).To(BeEmpty(), "No 
custom serviceAccountName specified, so the field should be empty.")
+                       
Expect(statefulSet.Spec.Template.Spec.InitContainers).To(HaveLen(2), "Solr 
StatefulSet requires 2 init containers, one for the solr.xml and one for ZK.")
+                       
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")
 
                        // Check the update strategy
                        
Expect(statefulSet.Spec.UpdateStrategy.Type).To(Equal(appsv1.OnDeleteStatefulSetStrategyType),
 "Incorrect statefulset update strategy")
diff --git a/controllers/util/solr_util.go b/controllers/util/solr_util.go
index 478145a..50fdbc4 100644
--- a/controllers/util/solr_util.go
+++ b/controllers/util/solr_util.go
@@ -391,7 +391,7 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, 
solrCloudStatus *solr.SolrCl
        }
 
        // Add all necessary information for connection to Zookeeper
-       zkEnvVars, zkSolrOpt, hasChroot := createZkConnectionEnvVars(solrCloud, 
solrCloudStatus)
+       zkEnvVars, zkSolrOpt, _ := createZkConnectionEnvVars(solrCloud, 
solrCloudStatus)
        if zkSolrOpt != "" {
                allSolrOpts = append(allSolrOpts, zkSolrOpt)
        }
@@ -402,16 +402,6 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, 
solrCloudStatus *solr.SolrCl
                envVars = append(envVars, backupEnvVars...)
        }
 
-       // Only have a postStart command to create the chRoot, if it is not '/' 
(which does not need to be created)
-       var postStart *corev1.LifecycleHandler
-       if hasChroot {
-               postStart = &corev1.LifecycleHandler{
-                       Exec: &corev1.ExecAction{
-                               Command: []string{"sh", "-c", "solr zk ls 
${ZK_CHROOT} -z ${ZK_SERVER} || solr zk mkroot ${ZK_CHROOT} -z ${ZK_SERVER}"},
-                       },
-               }
-       }
-
        // Default preStop hook
        preStop := &corev1.LifecycleHandler{
                Exec: &corev1.ExecAction{
@@ -508,8 +498,7 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, 
solrCloudStatus *solr.SolrCl
                        VolumeMounts: volumeMounts,
                        Env:          envVars,
                        Lifecycle: &corev1.Lifecycle{
-                               PostStart: postStart,
-                               PreStop:   preStop,
+                               PreStop: preStop,
                        },
                        SecurityContext: containerSecurityContext,
                },
@@ -1229,7 +1218,6 @@ func CreateNodeIngressRule(solrCloud *solr.SolrCloud, 
nodeName string, domainNam
        return ingressRule
 }
 
-// TODO: Have this replace the postStart hook for creating the chroot
 func generateZKInteractionInitContainer(solrCloud *solr.SolrCloud, 
solrCloudStatus *solr.SolrCloudStatus, security *SecurityConfig) (bool, 
corev1.Container) {
        allSolrOpts := make([]string, 0)
 
diff --git a/helm/solr-operator/Chart.yaml b/helm/solr-operator/Chart.yaml
index 2e3b830..ef3e7d1 100644
--- a/helm/solr-operator/Chart.yaml
+++ b/helm/solr-operator/Chart.yaml
@@ -55,16 +55,11 @@ annotations:
   # Allowed syntax is described at: 
https://artifacthub.io/docs/topics/annotations/helm/#example
   # 'kind' accepts values: "added", "changed", "deprecated", "removed", 
"fixed" and "security"
   artifacthub.io/changes: |
-    - kind: added
-      description: Addition 1
-      links:
-        - name: Github Issue
-          url: https://github.com/issue-url
     - kind: changed
-      description: Change 2
+      description: A container PostStart Hook is no longer used to create the 
ZooKeeper ChRoot, instead the initContainer will manage this
       links:
         - name: Github PR
-          url: https://github.com/pr-url
+          url: https://github.com/apache/solr-operator/pull/774
   artifacthub.io/images: |
     - name: solr-operator
       image: apache/solr-operator:v0.10.0-prerelease

Reply via email to