Skip to content

Commit 6138599

Browse files
committed
[decomission-controller] fix unit test race condition
Commit 0615094 introduced a race condition bc. the decomission controller added a finalizer to the node, which caused the node with the same name to exist in some cases for other tests which weren't expecting it. Addded an addition reconiliation step for cleanup, which removes the node.
1 parent 0615094 commit 6138599

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

internal/controller/decomission_controller_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,17 @@ var _ = Describe("Decommission Controller", func() {
7171
node := &corev1.Node{ObjectMeta: metav1.ObjectMeta{Name: nodeName}}
7272
By("Cleanup the specific node and hypervisor resource")
7373
Expect(client.IgnoreNotFound(k8sClient.Delete(ctx, node))).To(Succeed())
74-
hypervisor := &kvmv1.Hypervisor{ObjectMeta: metav1.ObjectMeta{Name: nodeName}}
75-
Expect(client.IgnoreNotFound(k8sClient.Delete(ctx, hypervisor))).To(Succeed())
74+
75+
// Due to the decommissioning finalizer, we need to reconcile once more to delete the node completely
76+
req := ctrl.Request{
77+
NamespacedName: types.NamespacedName{Name: nodeName},
78+
}
79+
_, err := decomReconciler.Reconcile(ctx, req)
80+
Expect(err).NotTo(HaveOccurred())
81+
82+
nodelist := &corev1.NodeList{}
83+
Expect(k8sClient.List(ctx, nodelist)).To(Succeed())
84+
Expect(nodelist.Items).To(BeEmpty())
7685
})
7786

7887
Context("When reconciling a node", func() {

0 commit comments

Comments
 (0)