@@ -207,43 +207,6 @@ func (r *IronicConductorReconciler) Reconcile(ctx context.Context, req ctrl.Requ
207207
208208// SetupWithManager sets up the controller with the Manager.
209209func (r * IronicConductorReconciler ) SetupWithManager (ctx context.Context , mgr ctrl.Manager ) error {
210- // watch for configmap where the CM owner label AND the CR.Spec.ManagingCrName label matches
211- configMapFn := func (ctx context.Context , o client.Object ) []reconcile.Request {
212- result := []reconcile.Request {}
213- Log := r .GetLogger (ctx )
214-
215- // get all API CRs
216- apis := & ironicv1.IronicConductorList {}
217- listOpts := []client.ListOption {
218- client .InNamespace (o .GetNamespace ()),
219- }
220- if err := r .Client .List (ctx , apis , listOpts ... ); err != nil {
221- Log .Error (err , "Unable to retrieve API CRs %v" )
222- return nil
223- }
224-
225- label := o .GetLabels ()
226- // TODO: Just trying to verify that the CM is owned by this CR's managing CR
227- if l , ok := label [labels .GetOwnerNameLabelSelector (labels .GetGroupLabel (ironic .ServiceName ))]; ok {
228- for _ , cr := range apis .Items {
229- // return reconcil event for the CR where the CM owner label AND the parentIronicName matches
230- if l == ironicv1 .GetOwningIronicName (& cr ) {
231- // return namespace and Name of CR
232- name := client.ObjectKey {
233- Namespace : o .GetNamespace (),
234- Name : cr .Name ,
235- }
236- Log .Info (fmt .Sprintf ("ConfigMap object %s and CR %s marked with label: %s" , o .GetName (), cr .Name , l ))
237- result = append (result , reconcile.Request {NamespacedName : name })
238- }
239- }
240- }
241- if len (result ) > 0 {
242- return result
243- }
244- return nil
245- }
246-
247210 // index passwordSecretField
248211 if err := mgr .GetFieldIndexer ().IndexField (ctx , & ironicv1.IronicConductor {}, passwordSecretField , func (rawObj client.Object ) []string {
249212 // Extract the secret name from the spec, if one is provided
@@ -291,16 +254,16 @@ func (r *IronicConductorReconciler) SetupWithManager(ctx context.Context, mgr ct
291254 Owns (& rbacv1.Role {}).
292255 Owns (& rbacv1.RoleBinding {}).
293256 // watch the config CMs we don't own
294- Watches (& corev1.ConfigMap {},
295- handler .EnqueueRequestsFromMapFunc (configMapFn )).
296257 Watches (
297258 & corev1.Secret {},
298259 handler .EnqueueRequestsFromMapFunc (r .findObjectsForSrc ),
299260 builder .WithPredicates (predicate.ResourceVersionChangedPredicate {}),
300261 ).
301- Watches (& topologyv1.Topology {},
262+ Watches (
263+ & topologyv1.Topology {},
302264 handler .EnqueueRequestsFromMapFunc (r .findObjectsForSrc ),
303- builder .WithPredicates (predicate.GenerationChangedPredicate {})).
265+ builder .WithPredicates (predicate.GenerationChangedPredicate {}),
266+ ).
304267 Complete (r )
305268}
306269
@@ -309,8 +272,38 @@ func (r *IronicConductorReconciler) findObjectsForSrc(ctx context.Context, src c
309272
310273 l := log .FromContext (ctx ).WithName ("Controllers" ).WithName ("IronicConductor" )
311274
275+ crList := & ironicv1.IronicConductorList {}
276+ namespace := src .GetNamespace ()
277+ listOpts := []client.ListOption {client .InNamespace (namespace )}
278+
279+ if err := r .List (ctx , crList , listOpts ... ); err != nil {
280+ l .Error (err , "Unable to retrieve Conductor CRs %v" )
281+ } else {
282+ label := src .GetLabels ()
283+ // TODO: Just trying to verify that the Secret is owned by this CR's managing CR
284+ if lbl , ok := label [labels .GetOwnerNameLabelSelector (labels .GetGroupLabel (ironic .ServiceName ))]; ok {
285+ for _ , item := range crList .Items {
286+ // return reconcil event for the CR where the Secret owner label AND the parentIronicName matches
287+ if lbl == ironicv1 .GetOwningIronicName (& item ) {
288+ // return Namespace and Name of CR
289+ l .Info (fmt .Sprintf ("input source %s changed, reconcile: %s - %s" , src .GetName (), item .GetName (), item .GetNamespace ()))
290+
291+ requests = append (
292+ requests ,
293+ reconcile.Request {
294+ NamespacedName : k8s_types.NamespacedName {
295+ Name : item .GetName (),
296+ Namespace : item .GetNamespace (),
297+ },
298+ },
299+ )
300+
301+ }
302+ }
303+ }
304+ }
305+
312306 for _ , field := range ironicConductorWatchFields {
313- crList := & ironicv1.IronicConductorList {}
314307 listOps := & client.ListOptions {
315308 FieldSelector : fields .OneTermEqualSelector (field , src .GetName ()),
316309 Namespace : src .GetNamespace (),
0 commit comments