fix kubectl taint test flake

This commit is contained in:
Kevin 2016-11-15 16:16:38 +08:00
parent 2bd8bb2699
commit 6211669a19

View File

@ -156,9 +156,9 @@ func readTestFileOrDie(file string) []byte {
func runKubectlRetryOrDie(args ...string) string { func runKubectlRetryOrDie(args ...string) string {
var err error var err error
var output string var output string
for i := 0; i < 3; i++ { for i := 0; i < 5; i++ {
output, err = framework.RunKubectl(args...) output, err = framework.RunKubectl(args...)
if err == nil || !strings.Contains(err.Error(), registry.OptimisticLockErrorMsg) { if err == nil || (!strings.Contains(err.Error(), registry.OptimisticLockErrorMsg) && !strings.Contains(err.Error(), "Operation cannot be fulfilled")) {
break break
} }
time.Sleep(time.Second) time.Sleep(time.Second)
@ -1355,18 +1355,17 @@ var _ = framework.KubeDescribe("Kubectl client", func() {
framework.KubeDescribe("Kubectl taint", func() { framework.KubeDescribe("Kubectl taint", func() {
It("should update the taint on a node", func() { It("should update the taint on a node", func() {
testTaint := api.Taint{ testTaint := api.Taint{
Key: fmt.Sprintf("kubernetes.io/e2e-taint-key-%s", string(uuid.NewUUID())), Key: fmt.Sprintf("kubernetes.io/e2e-taint-key-001-%s", string(uuid.NewUUID())),
Value: "testing-taint-value", Value: "testing-taint-value",
Effect: api.TaintEffectNoSchedule, Effect: api.TaintEffectNoSchedule,
} }
nodes, err := c.Core().Nodes().List(api.ListOptions{}) nodeName := getNodeThatCanRunPod(f)
Expect(err).NotTo(HaveOccurred())
node := nodes.Items[0]
nodeName := node.Name
By("adding the taint " + testTaint.ToString() + " to a node") By("adding the taint " + testTaint.ToString() + " to a node")
runKubectlRetryOrDie("taint", "nodes", nodeName, testTaint.ToString()) runKubectlRetryOrDie("taint", "nodes", nodeName, testTaint.ToString())
defer framework.RemoveTaintOffNode(f.ClientSet, nodeName, testTaint)
By("verifying the node has the taint " + testTaint.ToString()) By("verifying the node has the taint " + testTaint.ToString())
output := runKubectlRetryOrDie("describe", "node", nodeName) output := runKubectlRetryOrDie("describe", "node", nodeName)
requiredStrings := [][]string{ requiredStrings := [][]string{
@ -1387,18 +1386,17 @@ var _ = framework.KubeDescribe("Kubectl client", func() {
It("should remove all the taints with the same key off a node", func() { It("should remove all the taints with the same key off a node", func() {
testTaint := api.Taint{ testTaint := api.Taint{
Key: fmt.Sprintf("kubernetes.io/e2e-taint-key-%s", string(uuid.NewUUID())), Key: fmt.Sprintf("kubernetes.io/e2e-taint-key-002-%s", string(uuid.NewUUID())),
Value: "testing-taint-value", Value: "testing-taint-value",
Effect: api.TaintEffectNoSchedule, Effect: api.TaintEffectNoSchedule,
} }
nodes, err := c.Core().Nodes().List(api.ListOptions{}) nodeName := getNodeThatCanRunPod(f)
Expect(err).NotTo(HaveOccurred())
node := nodes.Items[0]
nodeName := node.Name
By("adding the taint " + testTaint.ToString() + " to a node") By("adding the taint " + testTaint.ToString() + " to a node")
runKubectlRetryOrDie("taint", "nodes", nodeName, testTaint.ToString()) runKubectlRetryOrDie("taint", "nodes", nodeName, testTaint.ToString())
defer framework.RemoveTaintOffNode(f.ClientSet, nodeName, testTaint)
By("verifying the node has the taint " + testTaint.ToString()) By("verifying the node has the taint " + testTaint.ToString())
output := runKubectlRetryOrDie("describe", "node", nodeName) output := runKubectlRetryOrDie("describe", "node", nodeName)
requiredStrings := [][]string{ requiredStrings := [][]string{
@ -1415,6 +1413,8 @@ var _ = framework.KubeDescribe("Kubectl client", func() {
} }
By("adding another taint " + newTestTaint.ToString() + " to the node") By("adding another taint " + newTestTaint.ToString() + " to the node")
runKubectlRetryOrDie("taint", "nodes", nodeName, newTestTaint.ToString()) runKubectlRetryOrDie("taint", "nodes", nodeName, newTestTaint.ToString())
defer framework.RemoveTaintOffNode(f.ClientSet, nodeName, newTestTaint)
By("verifying the node has the taint " + newTestTaint.ToString()) By("verifying the node has the taint " + newTestTaint.ToString())
output = runKubectlRetryOrDie("describe", "node", nodeName) output = runKubectlRetryOrDie("describe", "node", nodeName)
requiredStrings = [][]string{ requiredStrings = [][]string{