From c7aba1e3675058a62d16bd658c23875f0243d202 Mon Sep 17 00:00:00 2001 From: adrianc Date: Tue, 6 Feb 2024 18:53:30 +0200 Subject: [PATCH] Set OwnerReference to sriov-device-plugin configmap The configmap is created by the operator but never deleted. Set OwnerReference to SriovOperatorConfig default CR to ensure its deletion. Signed-off-by: adrianc --- controllers/sriovnetworknodepolicy_controller.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/controllers/sriovnetworknodepolicy_controller.go b/controllers/sriovnetworknodepolicy_controller.go index fa67a54aa..f4b276789 100644 --- a/controllers/sriovnetworknodepolicy_controller.go +++ b/controllers/sriovnetworknodepolicy_controller.go @@ -147,7 +147,7 @@ func (r *SriovNetworkNodePolicyReconciler) Reconcile(ctx context.Context, req ct return reconcile.Result{}, err } // Sync Sriov device plugin ConfigMap object - if err = r.syncDevicePluginConfigMap(ctx, policyList, nodeList); err != nil { + if err = r.syncDevicePluginConfigMap(ctx, defaultOpConf, policyList, nodeList); err != nil { return reconcile.Result{}, err } // Render and sync Daemon objects @@ -193,7 +193,8 @@ func (r *SriovNetworkNodePolicyReconciler) SetupWithManager(mgr ctrl.Manager) er Complete(r) } -func (r *SriovNetworkNodePolicyReconciler) syncDevicePluginConfigMap(ctx context.Context, pl *sriovnetworkv1.SriovNetworkNodePolicyList, nl *corev1.NodeList) error { +func (r *SriovNetworkNodePolicyReconciler) syncDevicePluginConfigMap(ctx context.Context, dc *sriovnetworkv1.SriovOperatorConfig, + pl *sriovnetworkv1.SriovNetworkNodePolicyList, nl *corev1.NodeList) error { logger := log.Log.WithName("syncDevicePluginConfigMap") logger.V(1).Info("Start to sync device plugin ConfigMap") @@ -221,6 +222,11 @@ func (r *SriovNetworkNodePolicyReconciler) syncDevicePluginConfigMap(ctx context }, Data: configData, } + + if err := controllerutil.SetControllerReference(dc, cm, r.Scheme); err != nil { + return err + } + found := &corev1.ConfigMap{} err := r.Get(ctx, types.NamespacedName{Namespace: cm.Namespace, Name: cm.Name}, found) if err != nil {