clean up labels that are added to node by scheduler e2e tests

pull/6/head
Kevin 2016-06-03 11:30:16 +08:00
parent 9c7dd2a2d6
commit 6c335b9e1f
1 changed files with 28 additions and 17 deletions

View File

@ -125,6 +125,23 @@ func cleanupPods(c *client.Client, ns string) {
} }
} }
func removeLabelOffNode(c *client.Client, nodeName string, labelKey string) {
By("removing the label " + labelKey + " off the node " + nodeName)
node, err := c.Nodes().Get(nodeName)
framework.ExpectNoError(err)
if node.Labels == nil || len(node.Labels[labelKey]) == 0 {
return
}
delete(node.Labels, labelKey)
nodeUpdated, err := c.Nodes().Update(node)
framework.ExpectNoError(err)
By("verifying the node doesn't have the label " + labelKey)
if nodeUpdated.Labels != nil || len(nodeUpdated.Labels[labelKey]) != 0 {
framework.Failf("Failed removing label " + labelKey + " of the node " + nodeName)
}
}
// Waits until all existing pods are scheduled and returns their amount. // Waits until all existing pods are scheduled and returns their amount.
func waitForStableCluster(c *client.Client) int { func waitForStableCluster(c *client.Client) int {
timeout := 10 * time.Minute timeout := 10 * time.Minute
@ -410,7 +427,6 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() {
}) })
It("validates that a pod with an invalid NodeAffinity is rejected", func() { It("validates that a pod with an invalid NodeAffinity is rejected", func() {
By("Trying to launch a pod with an invalid Affinity data.") By("Trying to launch a pod with an invalid Affinity data.")
podName := "without-label" podName := "without-label"
_, err := c.Pods(ns).Create(&api.Pod{ _, err := c.Pods(ns).Create(&api.Pod{
@ -494,6 +510,7 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() {
node, err := c.Nodes().Get(nodeName) node, err := c.Nodes().Get(nodeName)
framework.ExpectNoError(err) framework.ExpectNoError(err)
Expect(node.Labels[k]).To(Equal(v)) Expect(node.Labels[k]).To(Equal(v))
defer removeLabelOffNode(c, nodeName, k)
By("Trying to relaunch the pod, now with labels.") By("Trying to relaunch the pod, now with labels.")
labelPodName := "with-labels" labelPodName := "with-labels"
@ -631,6 +648,7 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() {
node, err := c.Nodes().Get(nodeName) node, err := c.Nodes().Get(nodeName)
framework.ExpectNoError(err) framework.ExpectNoError(err)
Expect(node.Labels[k]).To(Equal(v)) Expect(node.Labels[k]).To(Equal(v))
defer removeLabelOffNode(c, nodeName, k)
By("Trying to relaunch the pod, now with labels.") By("Trying to relaunch the pod, now with labels.")
labelPodName := "with-labels" labelPodName := "with-labels"
@ -680,6 +698,7 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() {
labelPod, err := c.Pods(ns).Get(labelPodName) labelPod, err := c.Pods(ns).Get(labelPodName)
framework.ExpectNoError(err) framework.ExpectNoError(err)
Expect(labelPod.Spec.NodeName).To(Equal(nodeName)) Expect(labelPod.Spec.NodeName).To(Equal(nodeName))
}) })
// Verify that an escaped JSON string of NodeAffinity in a YAML PodSpec works. // Verify that an escaped JSON string of NodeAffinity in a YAML PodSpec works.
@ -725,6 +744,7 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() {
node, err := c.Nodes().Get(nodeName) node, err := c.Nodes().Get(nodeName)
framework.ExpectNoError(err) framework.ExpectNoError(err)
Expect(node.Labels[k]).To(Equal(v)) Expect(node.Labels[k]).To(Equal(v))
defer removeLabelOffNode(c, nodeName, k)
By("Trying to launch a pod that with NodeAffinity setting as embedded JSON string in the annotation value.") By("Trying to launch a pod that with NodeAffinity setting as embedded JSON string in the annotation value.")
labelPodName := "with-labels" labelPodName := "with-labels"
@ -889,6 +909,7 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() {
node, err := c.Nodes().Get(nodeName) node, err := c.Nodes().Get(nodeName)
framework.ExpectNoError(err) framework.ExpectNoError(err)
Expect(node.Labels[k]).To(Equal(v)) Expect(node.Labels[k]).To(Equal(v))
defer removeLabelOffNode(c, nodeName, k)
By("Trying to launch the pod, now with podAffinity.") By("Trying to launch the pod, now with podAffinity.")
labelPodName := "with-podaffinity-" + string(util.NewUUID()) labelPodName := "with-podaffinity-" + string(util.NewUUID())
@ -980,6 +1001,7 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() {
node, err := c.Nodes().Get(nodeName) node, err := c.Nodes().Get(nodeName)
framework.ExpectNoError(err) framework.ExpectNoError(err)
Expect(node.Labels[k]).To(Equal(v)) Expect(node.Labels[k]).To(Equal(v))
defer removeLabelOffNode(c, nodeName, k)
By("Trying to launch the pod, now with podAffinity with same Labels.") By("Trying to launch the pod, now with podAffinity with same Labels.")
labelPodName := "with-podaffinity-" + string(util.NewUUID()) labelPodName := "with-podaffinity-" + string(util.NewUUID())
@ -1069,6 +1091,7 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() {
node, err := c.Nodes().Get(nodeName) node, err := c.Nodes().Get(nodeName)
framework.ExpectNoError(err) framework.ExpectNoError(err)
Expect(node.Labels[k]).To(Equal(v)) Expect(node.Labels[k]).To(Equal(v))
defer removeLabelOffNode(c, nodeName, k)
By("Trying to launch the pod, now with multiple pod affinities with diff LabelOperators.") By("Trying to launch the pod, now with multiple pod affinities with diff LabelOperators.")
labelPodName := "with-podaffinity-" + string(util.NewUUID()) labelPodName := "with-podaffinity-" + string(util.NewUUID())
@ -1169,6 +1192,7 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() {
node, err := c.Nodes().Get(nodeName) node, err := c.Nodes().Get(nodeName)
framework.ExpectNoError(err) framework.ExpectNoError(err)
Expect(node.Labels[k]).To(Equal(v)) Expect(node.Labels[k]).To(Equal(v))
defer removeLabelOffNode(c, nodeName, k)
By("Trying to launch the pod, now with Pod affinity and anti affinity.") By("Trying to launch the pod, now with Pod affinity and anti affinity.")
labelPodName := "with-podantiaffinity-" + string(util.NewUUID()) labelPodName := "with-podantiaffinity-" + string(util.NewUUID())
@ -1272,6 +1296,7 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() {
node, err := c.Nodes().Get(nodeName) node, err := c.Nodes().Get(nodeName)
framework.ExpectNoError(err) framework.ExpectNoError(err)
Expect(node.Labels[k]).To(Equal(v)) Expect(node.Labels[k]).To(Equal(v))
defer removeLabelOffNode(c, nodeName, k)
By("Trying to launch a pod that with PodAffinity & PodAntiAffinity setting as embedded JSON string in the annotation value.") By("Trying to launch a pod that with PodAffinity & PodAntiAffinity setting as embedded JSON string in the annotation value.")
labelPodName := "with-newlabels" labelPodName := "with-newlabels"
@ -1353,6 +1378,7 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() {
{labelKey + "=" + labelValue}, {labelKey + "=" + labelValue},
} }
checkOutput(labelOutput, labelOutputRequiredStrings) checkOutput(labelOutput, labelOutputRequiredStrings)
defer removeLabelOffNode(c, nodeName, labelKey)
By("Trying to relaunch the pod, now with tolerations.") By("Trying to relaunch the pod, now with tolerations.")
tolerationPodName := "with-tolerations" tolerationPodName := "with-tolerations"
@ -1403,14 +1429,6 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() {
if strings.Contains(output, taintName) { if strings.Contains(output, taintName) {
framework.Failf("Failed removing taint " + taintName + " of the node " + nodeName) framework.Failf("Failed removing taint " + taintName + " of the node " + nodeName)
} }
By("removing the label " + labelKey + " off the node " + nodeName)
framework.RunKubectlOrDie("label", "nodes", nodeName, labelKey+"-")
By("verifying the node doesn't have the label " + labelKey)
output = framework.RunKubectlOrDie("describe", "node", nodeName)
if strings.Contains(output, labelKey) {
framework.Failf("Failed removing label " + labelKey + " of the node " + nodeName)
}
}) })
// 1. Run a pod to get an available node, then delete the pod // 1. Run a pod to get an available node, then delete the pod
@ -1475,6 +1493,7 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() {
{labelKey + "=" + labelValue}, {labelKey + "=" + labelValue},
} }
checkOutput(labelOutput, labelOutputRequiredStrings) checkOutput(labelOutput, labelOutputRequiredStrings)
defer removeLabelOffNode(c, nodeName, labelKey)
By("Trying to relaunch the pod, still no tolerations.") By("Trying to relaunch the pod, still no tolerations.")
podNameNoTolerations := "still-no-tolerations" podNameNoTolerations := "still-no-tolerations"
@ -1527,13 +1546,5 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() {
deployedPod, err := c.Pods(ns).Get(podNameNoTolerations) deployedPod, err := c.Pods(ns).Get(podNameNoTolerations)
framework.ExpectNoError(err) framework.ExpectNoError(err)
Expect(deployedPod.Spec.NodeName).To(Equal(nodeName)) Expect(deployedPod.Spec.NodeName).To(Equal(nodeName))
By("removing the label " + labelKey + " off the node " + nodeName)
framework.RunKubectlOrDie("label", "nodes", nodeName, labelKey+"-")
By("verifying the node doesn't have the label " + labelKey)
output = framework.RunKubectlOrDie("describe", "node", nodeName)
if strings.Contains(output, labelKey) {
framework.Failf("Failed removing label " + labelKey + " of the node " + nodeName)
}
}) })
}) })