diff --git a/pkg/controllers/termination/terminate.go b/pkg/controllers/termination/terminate.go index 43ec6bcb9ac0..8a7110579f1a 100644 --- a/pkg/controllers/termination/terminate.go +++ b/pkg/controllers/termination/terminate.go @@ -61,6 +61,14 @@ 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 { + node.Labels = map[string]string{ + "node.kubernetes.io/exclude-from-external-load-balancers": "karpenter", + } + } else { + node.Labels["node.kubernetes.io/exclude-from-external-load-balancers"] = "karpenter" + } if err := t.KubeClient.Patch(ctx, node, client.MergeFrom(persisted)); err != nil { return fmt.Errorf("patching node %s, %w", node.Name, err) }