Skip to content

Commit b6bdd64

Browse files
authored
Merge pull request kubernetes#91973 from Huang-Wei/revert-91750
Revert "Fix an issue that a Pod's nominatedNodeName cannot be cleared…
2 parents d62762f + 51a9dcc commit b6bdd64

File tree

4 files changed

+8
-93
lines changed

4 files changed

+8
-93
lines changed

pkg/scheduler/scheduler.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,13 @@ func updatePod(client clientset.Interface, pod *v1.Pod, condition *v1.PodConditi
375375
podCopy := pod.DeepCopy()
376376
// NominatedNodeName is updated only if we are trying to set it, and the value is
377377
// different from the existing one.
378-
if !podutil.UpdatePodCondition(&podCopy.Status, condition) && pod.Status.NominatedNodeName == nominatedNode {
378+
if !podutil.UpdatePodCondition(&podCopy.Status, condition) &&
379+
(len(nominatedNode) == 0 || pod.Status.NominatedNodeName == nominatedNode) {
379380
return nil
380381
}
381-
podCopy.Status.NominatedNodeName = nominatedNode
382+
if nominatedNode != "" {
383+
podCopy.Status.NominatedNodeName = nominatedNode
384+
}
382385
return patchPod(client, pod, podCopy)
383386
}
384387

pkg/scheduler/scheduler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ func TestUpdatePod(t *testing.T) {
13341334
expectedPatchDataPattern: `{"status":{"\$setElementOrder/conditions":\[{"type":"currentType"}],"conditions":\[{"lastProbeTime":"2020-05-13T01:01:01Z","message":"newMessage","reason":"newReason","type":"currentType"}]}}`,
13351335
},
13361336
{
1337-
name: "Should make patch request if pod condition already exists and is identical but nominated node name is different",
1337+
name: "Should not make patch request if pod condition already exists and is identical and nominated node name is not set",
13381338
currentPodConditions: []v1.PodCondition{
13391339
{
13401340
Type: "currentType",
@@ -1354,7 +1354,7 @@ func TestUpdatePod(t *testing.T) {
13541354
Message: "currentMessage",
13551355
},
13561356
currentNominatedNodeName: "node1",
1357-
expectedPatchRequests: 1,
1357+
expectedPatchRequests: 0,
13581358
},
13591359
{
13601360
name: "Should make patch request if pod condition already exists and is identical but nominated node name is set and different",

test/integration/scheduler/preemption_test.go

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626

2727
v1 "k8s.io/api/core/v1"
2828
policy "k8s.io/api/policy/v1beta1"
29-
apierrors "k8s.io/apimachinery/pkg/api/errors"
3029
"k8s.io/apimachinery/pkg/api/resource"
3130
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3231
"k8s.io/apimachinery/pkg/runtime"
@@ -1030,93 +1029,6 @@ func TestNominatedNodeCleanUp(t *testing.T) {
10301029
}
10311030
}
10321031

1033-
func TestNominatedNodeCleanUpUponNodeDeletion(t *testing.T) {
1034-
// Initialize scheduler.
1035-
testCtx := initTest(t, "preemption")
1036-
defer testutils.CleanupTest(t, testCtx)
1037-
1038-
cs := testCtx.ClientSet
1039-
defer cleanupPodsInNamespace(cs, t, testCtx.NS.Name)
1040-
1041-
// Create a node with some resources and a label.
1042-
nodeRes := &v1.ResourceList{
1043-
v1.ResourcePods: *resource.NewQuantity(32, resource.DecimalSI),
1044-
v1.ResourceCPU: *resource.NewMilliQuantity(100, resource.DecimalSI),
1045-
v1.ResourceMemory: *resource.NewQuantity(100, resource.DecimalSI),
1046-
}
1047-
nodeNames := []string{"node1", "node2"}
1048-
for _, nodeName := range nodeNames {
1049-
_, err := createNode(testCtx.ClientSet, nodeName, nodeRes)
1050-
if err != nil {
1051-
t.Fatalf("Error creating nodes: %v", err)
1052-
}
1053-
}
1054-
1055-
// Fill the cluster with one high-priority and one low-priority Pod.
1056-
highPriPod, err := createPausePod(cs, mkPriorityPodWithGrace(testCtx, "high-pod", highPriority, 60))
1057-
if err != nil {
1058-
t.Fatalf("Error creating high-priority pod: %v", err)
1059-
}
1060-
// Make sure the pod is scheduled.
1061-
if err := testutils.WaitForPodToSchedule(cs, highPriPod); err != nil {
1062-
t.Fatalf("Pod %v/%v didn't get scheduled: %v", highPriPod.Namespace, highPriPod.Name, err)
1063-
}
1064-
1065-
lowPriPod, err := createPausePod(cs, mkPriorityPodWithGrace(testCtx, "low-pod", lowPriority, 60))
1066-
if err != nil {
1067-
t.Fatalf("Error creating low-priority pod: %v", err)
1068-
}
1069-
// Make sure the pod is scheduled.
1070-
if err := testutils.WaitForPodToSchedule(cs, lowPriPod); err != nil {
1071-
t.Fatalf("Pod %v/%v didn't get scheduled: %v", lowPriPod.Namespace, lowPriPod.Name, err)
1072-
}
1073-
1074-
// Create a medium-priority Pod.
1075-
medPriPod, err := createPausePod(cs, mkPriorityPodWithGrace(testCtx, "med-pod", mediumPriority, 60))
1076-
if err != nil {
1077-
t.Fatalf("Error creating med-priority pod: %v", err)
1078-
}
1079-
// Check its nominatedNodeName field is set properly.
1080-
if err := waitForNominatedNodeName(cs, medPriPod); err != nil {
1081-
t.Fatalf("NominatedNodeName was not set for pod %v/%v: %v", medPriPod.Namespace, medPriPod.Name, err)
1082-
}
1083-
1084-
// Get the live version of low and med pods.
1085-
lowPriPod, _ = getPod(cs, lowPriPod.Name, lowPriPod.Namespace)
1086-
medPriPod, _ = getPod(cs, medPriPod.Name, medPriPod.Namespace)
1087-
1088-
want, got := lowPriPod.Spec.NodeName, medPriPod.Status.NominatedNodeName
1089-
if want != got {
1090-
t.Fatalf("Expect med-priority's nominatedNodeName to be %v, but got %v.", want, got)
1091-
}
1092-
1093-
// Delete the node where med-priority pod is nominated to.
1094-
cs.CoreV1().Nodes().Delete(context.TODO(), got, metav1.DeleteOptions{})
1095-
if err := wait.Poll(200*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) {
1096-
_, err := cs.CoreV1().Nodes().Get(context.TODO(), got, metav1.GetOptions{})
1097-
if apierrors.IsNotFound(err) {
1098-
return true, nil
1099-
}
1100-
return false, err
1101-
}); err != nil {
1102-
t.Fatalf("Node %v cannot be deleted: %v.", got, err)
1103-
}
1104-
1105-
// Finally verify if med-priority pod's nominatedNodeName gets cleared.
1106-
if err := wait.Poll(200*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) {
1107-
pod, err := cs.CoreV1().Pods(medPriPod.Namespace).Get(context.TODO(), medPriPod.Name, metav1.GetOptions{})
1108-
if err != nil {
1109-
t.Errorf("Error getting the medium priority pod info: %v", err)
1110-
}
1111-
if len(pod.Status.NominatedNodeName) == 0 {
1112-
return true, nil
1113-
}
1114-
return false, err
1115-
}); err != nil {
1116-
t.Errorf("The nominated node name of the medium priority pod was not cleared: %v", err)
1117-
}
1118-
}
1119-
11201032
func mkMinAvailablePDB(name, namespace string, uid types.UID, minAvailable int, matchLabels map[string]string) *policy.PodDisruptionBudget {
11211033
intMinAvailable := intstr.FromInt(minAvailable)
11221034
return &policy.PodDisruptionBudget{

test/integration/scheduler/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ func noPodsInNamespace(c clientset.Interface, podNamespace string) wait.Conditio
483483
// cleanupPodsInNamespace deletes the pods in the given namespace and waits for them to
484484
// be actually deleted.
485485
func cleanupPodsInNamespace(cs clientset.Interface, t *testing.T, ns string) {
486-
if err := cs.CoreV1().Pods(ns).DeleteCollection(context.TODO(), *metav1.NewDeleteOptions(0), metav1.ListOptions{}); err != nil {
486+
if err := cs.CoreV1().Pods(ns).DeleteCollection(context.TODO(), metav1.DeleteOptions{}, metav1.ListOptions{}); err != nil {
487487
t.Errorf("error while listing pod in namespace %v: %v", ns, err)
488488
return
489489
}

0 commit comments

Comments
 (0)