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



##########
File path: controllers/solrcloud_controller.go
##########
@@ -960,80 +950,166 @@ func (r *SolrCloudReconciler) 
indexAndWatchForTLSSecret(mgr ctrl.Manager, ctrlBu
 
        return ctrlBuilder.Watches(
                &source.Kind{Type: &corev1.Secret{}},
-               &handler.EnqueueRequestsFromMapFunc{
-                       ToRequests: handler.ToRequestsFunc(func(a 
handler.MapObject) []reconcile.Request {
-                               foundClouds := &solr.SolrCloudList{}
-                               listOps := &client.ListOptions{
-                                       FieldSelector: 
fields.OneTermEqualSelector(".spec.solrTLS.pkcs12Secret", a.Meta.GetName()),
-                                       Namespace:     a.Meta.GetNamespace(),
-                               }
-                               err := r.List(context.TODO(), foundClouds, 
listOps)
-                               if err != nil {
-                                       return []reconcile.Request{}
-                               }
+               r.findSolrCloudByFieldValueFunc(field),
+               
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{})), nil
+}
 
-                               requests := make([]reconcile.Request, 
len(foundClouds.Items))
-                               for i, item := range foundClouds.Items {
-                                       requests[i] = reconcile.Request{
-                                               NamespacedName: 
types.NamespacedName{
-                                                       Name:      
item.GetName(),
-                                                       Namespace: 
item.GetNamespace(),
-                                               },
-                                       }
-                               }
-                               return requests
-                       }),
-               },
+func (r *SolrCloudReconciler) indexAndWatchForClientTLSSecret(mgr 
ctrl.Manager, ctrlBuilder *builder.Builder) (*builder.Builder, error) {
+       field := ".spec.solrClientTLS.pkcs12Secret"
+       if err := mgr.GetFieldIndexer().IndexField(context.TODO(), 
&solr.SolrCloud{}, field, func(rawObj runtime.Object) []string {
+               // grab the SolrCloud object, extract the used configMap...
+               solrCloud := rawObj.(*solr.SolrCloud)
+               if solrCloud.Spec.SolrClientTLS == nil || 
solrCloud.Spec.SolrClientTLS.PKCS12Secret == nil {
+                       return nil
+               }
+               // ...and if so, return it
+               return []string{solrCloud.Spec.SolrClientTLS.PKCS12Secret.Name}
+       }); err != nil {
+               return ctrlBuilder, err
+       }
+
+       return ctrlBuilder.Watches(
+               &source.Kind{Type: &corev1.Secret{}},
+               r.findSolrCloudByFieldValueFunc(field),
                
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{})), nil
 }
 
+func (r *SolrCloudReconciler) findSolrCloudByFieldValueFunc(field string) 
*handler.EnqueueRequestsFromMapFunc {
+       return &handler.EnqueueRequestsFromMapFunc{

Review comment:
       Refactored into this reusable function as only the field name varies for 
3 different indexAndWatch funcs.




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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to