Skip to content

Commit

Permalink
Remove deprecated code to prepare branch for release 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Ankitasw committed Oct 26, 2023
1 parent 5211b8e commit e50316a
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 127 deletions.
11 changes: 0 additions & 11 deletions controllers/vspherecluster_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
110 changes: 0 additions & 110 deletions controllers/vspherecluster_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 0 additions & 5 deletions controllers/vsphereclusteridentity_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ spec:
server: '${VSPHERE_SERVER}'
failureDomain: "ownerreferences"
placementConstraint:
resourcePool: '${VSPHERE_RESOURCE_POOL}'
resourcePool: '${VSPHERE_RESOURCE_POOL}'

0 comments on commit e50316a

Please sign in to comment.