Skip to content

Commit 9117ad4

Browse files
fix: don't mark pods with 'karpenter.sh/do-not-disrupt=true' as reschedulable
1 parent 82a7d80 commit 9117ad4

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

pkg/controllers/disruption/drift_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,7 @@ var _ = Describe("Drift", func() {
553553
Expect(ExpectNodes(ctx, env.Client)).To(HaveLen(1))
554554
ExpectExists(ctx, env.Client, nodeClaim)
555555
})
556-
It("should drift nodes that have pods with the karpenter.sh/do-not-disrupt annotation when the NodePool's TerminationGracePeriod is not nil", func() {
557-
nodeClaim.Spec.TerminationGracePeriod = &metav1.Duration{Duration: time.Second * 300}
556+
It("should ignore nodes that have pods with the karpenter.sh/do-not-disrupt annotation when the NodePool's TerminationGracePeriod is not nil", func() {
558557
pod := test.Pod(test.PodOptions{
559558
ObjectMeta: metav1.ObjectMeta{
560559
Annotations: map[string]string{
@@ -570,8 +569,9 @@ var _ = Describe("Drift", func() {
570569

571570
ExpectSingletonReconciled(ctx, disruptionController)
572571

573-
// Expect to create a replacement but not delete the old nodeclaim
574-
Expect(ExpectNodeClaims(ctx, env.Client)).To(HaveLen(2)) // new nodeclaim is created for drift
572+
// Pods with `karpenter.sh/do-not-disrupt` can't be evicted and hence can't be rescheduled on a new node.
573+
// Expect no new nodeclaims to be created.
574+
Expect(ExpectNodeClaims(ctx, env.Client)).To(HaveLen(1))
575575
Expect(ExpectNodes(ctx, env.Client)).To(HaveLen(1))
576576
ExpectExists(ctx, env.Client, nodeClaim)
577577
})

pkg/utils/pod/scheduling.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ func IsActive(pod *corev1.Pod) bool {
3939
// - Is an active pod (isn't terminal or actively terminating) OR Is owned by a StatefulSet and Is Terminating
4040
// - Isn't owned by a DaemonSet
4141
// - Isn't a mirror pod (https://kubernetes.io/docs/tasks/configure-pod-container/static-pod/)
42+
// - Does not have the "karpenter.sh/do-not-disrupt=true" annotation (https://karpenter.sh/docs/concepts/disruption/#pod-level-controls)
4243
func IsReschedulable(pod *corev1.Pod) bool {
4344
// StatefulSet pods can be handled differently here because we know that StatefulSet pods MUST
4445
// get deleted before new pods are re-created. This means that we can model terminating pods for StatefulSets
4546
// differently for higher availability by considering terminating pods for scheduling
4647
return (IsActive(pod) || (IsOwnedByStatefulSet(pod) && IsTerminating(pod))) &&
4748
!IsOwnedByDaemonSet(pod) &&
48-
!IsOwnedByNode(pod)
49+
!IsOwnedByNode(pod) &&
50+
!HasDoNotDisrupt(pod)
4951
}
5052

5153
// IsEvictable checks if a pod is evictable by Karpenter by ensuring that the pod:

0 commit comments

Comments
 (0)