Skip to content

Commit 564968a

Browse files
committed
remove the vspherecluster finalizer when the secret does not exist
Signed-off-by: Yassine TIJANI <[email protected]>
1 parent edf69b9 commit 564968a

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

controllers/vspherecluster_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ func (r clusterReconciler) reconcileDelete(ctx *context.ClusterContext) (reconci
253253
err := ctx.Client.Get(ctx, secretKey, secret)
254254
if err != nil {
255255
if apierrors.IsNotFound(err) {
256+
ctrlutil.RemoveFinalizer(ctx.VSphereCluster, infrav1.ClusterFinalizer)
256257
return reconcile.Result{}, nil
257258
}
258259
return reconcile.Result{}, err

controllers/vspherecluster_controller_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
. "github.com/onsi/gomega"
2525

2626
corev1 "k8s.io/api/core/v1"
27+
apierrors "k8s.io/apimachinery/pkg/api/errors"
2728
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2829
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
2930
"sigs.k8s.io/cluster-api/util/conditions"
@@ -206,5 +207,61 @@ var _ = Describe("ClusterReconciler", func() {
206207
}))
207208
}, timeout).Should(BeTrue())
208209
})
210+
211+
It("should remove vspherecluster finalizer if the secret does not exist", func() {
212+
ctx := goctx.Background()
213+
214+
capiCluster := &clusterv1.Cluster{
215+
ObjectMeta: metav1.ObjectMeta{
216+
GenerateName: "test1-",
217+
Namespace: "default",
218+
},
219+
Spec: clusterv1.ClusterSpec{
220+
InfrastructureRef: &corev1.ObjectReference{
221+
APIVersion: "infrastructure.cluster.x-k8s.io/v1alpha4",
222+
Kind: "VsphereCluster",
223+
Name: "vsphere-test1",
224+
},
225+
},
226+
}
227+
// Create the CAPI cluster (owner) object
228+
Expect(testEnv.Create(ctx, capiCluster)).To(Succeed())
229+
230+
// Create the VSphereCluster object
231+
instance := &infrav1.VSphereCluster{
232+
ObjectMeta: metav1.ObjectMeta{
233+
Name: "vsphere-test1",
234+
Namespace: "default",
235+
},
236+
Spec: infrav1.VSphereClusterSpec{
237+
IdentityRef: &infrav1.VSphereIdentityReference{
238+
Kind: infrav1.SecretKind,
239+
Name: "foo",
240+
},
241+
},
242+
}
243+
244+
Expect(testEnv.Create(ctx, instance)).To(Succeed())
245+
key := client.ObjectKey{Namespace: instance.Namespace, Name: instance.Name}
246+
247+
// Make sure the VSphereCluster exists.
248+
Eventually(func() bool {
249+
err := testEnv.Get(ctx, key, instance)
250+
return err == nil
251+
}, timeout).Should(BeTrue())
252+
253+
By("deleting the vspherecluster while the secret is gone")
254+
Eventually(func() bool {
255+
err := testEnv.Delete(ctx, instance)
256+
return err == nil
257+
}, timeout).Should(BeTrue())
258+
259+
Eventually(func() bool {
260+
err := testEnv.Get(ctx, key, instance)
261+
return apierrors.IsNotFound(err)
262+
}, timeout).Should(BeTrue())
263+
264+
})
265+
209266
})
210267
})

0 commit comments

Comments
 (0)