HoustonPutman commented on a change in pull request #193:
URL: 
https://github.com/apache/lucene-solr-operator/pull/193#discussion_r566277962



##########
File path: controllers/solrcloud_controller.go
##########
@@ -182,44 +182,61 @@ func (r *SolrCloudReconciler) Reconcile(req ctrl.Request) 
(ctrl.Result, error) {
                }
        }
 
-       // Generate ConfigMap unless the user supplied a custom ConfigMap for 
solr.xml ... but the provided ConfigMap
-       // might be for the Prometheus exporter, so we only care if they 
provide a solr.xml in the CM
-       solrXmlConfigMapName := instance.ConfigMapName()
-       solrXmlMd5 := ""
+       // Generate ConfigMap unless the user supplied a custom ConfigMap for 
solr.xml
+       configMapInfo := make(map[string]string)
        if instance.Spec.CustomSolrKubeOptions.ConfigMapOptions != nil && 
instance.Spec.CustomSolrKubeOptions.ConfigMapOptions.ProvidedConfigMap != "" {
+               providedConfigMapName := 
instance.Spec.CustomSolrKubeOptions.ConfigMapOptions.ProvidedConfigMap
                foundConfigMap := &corev1.ConfigMap{}
-               nn := types.NamespacedName{Name: 
instance.Spec.CustomSolrKubeOptions.ConfigMapOptions.ProvidedConfigMap, 
Namespace: instance.Namespace}
+               nn := types.NamespacedName{Name: providedConfigMapName, 
Namespace: instance.Namespace}
                err = r.Get(context.TODO(), nn, foundConfigMap)
                if err != nil {
                        return requeueOrNot, err // if they passed a 
providedConfigMap name, then it must exist
                }
 
-               // ConfigMap doesn't have to have a solr.xml, but if it does, 
then it needs to be valid!
                if foundConfigMap.Data != nil {
-                       solrXml, ok := foundConfigMap.Data["solr.xml"]
-                       if ok {
+                       logXml, hasLogXml := 
foundConfigMap.Data[util.LogXmlFile]
+                       solrXml, hasSolrXml := 
foundConfigMap.Data[util.SolrXmlFile]
+
+                       // if there's a user-provided config, it must have one 
of the expected keys
+                       if !hasLogXml && !hasSolrXml {
+                               return requeueOrNot, fmt.Errorf("User provided 
ConfigMap %s must have one of 'solr.xml' and/or 'log4j2.xml'",

Review comment:
       Please add a TODO comment to create a controller event for this error.

##########
File path: controllers/solrcloud_controller_test.go
##########
@@ -759,18 +754,246 @@ func TestCloudWithCustomSolrXmlConfigMapReconcile(t 
*testing.T) {
        // update the embedded solr.xml to trigger a pod rolling restart
        foundConfigMap = &corev1.ConfigMap{}
        err = testClient.Get(context.TODO(), types.NamespacedName{Name: 
testCustomSolrXmlConfigMap, Namespace: instance.Namespace}, foundConfigMap)
-       updateSolrXml := foundConfigMap.Data["solr.xml"]
-       foundConfigMap.Data["solr.xml"] = strings.Replace(updateSolrXml, 
"${zkClientTimeout:30000}", "${zkClientTimeout:15000}", 1)
+       updateSolrXml := foundConfigMap.Data[util.SolrXmlFile]
+       foundConfigMap.Data[util.SolrXmlFile] = strings.Replace(updateSolrXml, 
"${zkClientTimeout:30000}", "${zkClientTimeout:15000}", 1)
        err = testClient.Update(context.TODO(), foundConfigMap)
        g.Expect(err).NotTo(gomega.HaveOccurred())
        g.Eventually(requests, 
timeout).Should(gomega.Receive(gomega.Equal(expectedCloudRequest)))
        g.Eventually(requests, 
timeout).Should(gomega.Receive(gomega.Equal(expectedCloudRequest)))
+       g.Eventually(requests, 
timeout).Should(gomega.Receive(gomega.Equal(expectedCloudRequest)))
 
        // Check the annotation on the pod template to make sure a rolling 
restart will take place
-       updateSolrXml = foundConfigMap.Data["solr.xml"]
+       updateSolrXml = foundConfigMap.Data[util.SolrXmlFile]
        updateSolrXmlMd5 := fmt.Sprintf("%x", md5.Sum([]byte(updateSolrXml)))
        time.Sleep(time.Millisecond * 250)
        err = testClient.Get(context.TODO(), cloudSsKey, stateful)
        g.Expect(err).NotTo(gomega.HaveOccurred())
        assert.Equal(t, updateSolrXmlMd5, 
stateful.Spec.Template.Annotations[util.SolrXmlMd5Annotation], "Custom solr.xml 
MD5 annotation should be updated on the pod template.")
 }
+
+func TestCloudWithUserProvidedLogConfigMapReconcile(t *testing.T) {
+       UseZkCRD(true)
+       g := gomega.NewGomegaWithT(t)
+
+       testCustomLogXmlConfigMap := "my-custom-log4j2-xml"
+
+       instance := &solr.SolrCloud{
+               ObjectMeta: metav1.ObjectMeta{Name: expectedCloudRequest.Name, 
Namespace: expectedCloudRequest.Namespace},
+               Spec: solr.SolrCloudSpec{
+                       CustomSolrKubeOptions: solr.CustomSolrKubeOptions{
+                               ConfigMapOptions: &solr.ConfigMapOptions{
+                                       ProvidedConfigMap: 
testCustomLogXmlConfigMap,
+                               },
+                       },
+               },
+       }
+
+       // Setup the Manager and Controller.  Wrap the Controller Reconcile 
function so it writes each request to a
+       // channel when it is finished.
+       mgr, err := manager.New(testCfg, manager.Options{})
+       g.Expect(err).NotTo(gomega.HaveOccurred())
+       testClient = mgr.GetClient()
+
+       solrCloudReconciler := &SolrCloudReconciler{
+               Client: testClient,
+               Log:    ctrl.Log.WithName("controllers").WithName("SolrCloud"),
+       }
+       newRec, requests := SetupTestReconcile(solrCloudReconciler)
+       g.Expect(solrCloudReconciler.SetupWithManagerAndReconciler(mgr, 
newRec)).NotTo(gomega.HaveOccurred())
+
+       stopMgr, mgrStopped := StartTestManager(mgr, g)
+
+       defer func() {
+               close(stopMgr)
+               mgrStopped.Wait()
+       }()
+
+       cleanupTest(g, instance.Namespace)
+
+       // Create the SolrCloud object and expect the Reconcile and StatefulSet 
to be created
+       err = testClient.Create(context.TODO(), instance)
+       g.Expect(err).NotTo(gomega.HaveOccurred())
+       defer testClient.Delete(context.TODO(), instance)
+
+       // reconcile will have failed b/c the provided ConfigMap doesn't exist 
...
+       g.Eventually(requests, 
timeout).Should(gomega.Receive(gomega.Equal(expectedCloudRequest)))
+
+       userProvidedConfigMap := &corev1.ConfigMap{
+               ObjectMeta: metav1.ObjectMeta{
+                       Name:      testCustomLogXmlConfigMap,
+                       Namespace: instance.Namespace,
+               },
+               Data: map[string]string{
+                       util.LogXmlFile: "<Configuration/>",
+               },
+       }
+       err = testClient.Create(context.TODO(), userProvidedConfigMap)
+       g.Expect(err).NotTo(gomega.HaveOccurred())
+       defer testClient.Delete(context.TODO(), userProvidedConfigMap)
+
+       g.Eventually(requests, 
timeout).Should(gomega.Receive(gomega.Equal(expectedCloudRequest)))
+
+       g.Eventually(func() error { return testClient.Get(context.TODO(), 
expectedCloudRequest.NamespacedName, instance) }, 
timeout).Should(gomega.Succeed())
+       emptyRequests(requests)
+
+       stateful := &appsv1.StatefulSet{}
+       g.Eventually(func() error { return testClient.Get(context.TODO(), 
cloudSsKey, stateful) }, timeout).Should(gomega.Succeed())
+       assert.NotEmpty(t, 
stateful.Spec.Template.Annotations[util.LogXmlMd5Annotation], "Custom log XML 
MD5 annotation should be set on the pod template!")
+
+       assert.NotNil(t, stateful.Spec.Template.Spec.Volumes)
+       var logXmlVol *corev1.Volume = nil
+       for _, vol := range stateful.Spec.Template.Spec.Volumes {
+               if vol.Name == "log4j2-xml" {
+                       logXmlVol = &vol
+                       break
+               }
+       }
+       assert.NotNil(t, logXmlVol, "Didn't find custom log4j2-xml volume in 
sts config!")
+       assert.NotNil(t, logXmlVol.VolumeSource.ConfigMap, "log4j2-xml Volume 
should have a ConfigMap source")
+       assert.Equal(t, logXmlVol.VolumeSource.ConfigMap.Name, 
testCustomLogXmlConfigMap, "log4j2-xml Volume should have a ConfigMap source")
+
+       var logXmlVolMount *corev1.VolumeMount = nil
+       for _, mount := range 
stateful.Spec.Template.Spec.Containers[0].VolumeMounts {
+               if mount.Name == "log4j2-xml" {
+                       logXmlVolMount = &mount
+                       break
+               }
+       }
+       assert.NotNil(t, logXmlVolMount, "Didn't find the log4j2-xml Volume 
mount")
+       expectedMountPath := fmt.Sprintf("/var/solr/%s", 
testCustomLogXmlConfigMap)
+       assert.Equal(t, expectedMountPath, logXmlVolMount.MountPath)
+
+       solrXmlConfigName := fmt.Sprintf("%s-solrcloud-configmap", 
instance.GetName())
+       foundConfigMap := &corev1.ConfigMap{}
+       err = testClient.Get(context.TODO(), types.NamespacedName{Name: 
solrXmlConfigName, Namespace: instance.Namespace}, foundConfigMap)
+       g.Expect(err).NotTo(gomega.HaveOccurred(), "Built-in solr.xml ConfigMap 
should still exist! ")
+
+       emptyRequests(requests)
+       // update the user-provided log XML to trigger a pod rolling restart
+       updatedXml := "<Configuration>Updated!</Configuration>"
+       foundConfigMap = &corev1.ConfigMap{}
+       err = testClient.Get(context.TODO(), types.NamespacedName{Name: 
testCustomLogXmlConfigMap, Namespace: instance.Namespace}, foundConfigMap)
+       foundConfigMap.Data[util.LogXmlFile] = updatedXml
+       err = testClient.Update(context.TODO(), foundConfigMap)
+       g.Expect(err).NotTo(gomega.HaveOccurred())
+       // capture all reconcile requests
+       g.Eventually(requests, 
timeout).Should(gomega.Receive(gomega.Equal(expectedCloudRequest)))
+       g.Eventually(requests, 
timeout).Should(gomega.Receive(gomega.Equal(expectedCloudRequest)))
+       g.Eventually(requests, 
timeout).Should(gomega.Receive(gomega.Equal(expectedCloudRequest)))
+
+       // Check the annotation on the pod template to make sure a rolling 
restart will take place
+       updateLogXmlMd5 := fmt.Sprintf("%x", md5.Sum([]byte(updatedXml)))
+       time.Sleep(time.Millisecond * 250)
+       err = testClient.Get(context.TODO(), cloudSsKey, stateful)
+       g.Expect(err).NotTo(gomega.HaveOccurred())
+       assert.Equal(t, updateLogXmlMd5, 
stateful.Spec.Template.Annotations[util.LogXmlMd5Annotation], "Custom log XML 
MD5 annotation should be updated on the pod template.")

Review comment:
       Should you test that the log4j location env var is set?

##########
File path: controllers/solrcloud_controller_test.go
##########
@@ -759,18 +754,246 @@ func TestCloudWithCustomSolrXmlConfigMapReconcile(t 
*testing.T) {
        // update the embedded solr.xml to trigger a pod rolling restart
        foundConfigMap = &corev1.ConfigMap{}
        err = testClient.Get(context.TODO(), types.NamespacedName{Name: 
testCustomSolrXmlConfigMap, Namespace: instance.Namespace}, foundConfigMap)
-       updateSolrXml := foundConfigMap.Data["solr.xml"]
-       foundConfigMap.Data["solr.xml"] = strings.Replace(updateSolrXml, 
"${zkClientTimeout:30000}", "${zkClientTimeout:15000}", 1)
+       updateSolrXml := foundConfigMap.Data[util.SolrXmlFile]
+       foundConfigMap.Data[util.SolrXmlFile] = strings.Replace(updateSolrXml, 
"${zkClientTimeout:30000}", "${zkClientTimeout:15000}", 1)
        err = testClient.Update(context.TODO(), foundConfigMap)
        g.Expect(err).NotTo(gomega.HaveOccurred())
        g.Eventually(requests, 
timeout).Should(gomega.Receive(gomega.Equal(expectedCloudRequest)))
        g.Eventually(requests, 
timeout).Should(gomega.Receive(gomega.Equal(expectedCloudRequest)))
+       g.Eventually(requests, 
timeout).Should(gomega.Receive(gomega.Equal(expectedCloudRequest)))
 
        // Check the annotation on the pod template to make sure a rolling 
restart will take place
-       updateSolrXml = foundConfigMap.Data["solr.xml"]
+       updateSolrXml = foundConfigMap.Data[util.SolrXmlFile]
        updateSolrXmlMd5 := fmt.Sprintf("%x", md5.Sum([]byte(updateSolrXml)))
        time.Sleep(time.Millisecond * 250)
        err = testClient.Get(context.TODO(), cloudSsKey, stateful)
        g.Expect(err).NotTo(gomega.HaveOccurred())
        assert.Equal(t, updateSolrXmlMd5, 
stateful.Spec.Template.Annotations[util.SolrXmlMd5Annotation], "Custom solr.xml 
MD5 annotation should be updated on the pod template.")
 }
+
+func TestCloudWithUserProvidedLogConfigMapReconcile(t *testing.T) {
+       UseZkCRD(true)
+       g := gomega.NewGomegaWithT(t)
+
+       testCustomLogXmlConfigMap := "my-custom-log4j2-xml"
+
+       instance := &solr.SolrCloud{
+               ObjectMeta: metav1.ObjectMeta{Name: expectedCloudRequest.Name, 
Namespace: expectedCloudRequest.Namespace},
+               Spec: solr.SolrCloudSpec{
+                       CustomSolrKubeOptions: solr.CustomSolrKubeOptions{
+                               ConfigMapOptions: &solr.ConfigMapOptions{
+                                       ProvidedConfigMap: 
testCustomLogXmlConfigMap,
+                               },
+                       },
+               },
+       }
+
+       // Setup the Manager and Controller.  Wrap the Controller Reconcile 
function so it writes each request to a
+       // channel when it is finished.
+       mgr, err := manager.New(testCfg, manager.Options{})
+       g.Expect(err).NotTo(gomega.HaveOccurred())
+       testClient = mgr.GetClient()
+
+       solrCloudReconciler := &SolrCloudReconciler{
+               Client: testClient,
+               Log:    ctrl.Log.WithName("controllers").WithName("SolrCloud"),
+       }
+       newRec, requests := SetupTestReconcile(solrCloudReconciler)
+       g.Expect(solrCloudReconciler.SetupWithManagerAndReconciler(mgr, 
newRec)).NotTo(gomega.HaveOccurred())
+
+       stopMgr, mgrStopped := StartTestManager(mgr, g)
+
+       defer func() {
+               close(stopMgr)
+               mgrStopped.Wait()
+       }()
+
+       cleanupTest(g, instance.Namespace)
+
+       // Create the SolrCloud object and expect the Reconcile and StatefulSet 
to be created
+       err = testClient.Create(context.TODO(), instance)
+       g.Expect(err).NotTo(gomega.HaveOccurred())
+       defer testClient.Delete(context.TODO(), instance)
+
+       // reconcile will have failed b/c the provided ConfigMap doesn't exist 
...
+       g.Eventually(requests, 
timeout).Should(gomega.Receive(gomega.Equal(expectedCloudRequest)))
+
+       userProvidedConfigMap := &corev1.ConfigMap{
+               ObjectMeta: metav1.ObjectMeta{
+                       Name:      testCustomLogXmlConfigMap,
+                       Namespace: instance.Namespace,
+               },
+               Data: map[string]string{
+                       util.LogXmlFile: "<Configuration/>",
+               },
+       }
+       err = testClient.Create(context.TODO(), userProvidedConfigMap)
+       g.Expect(err).NotTo(gomega.HaveOccurred())
+       defer testClient.Delete(context.TODO(), userProvidedConfigMap)
+
+       g.Eventually(requests, 
timeout).Should(gomega.Receive(gomega.Equal(expectedCloudRequest)))
+
+       g.Eventually(func() error { return testClient.Get(context.TODO(), 
expectedCloudRequest.NamespacedName, instance) }, 
timeout).Should(gomega.Succeed())
+       emptyRequests(requests)
+
+       stateful := &appsv1.StatefulSet{}
+       g.Eventually(func() error { return testClient.Get(context.TODO(), 
cloudSsKey, stateful) }, timeout).Should(gomega.Succeed())
+       assert.NotEmpty(t, 
stateful.Spec.Template.Annotations[util.LogXmlMd5Annotation], "Custom log XML 
MD5 annotation should be set on the pod template!")
+
+       assert.NotNil(t, stateful.Spec.Template.Spec.Volumes)
+       var logXmlVol *corev1.Volume = nil
+       for _, vol := range stateful.Spec.Template.Spec.Volumes {
+               if vol.Name == "log4j2-xml" {
+                       logXmlVol = &vol
+                       break
+               }
+       }
+       assert.NotNil(t, logXmlVol, "Didn't find custom log4j2-xml volume in 
sts config!")
+       assert.NotNil(t, logXmlVol.VolumeSource.ConfigMap, "log4j2-xml Volume 
should have a ConfigMap source")
+       assert.Equal(t, logXmlVol.VolumeSource.ConfigMap.Name, 
testCustomLogXmlConfigMap, "log4j2-xml Volume should have a ConfigMap source")
+
+       var logXmlVolMount *corev1.VolumeMount = nil
+       for _, mount := range 
stateful.Spec.Template.Spec.Containers[0].VolumeMounts {
+               if mount.Name == "log4j2-xml" {
+                       logXmlVolMount = &mount
+                       break
+               }
+       }
+       assert.NotNil(t, logXmlVolMount, "Didn't find the log4j2-xml Volume 
mount")
+       expectedMountPath := fmt.Sprintf("/var/solr/%s", 
testCustomLogXmlConfigMap)
+       assert.Equal(t, expectedMountPath, logXmlVolMount.MountPath)

Review comment:
       Add a error message saying that's the mountPath is incorrect.

##########
File path: controllers/solrcloud_controller_test.go
##########
@@ -759,18 +754,246 @@ func TestCloudWithCustomSolrXmlConfigMapReconcile(t 
*testing.T) {
        // update the embedded solr.xml to trigger a pod rolling restart
        foundConfigMap = &corev1.ConfigMap{}
        err = testClient.Get(context.TODO(), types.NamespacedName{Name: 
testCustomSolrXmlConfigMap, Namespace: instance.Namespace}, foundConfigMap)
-       updateSolrXml := foundConfigMap.Data["solr.xml"]
-       foundConfigMap.Data["solr.xml"] = strings.Replace(updateSolrXml, 
"${zkClientTimeout:30000}", "${zkClientTimeout:15000}", 1)
+       updateSolrXml := foundConfigMap.Data[util.SolrXmlFile]
+       foundConfigMap.Data[util.SolrXmlFile] = strings.Replace(updateSolrXml, 
"${zkClientTimeout:30000}", "${zkClientTimeout:15000}", 1)
        err = testClient.Update(context.TODO(), foundConfigMap)
        g.Expect(err).NotTo(gomega.HaveOccurred())
        g.Eventually(requests, 
timeout).Should(gomega.Receive(gomega.Equal(expectedCloudRequest)))
        g.Eventually(requests, 
timeout).Should(gomega.Receive(gomega.Equal(expectedCloudRequest)))
+       g.Eventually(requests, 
timeout).Should(gomega.Receive(gomega.Equal(expectedCloudRequest)))
 
        // Check the annotation on the pod template to make sure a rolling 
restart will take place
-       updateSolrXml = foundConfigMap.Data["solr.xml"]
+       updateSolrXml = foundConfigMap.Data[util.SolrXmlFile]
        updateSolrXmlMd5 := fmt.Sprintf("%x", md5.Sum([]byte(updateSolrXml)))
        time.Sleep(time.Millisecond * 250)
        err = testClient.Get(context.TODO(), cloudSsKey, stateful)
        g.Expect(err).NotTo(gomega.HaveOccurred())
        assert.Equal(t, updateSolrXmlMd5, 
stateful.Spec.Template.Annotations[util.SolrXmlMd5Annotation], "Custom solr.xml 
MD5 annotation should be updated on the pod template.")
 }
+
+func TestCloudWithUserProvidedLogConfigMapReconcile(t *testing.T) {
+       UseZkCRD(true)
+       g := gomega.NewGomegaWithT(t)
+
+       testCustomLogXmlConfigMap := "my-custom-log4j2-xml"
+
+       instance := &solr.SolrCloud{
+               ObjectMeta: metav1.ObjectMeta{Name: expectedCloudRequest.Name, 
Namespace: expectedCloudRequest.Namespace},
+               Spec: solr.SolrCloudSpec{
+                       CustomSolrKubeOptions: solr.CustomSolrKubeOptions{
+                               ConfigMapOptions: &solr.ConfigMapOptions{
+                                       ProvidedConfigMap: 
testCustomLogXmlConfigMap,
+                               },
+                       },
+               },
+       }
+
+       // Setup the Manager and Controller.  Wrap the Controller Reconcile 
function so it writes each request to a
+       // channel when it is finished.
+       mgr, err := manager.New(testCfg, manager.Options{})
+       g.Expect(err).NotTo(gomega.HaveOccurred())
+       testClient = mgr.GetClient()
+
+       solrCloudReconciler := &SolrCloudReconciler{
+               Client: testClient,
+               Log:    ctrl.Log.WithName("controllers").WithName("SolrCloud"),
+       }
+       newRec, requests := SetupTestReconcile(solrCloudReconciler)
+       g.Expect(solrCloudReconciler.SetupWithManagerAndReconciler(mgr, 
newRec)).NotTo(gomega.HaveOccurred())
+
+       stopMgr, mgrStopped := StartTestManager(mgr, g)
+
+       defer func() {
+               close(stopMgr)
+               mgrStopped.Wait()
+       }()
+
+       cleanupTest(g, instance.Namespace)
+
+       // Create the SolrCloud object and expect the Reconcile and StatefulSet 
to be created
+       err = testClient.Create(context.TODO(), instance)
+       g.Expect(err).NotTo(gomega.HaveOccurred())
+       defer testClient.Delete(context.TODO(), instance)
+
+       // reconcile will have failed b/c the provided ConfigMap doesn't exist 
...
+       g.Eventually(requests, 
timeout).Should(gomega.Receive(gomega.Equal(expectedCloudRequest)))
+
+       userProvidedConfigMap := &corev1.ConfigMap{
+               ObjectMeta: metav1.ObjectMeta{
+                       Name:      testCustomLogXmlConfigMap,
+                       Namespace: instance.Namespace,
+               },
+               Data: map[string]string{
+                       util.LogXmlFile: "<Configuration/>",
+               },
+       }
+       err = testClient.Create(context.TODO(), userProvidedConfigMap)
+       g.Expect(err).NotTo(gomega.HaveOccurred())
+       defer testClient.Delete(context.TODO(), userProvidedConfigMap)
+
+       g.Eventually(requests, 
timeout).Should(gomega.Receive(gomega.Equal(expectedCloudRequest)))
+
+       g.Eventually(func() error { return testClient.Get(context.TODO(), 
expectedCloudRequest.NamespacedName, instance) }, 
timeout).Should(gomega.Succeed())
+       emptyRequests(requests)
+
+       stateful := &appsv1.StatefulSet{}
+       g.Eventually(func() error { return testClient.Get(context.TODO(), 
cloudSsKey, stateful) }, timeout).Should(gomega.Succeed())
+       assert.NotEmpty(t, 
stateful.Spec.Template.Annotations[util.LogXmlMd5Annotation], "Custom log XML 
MD5 annotation should be set on the pod template!")
+
+       assert.NotNil(t, stateful.Spec.Template.Spec.Volumes)
+       var logXmlVol *corev1.Volume = nil
+       for _, vol := range stateful.Spec.Template.Spec.Volumes {
+               if vol.Name == "log4j2-xml" {
+                       logXmlVol = &vol
+                       break
+               }
+       }
+       assert.NotNil(t, logXmlVol, "Didn't find custom log4j2-xml volume in 
sts config!")
+       assert.NotNil(t, logXmlVol.VolumeSource.ConfigMap, "log4j2-xml Volume 
should have a ConfigMap source")
+       assert.Equal(t, logXmlVol.VolumeSource.ConfigMap.Name, 
testCustomLogXmlConfigMap, "log4j2-xml Volume should have a ConfigMap source")
+
+       var logXmlVolMount *corev1.VolumeMount = nil
+       for _, mount := range 
stateful.Spec.Template.Spec.Containers[0].VolumeMounts {
+               if mount.Name == "log4j2-xml" {
+                       logXmlVolMount = &mount
+                       break
+               }
+       }
+       assert.NotNil(t, logXmlVolMount, "Didn't find the log4j2-xml Volume 
mount")
+       expectedMountPath := fmt.Sprintf("/var/solr/%s", 
testCustomLogXmlConfigMap)
+       assert.Equal(t, expectedMountPath, logXmlVolMount.MountPath)
+
+       solrXmlConfigName := fmt.Sprintf("%s-solrcloud-configmap", 
instance.GetName())
+       foundConfigMap := &corev1.ConfigMap{}
+       err = testClient.Get(context.TODO(), types.NamespacedName{Name: 
solrXmlConfigName, Namespace: instance.Namespace}, foundConfigMap)
+       g.Expect(err).NotTo(gomega.HaveOccurred(), "Built-in solr.xml ConfigMap 
should still exist! ")
+
+       emptyRequests(requests)
+       // update the user-provided log XML to trigger a pod rolling restart
+       updatedXml := "<Configuration>Updated!</Configuration>"
+       foundConfigMap = &corev1.ConfigMap{}
+       err = testClient.Get(context.TODO(), types.NamespacedName{Name: 
testCustomLogXmlConfigMap, Namespace: instance.Namespace}, foundConfigMap)
+       foundConfigMap.Data[util.LogXmlFile] = updatedXml
+       err = testClient.Update(context.TODO(), foundConfigMap)
+       g.Expect(err).NotTo(gomega.HaveOccurred())
+       // capture all reconcile requests
+       g.Eventually(requests, 
timeout).Should(gomega.Receive(gomega.Equal(expectedCloudRequest)))
+       g.Eventually(requests, 
timeout).Should(gomega.Receive(gomega.Equal(expectedCloudRequest)))
+       g.Eventually(requests, 
timeout).Should(gomega.Receive(gomega.Equal(expectedCloudRequest)))
+
+       // Check the annotation on the pod template to make sure a rolling 
restart will take place
+       updateLogXmlMd5 := fmt.Sprintf("%x", md5.Sum([]byte(updatedXml)))
+       time.Sleep(time.Millisecond * 250)
+       err = testClient.Get(context.TODO(), cloudSsKey, stateful)
+       g.Expect(err).NotTo(gomega.HaveOccurred())
+       assert.Equal(t, updateLogXmlMd5, 
stateful.Spec.Template.Annotations[util.LogXmlMd5Annotation], "Custom log XML 
MD5 annotation should be updated on the pod template.")
+}
+
+func TestCloudWithUserProvidedSolrXmlAndLogConfigReconcile(t *testing.T) {
+       UseZkCRD(true)
+       g := gomega.NewGomegaWithT(t)
+
+       testCustomConfigMap := "my-custom-config-xml"
+
+       instance := &solr.SolrCloud{
+               ObjectMeta: metav1.ObjectMeta{Name: expectedCloudRequest.Name, 
Namespace: expectedCloudRequest.Namespace},
+               Spec: solr.SolrCloudSpec{
+                       CustomSolrKubeOptions: solr.CustomSolrKubeOptions{
+                               ConfigMapOptions: &solr.ConfigMapOptions{
+                                       ProvidedConfigMap: testCustomConfigMap,
+                               },
+                       },
+               },
+       }
+
+       // Setup the Manager and Controller.  Wrap the Controller Reconcile 
function so it writes each request to a
+       // channel when it is finished.
+       mgr, err := manager.New(testCfg, manager.Options{})
+       g.Expect(err).NotTo(gomega.HaveOccurred())
+       testClient = mgr.GetClient()
+
+       solrCloudReconciler := &SolrCloudReconciler{
+               Client: testClient,
+               Log:    ctrl.Log.WithName("controllers").WithName("SolrCloud"),
+       }
+       newRec, requests := SetupTestReconcile(solrCloudReconciler)
+       g.Expect(solrCloudReconciler.SetupWithManagerAndReconciler(mgr, 
newRec)).NotTo(gomega.HaveOccurred())
+
+       stopMgr, mgrStopped := StartTestManager(mgr, g)
+
+       defer func() {
+               close(stopMgr)
+               mgrStopped.Wait()
+       }()
+
+       cleanupTest(g, instance.Namespace)
+
+       // Create the user-provided ConfigMap first to streamline reconcile,
+       // other tests cover creating it after the reconcile loop starts on the 
SolrCloud
+       userProvidedConfigMap := &corev1.ConfigMap{
+               ObjectMeta: metav1.ObjectMeta{
+                       Name:      testCustomConfigMap,
+                       Namespace: instance.Namespace,
+               },
+               Data: map[string]string{
+                       util.LogXmlFile:  "<Configuration/>",

Review comment:
       Should there be a test where the log4J file is auto-updated? (Thus no 
need for an annotation)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to