diff --git a/controllers/vspherecluster_reconciler.go b/controllers/vspherecluster_reconciler.go index 123c88bb47..13c3c45f7d 100644 --- a/controllers/vspherecluster_reconciler.go +++ b/controllers/vspherecluster_reconciler.go @@ -51,12 +51,6 @@ import ( infrautilv1 "sigs.k8s.io/cluster-api-provider-vsphere/pkg/util" ) -// legacyIdentityFinalizer is deprecated and should be used only while upgrading the cluster -// from v1alpha3(v.0.7). -// -// Deprecated: legacyIdentityFinalizer will be removed in a future release. -const legacyIdentityFinalizer string = "identity/infrastructure.cluster.x-k8s.io" - type clusterReconciler struct { ControllerManagerContext *capvcontext.ControllerManagerContext Client client.Client @@ -210,11 +204,6 @@ func (r *clusterReconciler) reconcileDelete(ctx context.Context, clusterCtx *cap log.Info(fmt.Sprintf("Removing finalizer from Secret %s/%s having finalizers %v", secret.Namespace, secret.Name, secret.Finalizers)) ctrlutil.RemoveFinalizer(secret, infrav1.SecretIdentitySetFinalizer) - // Check if the old finalizer(from v0.7) is present, if yes, delete it - // For more context, please refer: https://github.com/kubernetes-sigs/cluster-api-provider-vsphere/issues/1482 - if ctrlutil.ContainsFinalizer(secret, legacyIdentityFinalizer) { - ctrlutil.RemoveFinalizer(secret, legacyIdentityFinalizer) - } if err := r.Client.Update(ctx, secret); err != nil { return reconcile.Result{}, err } diff --git a/controllers/vspherecluster_reconciler_test.go b/controllers/vspherecluster_reconciler_test.go index bd5ea5b42a..4a712ed31b 100644 --- a/controllers/vspherecluster_reconciler_test.go +++ b/controllers/vspherecluster_reconciler_test.go @@ -243,116 +243,6 @@ var _ = Describe("VIM based VSphere ClusterReconciler", func() { }, timeout).Should(BeTrue()) }) }) - Context("Reconcile delete", func() { - var ( - secret *corev1.Secret - capiCluster *clusterv1.Cluster - instance *infrav1.VSphereCluster - legacyFinalizer = "identity/infrastructure.cluster.x-k8s.io" - key client.ObjectKey - ) - It("should remove legacy finalizer if present during the cluster deletion", func() { - ctx := context.Background() - capiCluster = &clusterv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - GenerateName: "test1-", - Namespace: "default", - }, - Spec: clusterv1.ClusterSpec{ - InfrastructureRef: &corev1.ObjectReference{ - APIVersion: infrav1.GroupVersion.String(), - Kind: "VsphereCluster", - Name: "vsphere-test1", - }, - }, - } - defer func() { - Expect(testEnv.Cleanup(ctx, capiCluster)).To(Succeed()) - }() - - // Create the CAPI cluster (owner) object - Expect(testEnv.Create(ctx, capiCluster)).To(Succeed()) - - fakeVCenter := startVcenter() - vcURL := fakeVCenter.ServerURL() - defer fakeVCenter.Destroy() - // Create the secret containing the credentials - password, _ := vcURL.User.Password() - - secret = &corev1.Secret{ - ObjectMeta: metav1.ObjectMeta{ - GenerateName: "secret-", - Namespace: "default", - Finalizers: []string{legacyFinalizer}, - }, - Data: map[string][]byte{ - identity.UsernameKey: []byte(vcURL.User.Username()), - identity.PasswordKey: []byte(password), - }, - } - Expect(testEnv.Create(ctx, secret)).To(Succeed()) - Eventually(func() error { - secretKey := client.ObjectKey{Namespace: secret.Namespace, Name: secret.Name} - return testEnv.Get(ctx, secretKey, secret) - }).Should(BeNil()) - - // Create the VSphereCluster object - instance = &infrav1.VSphereCluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "vsphere-test1", - Namespace: "default", - OwnerReferences: []metav1.OwnerReference{ - {Kind: "Cluster", APIVersion: clusterv1.GroupVersion.String(), Name: capiCluster.Name, UID: "blah"}, - }, - }, - Spec: infrav1.VSphereClusterSpec{ - IdentityRef: &infrav1.VSphereIdentityReference{ - Kind: infrav1.SecretKind, - Name: secret.Name, - }, - Server: fmt.Sprintf("%s://%s", vcURL.Scheme, vcURL.Host), - }, - } - Expect(testEnv.Create(ctx, instance)).To(Succeed()) - - // Make sure the VSphereCluster exists. - key = client.ObjectKey{Namespace: instance.Namespace, Name: instance.Name} - Eventually(func() error { - return testEnv.Get(ctx, key, instance) - }, timeout).Should(BeNil()) - - By("checking that the finalizers on the object are set") - Eventually(func() bool { - if err := testEnv.Get(ctx, key, instance); err != nil { - return false - } - return len(instance.Finalizers) > 0 - }, timeout).Should(BeTrue()) - - By("deleting the vspherecluster which has the secret with legacy finalizer") - Expect(testEnv.Delete(ctx, instance)).To(Succeed()) - - By("checking that the secret is deleted") - secretKey := client.ObjectKey{Namespace: secret.Namespace, Name: secret.Name} - Eventually(func() bool { - err := testEnv.Get(ctx, secretKey, secret) - return apierrors.IsNotFound(err) - }, timeout).Should(BeTrue()) - - // confirm that the VSphereCluster is deleted - Eventually(func() bool { - err := testEnv.Get(ctx, key, instance) - return apierrors.IsNotFound(err) - }, timeout).Should(BeTrue()) - - /*By("checking that the secret is deleted") - secretKey := client.ObjectKey{Namespace: secret.Namespace, Name: secret.Name} - Eventually(func() bool { - err := testEnv.Get(ctx, secretKey, secret) - return apierrors.IsNotFound(err) - }, timeout).Should(BeTrue())*/ - }) - }) It("should remove vspherecluster finalizer if the secret does not exist", func() { ctx := context.Background() diff --git a/controllers/vsphereclusteridentity_controller.go b/controllers/vsphereclusteridentity_controller.go index 3fbbb9376b..cfb2d93c5c 100644 --- a/controllers/vsphereclusteridentity_controller.go +++ b/controllers/vsphereclusteridentity_controller.go @@ -192,11 +192,6 @@ func (r clusterIdentityReconciler) reconcileDelete(ctx context.Context, identity return err } log.Info(fmt.Sprintf("Removing finalizer from Secret %s/%s", secret.Namespace, secret.Name)) - // Check if the old finalizer(from v0.7) is present, if yes, delete it - // For more context, please refer: https://github.com/kubernetes-sigs/cluster-api-provider-vsphere/issues/1482 - if ctrlutil.ContainsFinalizer(secret, legacyIdentityFinalizer) { - ctrlutil.RemoveFinalizer(secret, legacyIdentityFinalizer) - } ctrlutil.RemoveFinalizer(secret, infrav1.SecretIdentitySetFinalizer) if err := r.Client.Update(ctx, secret); err != nil { return err diff --git a/test/e2e/data/infrastructure-vsphere/main/ownerreferences/failure-domains.yaml b/test/e2e/data/infrastructure-vsphere/main/ownerreferences/failure-domains.yaml index 6fcabaa219..19e99df921 100644 --- a/test/e2e/data/infrastructure-vsphere/main/ownerreferences/failure-domains.yaml +++ b/test/e2e/data/infrastructure-vsphere/main/ownerreferences/failure-domains.yaml @@ -28,4 +28,4 @@ spec: server: '${VSPHERE_SERVER}' failureDomain: "ownerreferences" placementConstraint: - resourcePool: '${VSPHERE_RESOURCE_POOL}' \ No newline at end of file + resourcePool: '${VSPHERE_RESOURCE_POOL}'