Skip to content

Commit a75938d

Browse files
committed
Fix DaemonSet misscheduled status not updating on node taint changes
Signed-off-by: xigang <[email protected]>
1 parent d133742 commit a75938d

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

pkg/controller/daemon/daemon_controller.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,15 @@ func (dsc *DaemonSetsController) syncNodeUpdate(ctx context.Context, nodeName st
14451445
daemonPods := podsByDS[dsKey]
14461446
scheduled := len(daemonPods) > 0
14471447

1448-
if (shouldRun && !scheduled) || (!shouldContinueRunning && scheduled) {
1448+
// Enqueue DaemonSet for sync in the following scenarios:
1449+
// 1. (shouldRun && !scheduled): Node now meets scheduling requirements but no pod exists
1450+
// - Need to create a new pod on this node
1451+
// 2. (!shouldContinueRunning && scheduled): Node no longer meets requirements but pod exists
1452+
// - Need to delete the existing pod from this node
1453+
// 3. (scheduled && ds.Status.NumberMisscheduled > 0): DaemonSet pod exists and misscheduled count is nonzero.
1454+
// - For example: a pod was scheduled before the node became unready and tainted; after the node becomes ready and taints are removed, the pod may now be valid again.
1455+
// - Need to recalculate NumberMisscheduled to ensure the DaemonSet status accurately reflects the current scheduling state.
1456+
if (shouldRun && !scheduled) || (!shouldContinueRunning && scheduled) || (scheduled && ds.Status.NumberMisscheduled > 0) {
14491457
dsc.enqueueDaemonSet(ds)
14501458
}
14511459
}

pkg/controller/daemon/daemon_controller_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,6 +2410,9 @@ func TestUpdateNode(t *testing.T) {
24102410
expectedEventsFunc func(strategyType apps.DaemonSetUpdateStrategyType) int
24112411
shouldEnqueue bool
24122412
expectedCreates func() int
2413+
// Indicates whether a DaemonSet pod was already present on the node before the node transitioned to Ready and schedulable state.
2414+
// (In other words, was the DaemonSet pod scheduled before the node lost its readiness / was tainted?)
2415+
preExistingPod bool
24132416
}{
24142417
{
24152418
test: "Nothing changed, should not enqueue",
@@ -2422,6 +2425,7 @@ func TestUpdateNode(t *testing.T) {
24222425
}(),
24232426
shouldEnqueue: false,
24242427
expectedCreates: func() int { return 0 },
2428+
preExistingPod: false,
24252429
},
24262430
{
24272431
test: "Node labels changed",
@@ -2434,6 +2438,7 @@ func TestUpdateNode(t *testing.T) {
24342438
}(),
24352439
shouldEnqueue: true,
24362440
expectedCreates: func() int { return 0 },
2441+
preExistingPod: false,
24372442
},
24382443
{
24392444
test: "Node taints changed",
@@ -2446,6 +2451,7 @@ func TestUpdateNode(t *testing.T) {
24462451
ds: newDaemonSet("ds"),
24472452
shouldEnqueue: true,
24482453
expectedCreates: func() int { return 0 },
2454+
preExistingPod: false,
24492455
},
24502456
{
24512457
test: "Node Allocatable changed",
@@ -2475,6 +2481,21 @@ func TestUpdateNode(t *testing.T) {
24752481
expectedCreates: func() int {
24762482
return 1
24772483
},
2484+
preExistingPod: false,
2485+
},
2486+
{
2487+
test: "Pod transitions from misscheduled to scheduled due to node label change",
2488+
oldNode: newNode("node1", nil),
2489+
newNode: newNode("node1", simpleNodeLabel),
2490+
ds: func() *apps.DaemonSet {
2491+
ds := newDaemonSet("ds")
2492+
ds.Spec.Template.Spec.NodeSelector = simpleNodeLabel
2493+
ds.Status.NumberMisscheduled = 1
2494+
return ds
2495+
}(),
2496+
shouldEnqueue: true,
2497+
expectedCreates: func() int { return 0 },
2498+
preExistingPod: true,
24782499
},
24792500
}
24802501
for _, c := range cases {
@@ -2511,6 +2532,10 @@ func TestUpdateNode(t *testing.T) {
25112532
}
25122533
expectSyncDaemonSets(t, manager, c.ds, podControl, expectedCreates, 0, expectedEvents)
25132534

2535+
if c.preExistingPod {
2536+
addPods(manager.podStore, c.oldNode.Name, simpleDaemonSetLabel, c.ds, 1)
2537+
}
2538+
25142539
manager.enqueueDaemonSet = func(ds *apps.DaemonSet) {
25152540
if ds.Name == "ds" {
25162541
enqueued = true

0 commit comments

Comments
 (0)