Skip to content

Commit

Permalink
Fix review findings
Browse files Browse the repository at this point in the history
  • Loading branch information
sbueringer committed Nov 6, 2024
1 parent dc9d019 commit e426bb3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
4 changes: 2 additions & 2 deletions controlplane/kubeadm/internal/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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, "; ")
}
Expand Down
46 changes: 25 additions & 21 deletions controlplane/kubeadm/internal/controllers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand All @@ -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)
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit e426bb3

Please sign in to comment.