@@ -224,43 +224,6 @@ func (r *IronicAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
224224
225225// SetupWithManager sets up the controller with the Manager.
226226func (r * IronicAPIReconciler ) SetupWithManager (ctx context.Context , mgr ctrl.Manager ) error {
227- // watch for configmap where the CM owner label AND the CR.Spec.ManagingCrName label matches
228- configMapFn := func (ctx context.Context , o client.Object ) []reconcile.Request {
229- Log := r .GetLogger (ctx )
230-
231- result := []reconcile.Request {}
232-
233- // get all API CRs
234- apis := & ironicv1.IronicAPIList {}
235- listOpts := []client.ListOption {
236- client .InNamespace (o .GetNamespace ()),
237- }
238- if err := r .Client .List (ctx , apis , listOpts ... ); err != nil {
239- Log .Error (err , "Unable to retrieve API CRs %v" )
240- return nil
241- }
242-
243- label := o .GetLabels ()
244- // TODO: Just trying to verify that the CM is owned by this CR's managing CR
245- if l , ok := label [labels .GetOwnerNameLabelSelector (labels .GetGroupLabel (ironic .ServiceName ))]; ok {
246- for _ , cr := range apis .Items {
247- // return reconcil event for the CR where the CM owner label AND the parentIronicName matches
248- if l == ironicv1 .GetOwningIronicName (& cr ) {
249- // return namespace and Name of CR
250- name := client.ObjectKey {
251- Namespace : o .GetNamespace (),
252- Name : cr .Name ,
253- }
254- Log .Info (fmt .Sprintf ("ConfigMap object %s and CR %s marked with label: %s" , o .GetName (), cr .Name , l ))
255- result = append (result , reconcile.Request {NamespacedName : name })
256- }
257- }
258- }
259- if len (result ) > 0 {
260- return result
261- }
262- return nil
263- }
264227
265228 // index passwordSecretField
266229 if err := mgr .GetFieldIndexer ().IndexField (ctx , & ironicv1.IronicAPI {}, passwordSecretField , func (rawObj client.Object ) []string {
@@ -332,9 +295,6 @@ func (r *IronicAPIReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Man
332295 Owns (& corev1.ServiceAccount {}).
333296 Owns (& rbacv1.Role {}).
334297 Owns (& rbacv1.RoleBinding {}).
335- // watch the config CMs we don't own
336- Watches (& corev1.ConfigMap {},
337- handler .EnqueueRequestsFromMapFunc (configMapFn )).
338298 Watches (
339299 & corev1.Secret {},
340300 handler .EnqueueRequestsFromMapFunc (r .findObjectsForSrc ),
@@ -351,8 +311,36 @@ func (r *IronicAPIReconciler) findObjectsForSrc(ctx context.Context, src client.
351311
352312 l := log .FromContext (ctx ).WithName ("Controllers" ).WithName ("IronicAPI" )
353313
314+ crList := & ironicv1.IronicAPIList {}
315+ listOpts := []client.ListOption {client .InNamespace (src .GetNamespace ())}
316+
317+ if err := r .List (ctx , crList , listOpts ... ); err != nil {
318+ l .Error (err , "Unable to retrieve Conductor CRs %v" )
319+ } else {
320+ label := src .GetLabels ()
321+ // TODO: Just trying to verify that the Secret is owned by this CR's managing CR
322+ if lbl , ok := label [labels .GetOwnerNameLabelSelector (labels .GetGroupLabel (ironic .ServiceName ))]; ok {
323+ for _ , item := range crList .Items {
324+ // return reconcile event for the CR where the Secret owner label AND the parentIronicName matches
325+ if lbl == ironicv1 .GetOwningIronicName (& item ) {
326+ // return Namespace and Name of CR
327+ l .Info (fmt .Sprintf ("input source %s changed, reconcile: %s - %s" , src .GetName (), item .GetName (), item .GetNamespace ()))
328+
329+ requests = append (requests ,
330+ reconcile.Request {
331+ NamespacedName : types.NamespacedName {
332+ Name : item .GetName (),
333+ Namespace : item .GetNamespace (),
334+ },
335+ },
336+ )
337+
338+ }
339+ }
340+ }
341+ }
342+
354343 for _ , field := range ironicAPIWatchFields {
355- crList := & ironicv1.IronicAPIList {}
356344 listOps := & client.ListOptions {
357345 FieldSelector : fields .OneTermEqualSelector (field , src .GetName ()),
358346 Namespace : src .GetNamespace (),
@@ -662,6 +650,31 @@ func (r *IronicAPIReconciler) reconcileNormal(ctx context.Context, instance *iro
662650 //
663651 // check for required OpenStack secret holding passwords for service/admin user and add hash to the vars map
664652 //
653+
654+ // Get secrets by Namespace and Label that we need to hash
655+ labelSelectorMap := map [string ]string {}
656+ lbl := labels .GetOwnerNameLabelSelector (labels .GetGroupLabel (ironic .ServiceName ))
657+ labelSelectorMap [lbl ] = ironicv1 .GetOwningIronicName (instance )
658+ secrets , err := secret .GetSecrets (ctx , helper , instance .Namespace , labelSelectorMap )
659+ if err != nil {
660+ Log .Info (fmt .Sprintf ("No secrets with label %s found" , lbl ))
661+ } else {
662+ for _ , s := range secrets .Items {
663+ hash , err := secret .Hash (& s )
664+ if err != nil {
665+ Log .Info (fmt .Sprintf ("Not able to has secret %s found" , s .Name ))
666+ instance .Status .Conditions .Set (condition .FalseCondition (
667+ condition .InputReadyCondition ,
668+ condition .ErrorReason ,
669+ condition .SeverityWarning ,
670+ condition .InputReadyErrorMessage ,
671+ err .Error ()))
672+ return ctrl.Result {}, err
673+ }
674+ configMapVars [s .Name ] = env .SetValue (hash )
675+ }
676+ }
677+
665678 ospSecret , hash , err := secret .GetSecret (ctx , helper , instance .Spec .Secret , instance .Namespace )
666679 if err != nil {
667680 if k8s_errors .IsNotFound (err ) {
0 commit comments