@@ -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
@@ -290,9 +253,6 @@ func (r *IronicConductorReconciler) SetupWithManager(ctx context.Context, mgr ct
290253 Owns (& corev1.ServiceAccount {}).
291254 Owns (& rbacv1.Role {}).
292255 Owns (& rbacv1.RoleBinding {}).
293- // watch the config CMs we don't own
294- Watches (& corev1.ConfigMap {},
295- handler .EnqueueRequestsFromMapFunc (configMapFn )).
296256 Watches (
297257 & corev1.Secret {},
298258 handler .EnqueueRequestsFromMapFunc (r .findObjectsForSrc ),
@@ -309,8 +269,38 @@ func (r *IronicConductorReconciler) findObjectsForSrc(ctx context.Context, src c
309269
310270 l := log .FromContext (ctx ).WithName ("Controllers" ).WithName ("IronicConductor" )
311271
272+ crList := & ironicv1.IronicConductorList {}
273+ namespace := src .GetNamespace ()
274+ listOpts := []client.ListOption {client .InNamespace (namespace )}
275+
276+ if err := r .List (ctx , crList , listOpts ... ); err != nil {
277+ l .Error (err , "Unable to retrieve Conductor CRs %v" )
278+ } else {
279+ label := src .GetLabels ()
280+ // TODO: Just trying to verify that the Secret is owned by this CR's managing CR
281+ if lbl , ok := label [labels .GetOwnerNameLabelSelector (labels .GetGroupLabel (ironic .ServiceName ))]; ok {
282+ for _ , item := range crList .Items {
283+ // return reconcil event for the CR where the Secret owner label AND the parentIronicName matches
284+ if lbl == ironicv1 .GetOwningIronicName (& item ) {
285+ // return Namespace and Name of CR
286+ l .Info (fmt .Sprintf ("input source %s changed, reconcile: %s - %s" , src .GetName (), item .GetName (), item .GetNamespace ()))
287+
288+ requests = append (
289+ requests ,
290+ reconcile.Request {
291+ NamespacedName : k8s_types.NamespacedName {
292+ Name : item .GetName (),
293+ Namespace : item .GetNamespace (),
294+ },
295+ },
296+ )
297+
298+ }
299+ }
300+ }
301+ }
302+
312303 for _ , field := range ironicConductorWatchFields {
313- crList := & ironicv1.IronicConductorList {}
314304 listOps := & client.ListOptions {
315305 FieldSelector : fields .OneTermEqualSelector (field , src .GetName ()),
316306 Namespace : src .GetNamespace (),
@@ -500,6 +490,30 @@ func (r *IronicConductorReconciler) reconcileNormal(ctx context.Context, instanc
500490 //
501491 // check for required OpenStack secret holding passwords for service/admin user and add hash to the vars map
502492 //
493+
494+ // Get secrets by Namespace and Label that we need to hash ...
495+ labelSelectorMap := map [string ]string {}
496+ lbl := labels .GetOwnerNameLabelSelector (labels .GetGroupLabel (ironic .ServiceName ))
497+ labelSelectorMap [lbl ] = ironicv1 .GetOwningIronicName (instance )
498+ secrets , err := secret .GetSecrets (ctx , helper , instance .Namespace , labelSelectorMap )
499+ if err != nil {
500+ Log .Info (fmt .Sprintf ("No secrets with label %s found" , lbl ))
501+ } else {
502+ for _ , s := range secrets .Items {
503+ hash , err := secret .Hash (& s )
504+ if err != nil {
505+ Log .Info (fmt .Sprintf ("Not able to has secret %s not found" , s .Name ))
506+ instance .Status .Conditions .Set (condition .FalseCondition (
507+ condition .InputReadyCondition ,
508+ condition .ErrorReason ,
509+ condition .SeverityWarning ,
510+ condition .InputReadyErrorMessage ,
511+ err .Error ()))
512+ return ctrl.Result {}, err
513+ }
514+ configMapVars [s .Name ] = env .SetValue (hash )
515+ }
516+ }
503517 ospSecret , hash , err := secret .GetSecret (ctx , helper , instance .Spec .Secret , instance .Namespace )
504518 if err != nil {
505519 if k8s_errors .IsNotFound (err ) {
0 commit comments