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



##########
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'",
+                                       providedConfigMapName)
+                       }
+
+                       if hasSolrXml {
+                               // make sure the user-provided solr.xml is valid
                                if !strings.Contains(solrXml, "${hostPort:") {
                                        return requeueOrNot,
                                                fmt.Errorf("Custom solr.xml in 
ConfigMap %s must contain a placeholder for the 'hostPort' variable, such as 
<int name=\"hostPort\">${hostPort:80}</int>",
-                                                       
instance.Spec.CustomSolrKubeOptions.ConfigMapOptions.ProvidedConfigMap)
+                                                       providedConfigMapName)
                                }
                                // stored in the pod spec annotations on the 
statefulset so that we get a restart when solr.xml changes
-                               solrXmlMd5 = fmt.Sprintf("%x", 
md5.Sum([]byte(solrXml)))
-                               solrXmlConfigMapName = foundConfigMap.Name
-                       } else {
-                               return requeueOrNot, fmt.Errorf("Required 
'solr.xml' key not found in provided ConfigMap %s",
-                                       
instance.Spec.CustomSolrKubeOptions.ConfigMapOptions.ProvidedConfigMap)
+                               configMapInfo[util.SolrXmlMd5Annotation] = 
fmt.Sprintf("%x", md5.Sum([]byte(solrXml)))
+                               configMapInfo[util.SolrXmlFile] = 
foundConfigMap.Name
+                       }
+
+                       if hasLogXml {
+                               if !strings.Contains(logXml, 
"monitorInterval=") {
+                                       // stored in the pod spec annotations 
on the statefulset so that we get a restart when the log config changes
+                                       configMapInfo[util.LogXmlMd5Annotation] 
= fmt.Sprintf("%x", md5.Sum([]byte(logXml)))
+                               } // else log4j will automatically refresh for 
us, so no restart needed
+                               configMapInfo[util.LogXmlFile] = 
foundConfigMap.Name
                        }
+
                } else {
-                       return requeueOrNot, fmt.Errorf("Provided ConfigMap %s 
has no data",
-                               
instance.Spec.CustomSolrKubeOptions.ConfigMapOptions.ProvidedConfigMap)
+                       return requeueOrNot, fmt.Errorf("Provided ConfigMap %s 
has no data", providedConfigMapName)
                }
-       } else {
+       }
+
+       if configMapInfo[util.SolrXmlFile] == "" {

Review comment:
       ok cool ... I switched to keeping all the user-provided ConfigMap info 
in a single map arg to `GenerateStatefulSet` vs. having multiple function args 
just to keep things tidy.




----------------------------------------------------------------
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