Skip to content

Commit

Permalink
Fix the race check after an overlapping deployment is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
janetkuo committed Sep 6, 2016
1 parent 2a7d0df commit 1ece902
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions test/e2e/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package e2e

import (
"fmt"
"strings"
"time"

. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -181,7 +182,15 @@ func checkDeploymentRevision(c *clientset.Clientset, ns, deploymentName, revisio
return deployment, newRS
}

func stopDeploymentOverlap(c *clientset.Clientset, oldC client.Interface, ns, deploymentName, overlapWith string) {
stopDeploymentMaybeOverlap(c, oldC, ns, deploymentName, overlapWith)
}

func stopDeployment(c *clientset.Clientset, oldC client.Interface, ns, deploymentName string) {
stopDeploymentMaybeOverlap(c, oldC, ns, deploymentName, "")
}

func stopDeploymentMaybeOverlap(c *clientset.Clientset, oldC client.Interface, ns, deploymentName, overlapWith string) {
deployment, err := c.Extensions().Deployments(ns).Get(deploymentName)
Expect(err).NotTo(HaveOccurred())

Expand All @@ -202,16 +211,38 @@ func stopDeployment(c *clientset.Clientset, oldC client.Interface, ns, deploymen
options := api.ListOptions{LabelSelector: selector}
rss, err := c.Extensions().ReplicaSets(ns).List(options)
Expect(err).NotTo(HaveOccurred())
Expect(rss.Items).Should(HaveLen(0))
// RSes may be created by overlapping deployments right after this deployment is deleted, ignore them
if len(overlapWith) == 0 {
Expect(rss.Items).Should(HaveLen(0))
} else {
noOverlapRSes := []extensions.ReplicaSet{}
for _, rs := range rss.Items {
if !strings.HasPrefix(rs.Name, overlapWith) {
noOverlapRSes = append(noOverlapRSes, rs)
}
}
Expect(noOverlapRSes).Should(HaveLen(0))
}
framework.Logf("Ensuring deployment %s's Pods were deleted", deploymentName)
var pods *api.PodList
if err := wait.PollImmediate(time.Second, timeout, func() (bool, error) {
pods, err = c.Core().Pods(ns).List(options)
if err != nil {
return false, err
}
if len(pods.Items) == 0 {
// Pods may be created by overlapping deployments right after this deployment is deleted, ignore them
if len(overlapWith) == 0 && len(pods.Items) == 0 {
return true, nil
} else if len(overlapWith) != 0 {
noOverlapPods := []api.Pod{}
for _, pod := range pods.Items {
if !strings.HasPrefix(pod.Name, overlapWith) {
noOverlapPods = append(noOverlapPods, pod)
}
}
if len(noOverlapPods) == 0 {
return true, nil
}
}
return false, nil
}); err != nil {
Expand Down Expand Up @@ -1224,7 +1255,7 @@ func testOverlappingDeployment(f *framework.Framework) {
Expect(rsList.Items[0].Spec.Template.Spec.Containers[0].Image).To(Equal(deploy.Spec.Template.Spec.Containers[0].Image))

By("Deleting the first deployment")
stopDeployment(c, f.Client, ns, deploy.Name)
stopDeploymentOverlap(c, f.Client, ns, deploy.Name, deployOverlapping.Name)

// Wait for overlapping annotation cleared
By("Waiting for the second deployment to clear overlapping annotation")
Expand Down

0 comments on commit 1ece902

Please sign in to comment.