Merge pull request #32004 from janetkuo/overlapping-deployment-e2e-stop-flake

Automatic merge from submit-queue

Fix the race check after an overlapping deployment is deleted

<!--  Thanks for sending a pull request!  Here are some tips for you:
1. If this is your first time, read our contributor guidelines https://github.com/kubernetes/kubernetes/blob/master/CONTRIBUTING.md and developer guide https://github.com/kubernetes/kubernetes/blob/master/docs/devel/development.md
2. If you want *faster* PR reviews, read how: https://github.com/kubernetes/kubernetes/blob/master/docs/devel/faster_reviews.md
3. Follow the instructions for writing a release note: https://github.com/kubernetes/kubernetes/blob/master/docs/devel/pull-requests.md#release-notes
-->

**What this PR does / why we need it**: When deleting deployments in the "overlapping deployment" e2e test, we check that the deployment's RSes & Pods are deleted as well. However, other RSes and Pods (that matches this deployment's selector) may be created by overlapping deployments right after this one is deleted. So when we check that, we should ignore those created by overlapping deployments. 

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #31502

**Special notes for your reviewer**:

**Release note**:
<!--  Steps to write your release note:
1. Use the release-note-* labels to set the release note state (if you have access) 
2. Enter your extended release note in the below block; leaving it blank means using the PR title as the release note. If no release note is required, just write `NONE`. 
-->
```release-note
NONE
```

cc @kubernetes/deployment @pwittrock @kargakis
pull/6/head
Kubernetes Submit Queue 2016-09-06 13:06:08 -07:00 committed by GitHub
commit 5b7f75b314
1 changed files with 34 additions and 3 deletions

View File

@ -18,6 +18,7 @@ package e2e
import (
"fmt"
"strings"
"time"
. "github.com/onsi/ginkgo"
@ -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())
@ -202,7 +211,18 @@ 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) {
@ -210,8 +230,19 @@ func stopDeployment(c *clientset.Clientset, oldC client.Interface, ns, deploymen
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 {
@ -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")