Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Remove previously deprecated code #2451

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Ankitasw marked this conversation as resolved.
Show resolved Hide resolved

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")
Ankitasw marked this conversation as resolved.
Show resolved Hide resolved
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}'