thelabdude commented on a change in pull request #312: URL: https://github.com/apache/solr-operator/pull/312#discussion_r698804396
########## File path: controllers/controller_utils_test.go ########## @@ -184,46 +182,6 @@ func expectDeployment(t *testing.T, g *gomega.GomegaWithT, requests chan reconci return deploy } -func verifyUserSuppliedTLSConfig(t *testing.T, tls *solr.SolrTLSOptions, expectedKeystorePasswordSecretName string, expectedKeystorePasswordSecretKey string, expectedTlsSecretName string, needsPkcs12InitContainer bool) { Review comment: Moved these TLS specific test helper functions to `solrcloud_controller_tls_test` as they are only used by TLS tests and now seem out of place in this file ########## File path: controllers/controller_utils_test.go ########## @@ -279,170 +237,6 @@ func expectInitContainer(t *testing.T, podTemplate *corev1.PodTemplateSpec, expN return expInitContainer } -// Ensures all the TLS env vars, volume mounts and initContainers are setup for the PodTemplateSpec Review comment: Moved these TLS specific test helper functions to `solrcloud_controller_tls_test` as they are only used by TLS tests and now seem out of place in this file ########## 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: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org