From e426bb30f279589f1c3e43651d9f307bf1a8c5b9 Mon Sep 17 00:00:00 2001 From: Stefan Bueringer Date: Wed, 6 Nov 2024 18:55:21 +0100 Subject: [PATCH] Fix review findings --- .../internal/controllers/controller.go | 4 +- .../internal/controllers/controller_test.go | 46 ++++++++++--------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/controlplane/kubeadm/internal/controllers/controller.go b/controlplane/kubeadm/internal/controllers/controller.go index bad61f6aa192..f1ece2c75a90 100644 --- a/controlplane/kubeadm/internal/controllers/controller.go +++ b/controlplane/kubeadm/internal/controllers/controller.go @@ -641,7 +641,7 @@ func (r *KubeadmControlPlaneReconciler) reconcileDelete(ctx context.Context, con conditions.MarkFalse(controlPlane.KCP, controlplanev1.ResizedCondition, clusterv1.DeletingReason, clusterv1.ConditionSeverityInfo, "Waiting for worker nodes to be deleted first") controlPlane.DeletingReason = controlplanev1.KubeadmControlPlaneDeletingWaitingForWorkersDeletionV1Beta2Reason - controlPlane.DeletingMessage = objectsPendingDeleteNames(allMachines, allMachinePools, controlPlane.Cluster) + controlPlane.DeletingMessage = fmt.Sprintf("KCP deletion blocked because %s still exist", objectsPendingDeleteNames(allMachines, allMachinePools, controlPlane.Cluster)) return ctrl.Result{RequeueAfter: deleteRequeueAfter}, nil } @@ -727,7 +727,7 @@ func objectsPendingDeleteNames(allMachines collections.Machines, allMachinePools } if len(workerMachineNames) > 0 { sort.Strings(workerMachineNames) - descendants = append(descendants, "Worker Machines: "+clog.StringListToString(workerMachineNames)) + descendants = append(descendants, "worker Machines: "+clog.StringListToString(workerMachineNames)) } return strings.Join(descendants, "; ") } diff --git a/controlplane/kubeadm/internal/controllers/controller_test.go b/controlplane/kubeadm/internal/controllers/controller_test.go index 63e738dabeab..fe1e893e84fb 100644 --- a/controlplane/kubeadm/internal/controllers/controller_test.go +++ b/controlplane/kubeadm/internal/controllers/controller_test.go @@ -3079,18 +3079,20 @@ func TestKubeadmControlPlaneReconciler_reconcileDelete(t *testing.T) { cluster, kcp, _ := createClusterWithControlPlane(metav1.NamespaceDefault) controllerutil.AddFinalizer(kcp, controlplanev1.KubeadmControlPlaneFinalizer) - workerMachine := &clusterv1.Machine{ - ObjectMeta: metav1.ObjectMeta{ - Name: "worker", - Namespace: cluster.Namespace, - Labels: map[string]string{ - clusterv1.ClusterNameLabel: cluster.Name, + initObjs := []client.Object{cluster.DeepCopy(), kcp.DeepCopy()} + + for i := range 10 { + initObjs = append(initObjs, &clusterv1.Machine{ + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("worker-%d", i), + Namespace: cluster.Namespace, + Labels: map[string]string{ + clusterv1.ClusterNameLabel: cluster.Name, + }, }, - }, + }) } - initObjs := []client.Object{cluster.DeepCopy(), kcp.DeepCopy(), workerMachine.DeepCopy()} - machines := collections.New() for i := range 3 { m, _ := createMachineNodePair(fmt.Sprintf("test-%d", i), cluster, kcp, true) @@ -3121,7 +3123,7 @@ func TestKubeadmControlPlaneReconciler_reconcileDelete(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) g.Expect(kcp.Finalizers).To(ContainElement(controlplanev1.KubeadmControlPlaneFinalizer)) g.Expect(controlPlane.DeletingReason).To(Equal(controlplanev1.KubeadmControlPlaneDeletingWaitingForWorkersDeletionV1Beta2Reason)) - g.Expect(controlPlane.DeletingMessage).To(Equal("Worker Machines: worker")) + g.Expect(controlPlane.DeletingMessage).To(Equal("KCP deletion blocked because worker Machines: worker-0, worker-1, worker-2, worker-3, worker-4, ... (5 more) still exist")) controlPlaneMachines := clusterv1.MachineList{} labels := map[string]string{ @@ -3138,18 +3140,20 @@ func TestKubeadmControlPlaneReconciler_reconcileDelete(t *testing.T) { cluster, kcp, _ := createClusterWithControlPlane(metav1.NamespaceDefault) controllerutil.AddFinalizer(kcp, controlplanev1.KubeadmControlPlaneFinalizer) - workerMachinePool := &expv1.MachinePool{ - ObjectMeta: metav1.ObjectMeta{ - Name: "worker", - Namespace: cluster.Namespace, - Labels: map[string]string{ - clusterv1.ClusterNameLabel: cluster.Name, + initObjs := []client.Object{cluster.DeepCopy(), kcp.DeepCopy()} + + for i := range 10 { + initObjs = append(initObjs, &expv1.MachinePool{ + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("mp-%d", i), + Namespace: cluster.Namespace, + Labels: map[string]string{ + clusterv1.ClusterNameLabel: cluster.Name, + }, }, - }, + }) } - initObjs := []client.Object{cluster.DeepCopy(), kcp.DeepCopy(), workerMachinePool.DeepCopy()} - machines := collections.New() for i := range 3 { m, _ := createMachineNodePair(fmt.Sprintf("test-%d", i), cluster, kcp, true) @@ -3180,7 +3184,7 @@ func TestKubeadmControlPlaneReconciler_reconcileDelete(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) g.Expect(kcp.Finalizers).To(ContainElement(controlplanev1.KubeadmControlPlaneFinalizer)) g.Expect(controlPlane.DeletingReason).To(Equal(controlplanev1.KubeadmControlPlaneDeletingWaitingForWorkersDeletionV1Beta2Reason)) - g.Expect(controlPlane.DeletingMessage).To(Equal("MachinePools: worker")) + g.Expect(controlPlane.DeletingMessage).To(Equal("KCP deletion blocked because MachinePools: mp-0, mp-1, mp-2, mp-3, mp-4, ... (5 more) still exist")) controlPlaneMachines := clusterv1.MachineList{} labels := map[string]string{ @@ -3264,7 +3268,7 @@ func TestObjectsPendingDelete(t *testing.T) { g := NewWithT(t) - g.Expect(objectsPendingDeleteNames(allMachines, machinePools, c)).To(Equal("MachinePools: mp1; Worker Machines: w1, w2, w3, w4, w5, ... (3 more)")) + g.Expect(objectsPendingDeleteNames(allMachines, machinePools, c)).To(Equal("MachinePools: mp1; worker Machines: w1, w2, w3, w4, w5, ... (3 more)")) } // test utils.