From 6997a65c3f9db6438277864bd3a7ebd1eabaa11c 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 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/controllers/sriovnetworknodepolicy_controller.go b/controllers/sriovnetworknodepolicy_controller.go index fa67a54aa9..e11c2d7e57 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,8 @@ func (r *SriovNetworkNodePolicyReconciler) syncDevicePluginConfigMap(ctx context }, Data: configData, } + controllerutil.SetControllerReference(dc, cm, r.Scheme) + found := &corev1.ConfigMap{} err := r.Get(ctx, types.NamespacedName{Namespace: cm.Namespace, Name: cm.Name}, found) if err != nil {