@@ -49,6 +49,7 @@ import (
4949 "sigs.k8s.io/controller-runtime/pkg/builder"
5050 "sigs.k8s.io/controller-runtime/pkg/client"
5151 "sigs.k8s.io/controller-runtime/pkg/handler"
52+ "sigs.k8s.io/controller-runtime/pkg/predicate"
5253 "sigs.k8s.io/controller-runtime/pkg/reconcile"
5354
5455 batchv1 "k8s.io/api/batch/v1"
@@ -218,6 +219,52 @@ func (r *IronicReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
218219
219220// SetupWithManager sets up the controller with the Manager.
220221func (r * IronicReconciler ) SetupWithManager (mgr ctrl.Manager ) error {
222+ // watch for configmap where the CM owner label AND the CR.Spec.ManagingCrName label matches
223+ configMapFn := func (ctx context.Context , o client.Object ) []reconcile.Request {
224+ Log := r .GetLogger (ctx )
225+
226+ result := []reconcile.Request {}
227+
228+ // get all API CRs
229+ apis := & ironicv1.IronicInspectorList {}
230+ listOpts := []client.ListOption {
231+ client .InNamespace (o .GetNamespace ()),
232+ }
233+ if err := r .Client .List (
234+ ctx ,
235+ apis ,
236+ listOpts ... ); err != nil {
237+
238+ Log .Error (err , "Unable to retrieve API CRs %v" )
239+ return nil
240+ }
241+
242+ label := o .GetLabels ()
243+ // TODO: Just trying to verify that the CM is owned by this CR's managing CR
244+ if l , ok := label [labels .GetOwnerNameLabelSelector (
245+ labels .GetGroupLabel (ironic .ServiceName ))]; ok {
246+ for _ , cr := range apis .Items {
247+ // return reconcil event for the CR where the CM owner label
248+ // AND the parentIronicName matches
249+ if l == ironicv1 .GetOwningIronicName (& cr ) {
250+ // return namespace and Name of CR
251+ name := client.ObjectKey {
252+ Namespace : o .GetNamespace (),
253+ Name : cr .Name ,
254+ }
255+ Log .Info (fmt .Sprintf (
256+ "ConfigMap object %s and CR %s marked with label: %s" ,
257+ o .GetName (), cr .Name , l ))
258+ result = append (
259+ result , reconcile.Request {NamespacedName : name })
260+ }
261+ }
262+ }
263+ if len (result ) > 0 {
264+ return result
265+ }
266+ return nil
267+ }
221268 return ctrl .NewControllerManagedBy (mgr ).
222269 For (& ironicv1.Ironic {}).
223270 Owns (& ironicv1.IronicConductor {}).
@@ -228,10 +275,13 @@ func (r *IronicReconciler) SetupWithManager(mgr ctrl.Manager) error {
228275 Owns (& mariadbv1.MariaDBAccount {}).
229276 Owns (& batchv1.Job {}).
230277 Owns (& corev1.Secret {}).
231- Owns (& corev1.ConfigMap {}).
232278 Owns (& corev1.ServiceAccount {}).
233279 Owns (& rbacv1.Role {}).
234280 Owns (& rbacv1.RoleBinding {}).
281+ Watches (
282+ & corev1.ConfigMap {},
283+ handler .EnqueueRequestsFromMapFunc (configMapFn ),
284+ builder .WithPredicates (predicate.ResourceVersionChangedPredicate {})).
235285 Watches (& keystonev1.KeystoneAPI {},
236286 handler .EnqueueRequestsFromMapFunc (r .findObjectForSrc ),
237287 builder .WithPredicates (keystonev1 .KeystoneAPIStatusChangedPredicate )).
@@ -539,6 +589,10 @@ func (r *IronicReconciler) reconcileNormal(ctx context.Context, instance *ironic
539589 }
540590 }
541591
592+ if instance .Spec .IronicAPI .CustomServiceConfig == "" {
593+ instance .Spec .IronicAPI .CustomServiceConfig = instance .Spec .IronicSpecCore .CustomServiceConfig
594+ }
595+
542596 // deploy ironic-api
543597 ironicAPI , op , err := r .apiDeploymentCreateOrUpdate (instance , & keystoneEndpoints )
544598 if err != nil {
@@ -935,8 +989,8 @@ func (r *IronicReconciler) generateServiceConfigMaps(
935989 // all other files get placed into /etc/ironic to allow overwrite of e.g. policy.json
936990 // TODO: make sure custom.conf can not be overwritten
937991 customData := map [string ]string {
938- common . CustomServiceConfigFileName : instance .Spec .CustomServiceConfig ,
939- "my.cnf" : db .GetDatabaseClientConfig (tlsCfg ), //(mschuppert) for now just get the default my.cnf
992+ "01-ironic-custom.conf" : instance .Spec .CustomServiceConfig ,
993+ "my.cnf" : db .GetDatabaseClientConfig (tlsCfg ), //(mschuppert) for now just get the default my.cnf
940994
941995 }
942996 for key , data := range instance .Spec .DefaultConfigOverwrite {
0 commit comments