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

feat: Add LB exclusion label when deleting node #2518

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pkg/controllers/termination/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,25 @@ var _ = Describe("Termination", func() {
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node))
ExpectNotFound(ctx, env.Client, node)
})
It("should exclude nodes from load balancers when terminating", func() {
// This is a kludge to prevent the node from being deleted before we can
// inspect its labels
podNoEvict := test.Pod(test.PodOptions{
NodeName: node.Name,
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{v1alpha5.DoNotEvictPodAnnotationKey: "true"},
OwnerReferences: defaultOwnerRefs,
},
})

ExpectApplied(ctx, env.Client, node, podNoEvict)

Expect(env.Client.Delete(ctx, node)).To(Succeed())
node = ExpectNodeExists(ctx, env.Client, node.Name)
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node))
node = ExpectNodeExists(ctx, env.Client, node.Name)
Expect(node.Labels[v1.LabelNodeExcludeBalancers]).Should(Equal("karpenter"))
})
It("should not evict pods that tolerate unschedulable taint", func() {
podEvict := test.Pod(test.PodOptions{NodeName: node.Name, ObjectMeta: metav1.ObjectMeta{OwnerReferences: defaultOwnerRefs}})
podSkip := test.Pod(test.PodOptions{
Expand Down
5 changes: 5 additions & 0 deletions pkg/controllers/termination/terminate.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ func (t *Terminator) cordon(ctx context.Context, node *v1.Node) error {
// 2. Cordon node
persisted := node.DeepCopy()
node.Spec.Unschedulable = true
// Handle nil map
if node.Labels == nil {
DWSR marked this conversation as resolved.
Show resolved Hide resolved
node.Labels = map[string]string{}
}
node.Labels[v1.LabelNodeExcludeBalancers] = "karpenter"
if err := t.KubeClient.Patch(ctx, node, client.MergeFrom(persisted)); err != nil {
return fmt.Errorf("patching node %s, %w", node.Name, err)
}
Expand Down