Skip to content
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

Fix Deleting out-of-date machines #40

Merged
merged 4 commits into from
Aug 10, 2023
Merged

Conversation

tatlat
Copy link
Member

@tatlat tatlat commented Aug 8, 2023

Issue #, if available:
https://github.com/aws/eks-anywhere-internal/issues/1626

Description of changes:
We should only remove the finalizer on the EtcdadmCluster when all machines have been deleted. Otherwise there may be a situation where out-of-date machines never get cleaned up.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.


machineList := &clusterv1.MachineList{}
g.Expect(fakeClient.List(context.Background(), machineList, client.InNamespace("test"))).To(Succeed())
g.Expect(len(machineList.Items)).To(Equal(0))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this improves the error message in case of error

Suggested change
g.Expect(len(machineList.Items)).To(Equal(0))
g.Expect(machineList.Items).To(BeEmpty())

Comment on lines 405 to 412
machine2.OwnerReferences = []metav1.OwnerReference{
{
Kind: "Cluster",
APIVersion: clusterv1.GroupVersion.String(),
Name: cluster.Name,
UID: cluster.GetUID(),
},
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this ownership is not realistic afaik

Suggested change
machine2.OwnerReferences = []metav1.OwnerReference{
{
Kind: "Cluster",
APIVersion: clusterv1.GroupVersion.String(),
Name: cluster.Name,
UID: cluster.GetUID(),
},
}
notOwnedMachine.OwnerReferences = []metav1.OwnerReference{}

etcdadmCluster.Status.Initialized = true
// etcdadm controller has also registered that the status.Initialized field is true, so it has set InitializedCondition to true
conditions.MarkTrue(etcdadmCluster, etcdv1.InitializedCondition)
machine := newEtcdMachine(etcdadmCluster, cluster)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
machine := newEtcdMachine(etcdadmCluster, cluster)
ownedMachine := newEtcdMachine(etcdadmCluster, cluster)

// etcdadm controller has also registered that the status.Initialized field is true, so it has set InitializedCondition to true
conditions.MarkTrue(etcdadmCluster, etcdv1.InitializedCondition)
machine := newEtcdMachine(etcdadmCluster, cluster)
machine2 := newEtcdMachine(etcdadmCluster, cluster)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
machine2 := newEtcdMachine(etcdadmCluster, cluster)
notOwnedMachine := newEtcdMachine(etcdadmCluster, cluster)

@@ -342,7 +342,7 @@ func (r *EtcdadmClusterReconciler) reconcileDelete(ctx context.Context, etcdClus

ownedMachines := etcdMachines.Filter(collections.OwnedMachines(etcdCluster))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you can move this to after the length check

Copy link
Member

@g-gaston g-gaston left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@tatlat tatlat merged commit c234874 into aws:main Aug 10, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants