From 29da46f30b4908d408d4b9fb6111e0b4a5be3c74 Mon Sep 17 00:00:00 2001 From: killianmuldoon Date: Fri, 25 Nov 2022 09:32:12 +0000 Subject: [PATCH] Fix bug in kubeadmconfig adoption Signed-off-by: killianmuldoon --- .../internal/controllers/kubeadmconfig_controller.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go b/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go index eb4f4c64adf1..7d70bfd0a3be 100644 --- a/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go +++ b/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go @@ -1041,11 +1041,14 @@ func (r *KubeadmConfigReconciler) ensureBootstrapSecretOwnersRef(ctx context.Con if err != nil { return errors.Wrapf(err, "failed to add KubeadmConfig %s as ownerReference to bootstrap Secret %s", scope.ConfigOwner.GetName(), secret.GetName()) } + if controller := metav1.GetControllerOf(secret); controller != nil { + util.RemoveOwnerRef(secret.OwnerReferences, *controller) + } secret.OwnerReferences = util.EnsureOwnerRef(secret.OwnerReferences, metav1.OwnerReference{ - APIVersion: scope.ConfigOwner.GetAPIVersion(), - Kind: scope.ConfigOwner.GetKind(), - UID: scope.ConfigOwner.GetUID(), - Name: scope.ConfigOwner.GetName(), + APIVersion: scope.Config.APIVersion, + Kind: scope.Config.Kind, + UID: scope.Config.UID, + Name: scope.Config.Name, Controller: pointer.Bool(true), }) err = patchHelper.Patch(ctx, secret)