From ad0bee482e5aee4487b06f20e262aad6c492ef64 Mon Sep 17 00:00:00 2001 From: Andrea Nodari Date: Fri, 12 Jun 2020 17:31:35 +0200 Subject: [PATCH 1/2] Add test case for a pod becoming schedulable when another pod is added --- test/integration/scheduler/predicates_test.go | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/test/integration/scheduler/predicates_test.go b/test/integration/scheduler/predicates_test.go index 515ce7d7c9b..b04af8f4bc1 100644 --- a/test/integration/scheduler/predicates_test.go +++ b/test/integration/scheduler/predicates_test.go @@ -1106,7 +1106,49 @@ func TestUnschedulablePodBecomesSchedulable(t *testing.T) { return nil }, }, - // TODO(#91111): Add more test cases. + { + name: "pod with pod-affinity gets added", + init: func(cs kubernetes.Interface, _ string) error { + node, err := createNode(cs, "node-1", nil) + if err != nil { + return fmt.Errorf("cannot create node: %v", err) + } + if err := utils.AddLabelsToNode(cs, node.Name, map[string]string{"region": "test"}); err != nil { + return fmt.Errorf("cannot add labels to node: %v", err) + } + return nil + }, + pod: &pausePodConfig{ + Name: "pod-1", + Affinity: &v1.Affinity{ + PodAffinity: &v1.PodAffinity{ + RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{ + { + LabelSelector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "pod-with-affinity": "true", + }, + }, + TopologyKey: "region", + }, + }, + }, + }, + }, + update: func(cs kubernetes.Interface, ns string) error { + podConfig := &pausePodConfig{ + Name: "pod-with-affinity", + Namespace: ns, + Labels: map[string]string{ + "pod-with-affinity": "true", + }, + } + if _, err := createPausePod(cs, initPausePod(podConfig)); err != nil { + return fmt.Errorf("cannot create pod: %v", err) + } + return nil + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { From 0c23caf8e7d845a463c448e70de5efcbdac2d257 Mon Sep 17 00:00:00 2001 From: Andrea Nodari Date: Tue, 16 Jun 2020 18:04:23 +0200 Subject: [PATCH 2/2] Test a pod becoming schedulable when a scheduled pod is updated --- test/integration/scheduler/predicates_test.go | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/test/integration/scheduler/predicates_test.go b/test/integration/scheduler/predicates_test.go index b04af8f4bc1..1c98f5e8601 100644 --- a/test/integration/scheduler/predicates_test.go +++ b/test/integration/scheduler/predicates_test.go @@ -54,6 +54,7 @@ func TestInterPodAffinity(t *testing.T) { "zone": "z11", } for _, node := range nodes { + // TODO(nodo): Use PodWrapper to directly initialize node with labels. if err = utils.AddLabelsToNode(testCtx.ClientSet, node.Name, labels1); err != nil { t.Fatalf("Cannot add labels to node: %v", err) } @@ -895,6 +896,7 @@ func TestEvenPodsSpreadPredicate(t *testing.T) { "zone": fmt.Sprintf("zone-%d", i/2), "node": node.Name, } + // TODO(nodo): Use PodWrapper to directly initialize node with labels. if err = utils.AddLabelsToNode(cs, node.Name, labels); err != nil { t.Fatalf("Cannot add labels to node: %v", err) } @@ -1113,6 +1115,7 @@ func TestUnschedulablePodBecomesSchedulable(t *testing.T) { if err != nil { return fmt.Errorf("cannot create node: %v", err) } + // TODO(nodo): Use PodWrapper to directly initialize node with labels. if err := utils.AddLabelsToNode(cs, node.Name, map[string]string{"region": "test"}); err != nil { return fmt.Errorf("cannot add labels to node: %v", err) } @@ -1149,6 +1152,51 @@ func TestUnschedulablePodBecomesSchedulable(t *testing.T) { return nil }, }, + { + name: "scheduled pod gets updated to match affinity", + init: func(cs kubernetes.Interface, ns string) error { + node, err := createNode(cs, "node-1", nil) + if err != nil { + return fmt.Errorf("cannot create node: %v", err) + } + // TODO(nodo): Use PodWrapper to directly initialize node with labels. + if err := utils.AddLabelsToNode(cs, node.Name, map[string]string{"region": "test"}); err != nil { + return fmt.Errorf("cannot add labels to node: %v", err) + } + if _, err := createPausePod(cs, initPausePod(&pausePodConfig{Name: "pod-to-be-updated", Namespace: ns})); err != nil { + return fmt.Errorf("cannot create pod: %v", err) + } + return nil + }, + pod: &pausePodConfig{ + Name: "pod-1", + Affinity: &v1.Affinity{ + PodAffinity: &v1.PodAffinity{ + RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{ + { + LabelSelector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "pod-with-affinity": "true", + }, + }, + TopologyKey: "region", + }, + }, + }, + }, + }, + update: func(cs kubernetes.Interface, ns string) error { + pod, err := getPod(cs, "pod-to-be-updated", ns) + if err != nil { + return fmt.Errorf("cannot get pod: %v", err) + } + pod.Labels = map[string]string{"pod-with-affinity": "true"} + if _, err := cs.CoreV1().Pods(pod.Namespace).Update(context.TODO(), pod, metav1.UpdateOptions{}); err != nil { + return fmt.Errorf("cannot update pod: %v", err) + } + return nil + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {