Skip to content

Commit a3c14ec

Browse files
authored
Merge pull request kubernetes#73606 from krzysztof-jastrzebski/daemonsets
Deleting pods assigned to not existing nodes only if
2 parents 1b741f4 + 0087af7 commit a3c14ec

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

pkg/controller/daemon/daemon_controller.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -964,8 +964,11 @@ func (dsc *DaemonSetsController) manage(ds *apps.DaemonSet, hash string) error {
964964
failedPodsObserved += failedPodsObservedOnNode
965965
}
966966

967-
// Remove pods assigned to not existing nodes.
968-
podsToDelete = append(podsToDelete, getPodsWithoutNode(nodeList, nodeToDaemonPods)...)
967+
// Remove pods assigned to not existing nodes when daemonset pods are scheduled by default scheduler.
968+
// If node doesn't exist then pods are never scheduled and can't be deleted by PodGCController.
969+
if utilfeature.DefaultFeatureGate.Enabled(features.ScheduleDaemonSetPods) {
970+
podsToDelete = append(podsToDelete, getPodsWithoutNode(nodeList, nodeToDaemonPods)...)
971+
}
969972

970973
// Label new pods using the hash label value of the current history when creating them
971974
if err = dsc.syncNodes(ds, podsToDelete, nodesNeedingDaemonPods, hash); err != nil {
@@ -1529,8 +1532,7 @@ func failedPodsBackoffKey(ds *apps.DaemonSet, nodeName string) string {
15291532
}
15301533

15311534
// getPodsWithoutNode returns list of pods assigned to not existing nodes.
1532-
func getPodsWithoutNode(
1533-
runningNodesList []*v1.Node, nodeToDaemonPods map[string][]*v1.Pod) []string {
1535+
func getPodsWithoutNode(runningNodesList []*v1.Node, nodeToDaemonPods map[string][]*v1.Pod) []string {
15341536
var results []string
15351537
isNodeRunning := make(map[string]bool)
15361538
for _, node := range runningNodesList {

pkg/controller/daemon/daemon_controller_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2461,7 +2461,11 @@ func TestDeletePodForNotExistingNode(t *testing.T) {
24612461
addNodes(manager.nodeStore, 0, 1, nil)
24622462
addPods(manager.podStore, "node-0", simpleDaemonSetLabel, ds, 1)
24632463
addPods(manager.podStore, "node-1", simpleDaemonSetLabel, ds, 1)
2464-
syncAndValidateDaemonSets(t, manager, ds, podControl, 0, 1, 0)
2464+
if f {
2465+
syncAndValidateDaemonSets(t, manager, ds, podControl, 0, 1, 0)
2466+
} else {
2467+
syncAndValidateDaemonSets(t, manager, ds, podControl, 0, 0, 0)
2468+
}
24652469
}
24662470
}
24672471
}

0 commit comments

Comments
 (0)