-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
🐛 Wait for MachinePools to be deleted before deleting KCP Machines #4646
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -19,6 +19,8 @@ package controllers | |||
import ( | ||||
"context" | ||||
"fmt" | ||||
expv1 "sigs.k8s.io/cluster-api/exp/api/v1alpha4" | ||||
"sigs.k8s.io/cluster-api/feature" | ||||
"sync" | ||||
"testing" | ||||
"time" | ||||
|
@@ -1232,6 +1234,55 @@ func TestKubeadmControlPlaneReconciler_reconcileDelete(t *testing.T) { | |||
g.Expect(controlPlaneMachines.Items).To(HaveLen(3)) | ||||
}) | ||||
|
||||
t.Run("does not remove any control plane Machines if MachinePools exist", func(t *testing.T) { | ||||
_ = feature.MutableGates.Set("MachinePool=true") | ||||
g := NewWithT(t) | ||||
|
||||
cluster, kcp, _ := createClusterWithControlPlane() | ||||
controllerutil.AddFinalizer(kcp, controlplanev1.KubeadmControlPlaneFinalizer) | ||||
|
||||
workerMachinePool := &expv1.MachinePool{ | ||||
ObjectMeta: metav1.ObjectMeta{ | ||||
Name: "worker", | ||||
Namespace: cluster.Namespace, | ||||
Labels: map[string]string{ | ||||
clusterv1.ClusterLabelName: cluster.Name, | ||||
}, | ||||
}, | ||||
} | ||||
|
||||
initObjs := []client.Object{cluster.DeepCopy(), kcp.DeepCopy(), workerMachinePool.DeepCopy()} | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This deepCopy is fine though is a bit redundant. I see this is calling cluster-api/test/helpers/client.go Line 38 in 5858391
Also the fakeClient tracker itself deepCopy as well. https://github.com/kubernetes/client-go/blob/master/testing/fixture.go#L373-L376 |
||||
|
||||
for i := 0; i < 3; i++ { | ||||
m, _ := createMachineNodePair(fmt.Sprintf("test-%d", i), cluster, kcp, true) | ||||
initObjs = append(initObjs, m) | ||||
} | ||||
|
||||
fakeClient := newFakeClient(g, initObjs...) | ||||
|
||||
r := &KubeadmControlPlaneReconciler{ | ||||
Client: fakeClient, | ||||
managementCluster: &fakeManagementCluster{ | ||||
Management: &internal.Management{Client: fakeClient}, | ||||
Workload: fakeWorkloadCluster{}, | ||||
}, | ||||
recorder: record.NewFakeRecorder(32), | ||||
} | ||||
|
||||
result, err := r.reconcileDelete(ctx, cluster, kcp) | ||||
g.Expect(result).To(Equal(ctrl.Result{RequeueAfter: deleteRequeueAfter})) | ||||
g.Expect(err).To(BeNil()) | ||||
|
||||
g.Expect(kcp.Finalizers).To(ContainElement(controlplanev1.KubeadmControlPlaneFinalizer)) | ||||
|
||||
controlPlaneMachines := clusterv1.MachineList{} | ||||
labels := map[string]string{ | ||||
clusterv1.MachineControlPlaneLabelName: "", | ||||
} | ||||
g.Expect(fakeClient.List(ctx, &controlPlaneMachines, client.MatchingLabels(labels))).To(Succeed()) | ||||
g.Expect(controlPlaneMachines.Items).To(HaveLen(3)) | ||||
}) | ||||
|
||||
t.Run("removes the finalizer if no control plane Machines exist", func(t *testing.T) { | ||||
g := NewWithT(t) | ||||
|
||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we sum all the dependents in a single integer? If later on we add more classes it might be easier to reason about