From 2a0d3fbcfb00a8434361a50d4d379b88fab10437 Mon Sep 17 00:00:00 2001 From: gmarek Date: Thu, 4 Aug 2016 10:55:19 +0200 Subject: [PATCH] Fix JSON-based scheduler predicates tests --- test/e2e/scheduler_predicates.go | 86 +++++++++++++++++-- .../pod-with-node-affinity.yaml | 28 ------ .../node-selection/pod-with-pod-affinity.yaml | 37 -------- 3 files changed, 79 insertions(+), 72 deletions(-) delete mode 100644 test/e2e/testing-manifests/node-selection/pod-with-node-affinity.yaml delete mode 100644 test/e2e/testing-manifests/node-selection/pod-with-pod-affinity.yaml diff --git a/test/e2e/scheduler_predicates.go b/test/e2e/scheduler_predicates.go index a478563b3c8..6e3e5ac6ee5 100644 --- a/test/e2e/scheduler_predicates.go +++ b/test/e2e/scheduler_predicates.go @@ -41,6 +41,79 @@ const minPodCPURequest int64 = 500 // variable set in BeforeEach, never modified afterwards var masterNodes sets.String +var podWithNodeAffinity = api.Pod{ + ObjectMeta: api.ObjectMeta{ + Name: "with-labels", + Annotations: map[string]string{ + "scheduler.alpha.kubernetes.io/affinity": `{ + "nodeAffinity": { + "requiredDuringSchedulingIgnoredDuringExecution": { + "nodeSelectorTerms": [{ + "matchExpressions": [{ + "key": "kubernetes.io/e2e-az-name", + "operator": "In", + "values": ["e2e-az1", "e2e-az2"] + }] + }] + } + } + }`, + "another-annotation-key": "another-annotation-value", + }, + }, + Spec: api.PodSpec{ + Containers: []api.Container{ + { + Name: "with-labels", + Image: "gcr.io/google_containers/pause:2.0", + }, + }, + }, +} + +var podWithPodAffinity = api.Pod{ + ObjectMeta: api.ObjectMeta{ + Name: "with-newlabels", + Annotations: map[string]string{ + "scheduler.alpha.kubernetes.io/affinity": `{ + "podAffinity": { + "requiredDuringSchedulingIgnoredDuringExecution": [{ + "labelSelector": { + "matchExpressions": [{ + "key": "security", + "operator": "In", + "values":["S1"] + }] + }, + "topologyKey": "kubernetes.io/hostname" + }] + }, + "podAntiAffinity": { + "requiredDuringSchedulingIgnoredDuringExecution": [{ + "labelSelector": { + "matchExpressions": [{ + "key": "security", + "operator": "In", + "values":["S2"] + }] + }, + "topologyKey": "kubernetes.io/hostname" + }] + } + }`, + "another-annotation-key": "another-annotation-value", + }, + }, + Spec: api.PodSpec{ + Containers: []api.Container{ + { + Name: "with-newlabels", + Image: "gcr.io/google_containers/pause:2.0", + }, + }, + }, +} + // Returns a number of currently scheduled and not scheduled Pods. func getPodsScheduled(pods *api.PodList) (scheduledPods, notScheduledPods []api.Pod) { for _, pod := range pods.Items { @@ -708,9 +781,9 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() { defer framework.RemoveLabelOffNode(c, nodeName, k) By("Trying to launch a pod that with NodeAffinity setting as embedded JSON string in the annotation value.") - labelPodName := "with-labels" - testPodPath := "test/e2e/testing-manifests/node-selection/pod-with-node-affinity.yaml" - framework.RunKubectlOrDie("create", "-f", testPodPath, fmt.Sprintf("--namespace=%v", ns)) + labelPodName := podWithNodeAffinity.Name + pod, err = c.Pods(ns).Create(&podWithNodeAffinity) + framework.ExpectNoError(err) // check that pod got scheduled. We intentionally DO NOT check that the // pod is running because this will create a race condition with the @@ -1223,10 +1296,9 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() { defer framework.RemoveLabelOffNode(c, nodeName, k) By("Trying to launch a pod that with PodAffinity & PodAntiAffinity setting as embedded JSON string in the annotation value.") - labelPodName := "with-newlabels" - testPodPath := "test/e2e/testing-manifests/node-selection/pod-with-pod-affinity.yaml" - framework.RunKubectlOrDie("create", "-f", testPodPath, fmt.Sprintf("--namespace=%v", ns)) - + labelPodName := podWithPodAffinity.Name + pod, err = c.Pods(ns).Create(&podWithPodAffinity) + framework.ExpectNoError(err) // check that pod got scheduled. We intentionally DO NOT check that the // pod is running because this will create a race condition with the // kubelet and the scheduler: the scheduler might have scheduled a pod diff --git a/test/e2e/testing-manifests/node-selection/pod-with-node-affinity.yaml b/test/e2e/testing-manifests/node-selection/pod-with-node-affinity.yaml deleted file mode 100644 index 526f83e4d4f..00000000000 --- a/test/e2e/testing-manifests/node-selection/pod-with-node-affinity.yaml +++ /dev/null @@ -1,28 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: with-labels - annotations: - scheduler.alpha.kubernetes.io/affinity: > - { - "nodeAffinity": { - "requiredDuringSchedulingIgnoredDuringExecution": { - "nodeSelectorTerms": [ - { - "matchExpressions": [ - { - "key": "kubernetes.io/e2e-az-name", - "operator": "In", - "values": ["e2e-az1", "e2e-az2"] - } - ] - } - ] - } - } - } - another-annotation-key: another-annotation-value -spec: - containers: - - name: with-labels - image: gcr.io/google_containers/pause:2.0 diff --git a/test/e2e/testing-manifests/node-selection/pod-with-pod-affinity.yaml b/test/e2e/testing-manifests/node-selection/pod-with-pod-affinity.yaml deleted file mode 100644 index 718602b9229..00000000000 --- a/test/e2e/testing-manifests/node-selection/pod-with-pod-affinity.yaml +++ /dev/null @@ -1,37 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: with-newlabels - annotations: - scheduler.alpha.kubernetes.io/affinity: > - { - "podAffinity": { - "requiredDuringSchedulingIgnoredDuringExecution": [{ - "labelSelector": { - "matchExpressions": [{ - "key": "security", - "operator": "In", - "values":["S1"] - }] - }, - "topologyKey": "kubernetes.io/hostname" - }] - }, - "podAntiAffinity": { - "requiredDuringSchedulingIgnoredDuringExecution": [{ - "labelSelector": { - "matchExpressions": [{ - "key": "security", - "operator": "In", - "values":["S2"] - }] - }, - "topologyKey": "kubernetes.io/hostname" - }] - } - } - another-annotation-key: another-annotation-value -spec: - containers: - - name: with-newlabels - image: gcr.io/google_containers/pause:2.0