Skip to content

Commit c48ba09

Browse files
authored
Merge pull request kubernetes#89959 from alculquicondor/automated-cherry-pick-of-#89908-upstream-release-1.18
Automated cherry pick of kubernetes#89908: Skip updating cache on pod update if the node was deleted
2 parents c37f8ac + 23c6b68 commit c48ba09

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

pkg/scheduler/internal/cache/cache.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,13 @@ func (cache *schedulerCache) addPod(pod *v1.Pod) {
428428

429429
// Assumes that lock is already acquired.
430430
func (cache *schedulerCache) updatePod(oldPod, newPod *v1.Pod) error {
431+
if _, ok := cache.nodes[newPod.Spec.NodeName]; !ok {
432+
// The node might have been deleted already.
433+
// This is not a problem in the case where a pod update arrives before the
434+
// node creation, because we will always have a create pod event before
435+
// that, which will create the placeholder node item.
436+
return nil
437+
}
431438
if err := cache.removePod(oldPod); err != nil {
432439
return err
433440
}

pkg/scheduler/internal/cache/cache_test.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,15 +1232,15 @@ func TestSchedulerCache_UpdateSnapshot(t *testing.T) {
12321232

12331233
// Create a few pods for tests.
12341234
pods := []*v1.Pod{}
1235-
for i := 0; i < 10; i++ {
1235+
for i := 0; i < 20; i++ {
12361236
pod := &v1.Pod{
12371237
ObjectMeta: metav1.ObjectMeta{
12381238
Name: fmt.Sprintf("test-pod%v", i),
12391239
Namespace: "test-ns",
12401240
UID: types.UID(fmt.Sprintf("test-puid%v", i)),
12411241
},
12421242
Spec: v1.PodSpec{
1243-
NodeName: fmt.Sprintf("test-node%v", i),
1243+
NodeName: fmt.Sprintf("test-node%v", i%10),
12441244
},
12451245
}
12461246
pods = append(pods, pod)
@@ -1313,6 +1313,13 @@ func TestSchedulerCache_UpdateSnapshot(t *testing.T) {
13131313
}
13141314
}
13151315
}
1316+
removePod := func(i int) operation {
1317+
return func() {
1318+
if err := cache.RemovePod(pods[i]); err != nil {
1319+
t.Error(err)
1320+
}
1321+
}
1322+
}
13161323
removePodWithAffinity := func(i int) operation {
13171324
return func() {
13181325
if err := cache.RemovePod(podsWithAffinity[i]); err != nil {
@@ -1381,13 +1388,6 @@ func TestSchedulerCache_UpdateSnapshot(t *testing.T) {
13811388
},
13821389
expected: []*v1.Node{nodes[6], nodes[5], nodes[2], nodes[0]},
13831390
},
1384-
{
1385-
name: "Remove non-existing node",
1386-
operations: []operation{
1387-
addNode(0), addNode(1), updateSnapshot(),
1388-
},
1389-
expected: []*v1.Node{nodes[1], nodes[0]},
1390-
},
13911391
{
13921392
name: "Update some nodes",
13931393
operations: []operation{
@@ -1444,11 +1444,19 @@ func TestSchedulerCache_UpdateSnapshot(t *testing.T) {
14441444
expected: []*v1.Node{nodes[0], nodes[4], nodes[2]},
14451445
},
14461446
{
1447-
name: "Remove pod from non-existing node",
1447+
name: "Add pod before its node",
1448+
operations: []operation{
1449+
addNode(0), addPod(1), updatePod(1), addNode(1),
1450+
},
1451+
expected: []*v1.Node{nodes[1], nodes[0]},
1452+
},
1453+
{
1454+
name: "Remove node before its pods",
14481455
operations: []operation{
1449-
addNode(0), addPod(0), addNode(2), updateSnapshot(),
1456+
addNode(0), addNode(1), addPod(1), addPod(11),
1457+
removeNode(1), updatePod(1), updatePod(11), removePod(1), removePod(11),
14501458
},
1451-
expected: []*v1.Node{nodes[2], nodes[0]},
1459+
expected: []*v1.Node{nodes[0]},
14521460
},
14531461
{
14541462
name: "Add Pods with affinity",

0 commit comments

Comments
 (0)