Add e2e test for overlapping deployments

This commit is contained in:
Janet Kuo 2016-08-17 15:37:04 -07:00
parent 90557ec56c
commit c5cef18735
2 changed files with 125 additions and 1 deletions

View File

@ -86,6 +86,9 @@ var _ = framework.KubeDescribe("Deployment", func() {
It("scaled rollout deployment should not block on annotation check", func() {
testScaledRolloutDeployment(f)
})
It("overlapping deployment should not fight with each other", func() {
testOverlappingDeployment(f)
})
// TODO: add tests that cover deployment.Spec.MinReadySeconds once we solved clock-skew issues
})
@ -203,7 +206,7 @@ func stopDeployment(c *clientset.Clientset, oldC client.Interface, ns, deploymen
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(api.ListOptions{})
pods, err = c.Core().Pods(ns).List(options)
if err != nil {
return false, err
}
@ -1177,3 +1180,111 @@ func testScaledRolloutDeployment(f *framework.Framework) {
err = framework.WaitForDeploymentStatus(c, deployment)
Expect(err).NotTo(HaveOccurred())
}
func testOverlappingDeployment(f *framework.Framework) {
ns := f.Namespace.Name
// TODO: remove unversionedClient when the refactoring is done. Currently some
// functions like verifyPod still expects a unversioned#Client.
c := adapter.FromUnversionedClient(f.Client)
deploymentName := "first-deployment"
podLabels := map[string]string{"name": redisImageName}
replicas := int32(1)
By(fmt.Sprintf("Creating deployment %q", deploymentName))
d := newDeployment(deploymentName, replicas, podLabels, redisImageName, redisImage, extensions.RollingUpdateDeploymentStrategyType, nil)
deploy, err := c.Extensions().Deployments(ns).Create(d)
Expect(err).NotTo(HaveOccurred(), "Failed creating the first deployment")
// Wait for it to be updated to revision 1
err = framework.WaitForDeploymentRevisionAndImage(c, ns, deploy.Name, "1", redisImage)
Expect(err).NotTo(HaveOccurred(), "The first deployment failed to update to revision 1")
Expect(err).NotTo(HaveOccurred())
deploymentName = "second-deployment"
By(fmt.Sprintf("Creating deployment %q with overlapping selector", deploymentName))
d = newDeployment(deploymentName, replicas, podLabels, nginxImageName, nginxImage, extensions.RollingUpdateDeploymentStrategyType, nil)
deployOverlapping, err := c.Extensions().Deployments(ns).Create(d)
Expect(err).NotTo(HaveOccurred(), "Failed creating the second deployment")
defer stopDeployment(c, f.Client, ns, deployOverlapping.Name)
// Wait for overlapping annotation updated to both deployments
By("Waiting for both deployments to have overlapping annotations")
err = framework.WaitForOverlappingAnnotationMatch(c, ns, deploy.Name, deployOverlapping.Name)
Expect(err).NotTo(HaveOccurred(), "Failed to update the first deployment's overlapping annotation")
err = framework.WaitForOverlappingAnnotationMatch(c, ns, deployOverlapping.Name, deploy.Name)
Expect(err).NotTo(HaveOccurred(), "Failed to update the second deployment's overlapping annotation")
// Only the first deployment is synced
By("Checking only the first overlapping deployment is synced")
options := api.ListOptions{}
rsList, err := c.Extensions().ReplicaSets(ns).List(options)
Expect(err).NotTo(HaveOccurred(), "Failed listing all replica sets in namespace %s", ns)
Expect(rsList.Items).To(HaveLen(int(replicas)))
Expect(rsList.Items[0].Spec.Template.Spec.Containers).To(HaveLen(1))
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)
// Wait for overlapping annotation cleared
By("Waiting for the second deployment to clear overlapping annotation")
err = framework.WaitForOverlappingAnnotationMatch(c, ns, deployOverlapping.Name, "")
Expect(err).NotTo(HaveOccurred(), "Failed to clear the second deployment's overlapping annotation")
// Wait for it to be updated to revision 1
err = framework.WaitForDeploymentRevisionAndImage(c, ns, deployOverlapping.Name, "1", nginxImage)
Expect(err).NotTo(HaveOccurred(), "The second deployment failed to update to revision 1")
// Now the second deployment is synced
By("Checking the second overlapping deployment is synced")
rsList, err = c.Extensions().ReplicaSets(ns).List(options)
Expect(err).NotTo(HaveOccurred(), "Failed listing all replica sets in namespace %s", ns)
Expect(rsList.Items).To(HaveLen(int(replicas)))
Expect(rsList.Items[0].Spec.Template.Spec.Containers).To(HaveLen(1))
Expect(rsList.Items[0].Spec.Template.Spec.Containers[0].Image).To(Equal(deployOverlapping.Spec.Template.Spec.Containers[0].Image))
deploymentName = "third-deployment"
podLabels = map[string]string{"name": nginxImageName}
By(fmt.Sprintf("Creating deployment %q", deploymentName))
d = newDeployment(deploymentName, replicas, podLabels, nginxImageName, nginxImage, extensions.RollingUpdateDeploymentStrategyType, nil)
deployLater, err := c.Extensions().Deployments(ns).Create(d)
Expect(err).NotTo(HaveOccurred(), "Failed creating the third deployment")
defer stopDeployment(c, f.Client, ns, deployLater.Name)
// Wait for it to be updated to revision 1
err = framework.WaitForDeploymentRevisionAndImage(c, ns, deployLater.Name, "1", nginxImage)
Expect(err).NotTo(HaveOccurred(), "The third deployment failed to update to revision 1")
// Update the second deployment's selector to make it overlap with the third deployment
By(fmt.Sprintf("Updating deployment %q selector to make it overlap with existing one", deployOverlapping.Name))
deployOverlapping, err = framework.UpdateDeploymentWithRetries(c, ns, deployOverlapping.Name, func(update *extensions.Deployment) {
update.Spec.Selector = deployLater.Spec.Selector
update.Spec.Template.Labels = deployLater.Spec.Template.Labels
update.Spec.Template.Spec.Containers[0].Image = redisImage
})
Expect(err).NotTo(HaveOccurred())
// Wait for overlapping annotation updated to both deployments
By("Waiting for both deployments to have overlapping annotations")
err = framework.WaitForOverlappingAnnotationMatch(c, ns, deployOverlapping.Name, deployLater.Name)
Expect(err).NotTo(HaveOccurred(), "Failed to update the second deployment's overlapping annotation")
err = framework.WaitForOverlappingAnnotationMatch(c, ns, deployLater.Name, deployOverlapping.Name)
Expect(err).NotTo(HaveOccurred(), "Failed to update the third deployment's overlapping annotation")
// The second deployment shouldn't be synced
By("Checking the second deployment is not synced")
Expect(deployOverlapping.Annotations[deploymentutil.RevisionAnnotation]).To(Equal("1"))
// Update the second deployment's selector to make it not overlap with the third deployment
By(fmt.Sprintf("Updating deployment %q selector to make it not overlap with existing one", deployOverlapping.Name))
deployOverlapping, err = framework.UpdateDeploymentWithRetries(c, ns, deployOverlapping.Name, func(update *extensions.Deployment) {
update.Spec.Selector = deploy.Spec.Selector
update.Spec.Template.Labels = deploy.Spec.Template.Labels
})
Expect(err).NotTo(HaveOccurred())
// Wait for the second deployment to be synced
By("Checking the second deployment is now synced")
err = framework.WaitForDeploymentRevisionAndImage(c, ns, deployOverlapping.Name, "2", redisImage)
Expect(err).NotTo(HaveOccurred(), "The second deployment failed to update to revision 2")
}

View File

@ -3470,6 +3470,19 @@ func WaitForDeploymentRevisionAndImage(c clientset.Interface, ns, deploymentName
return nil
}
func WaitForOverlappingAnnotationMatch(c clientset.Interface, ns, deploymentName, expected string) error {
return wait.Poll(Poll, 1*time.Minute, func() (bool, error) {
deployment, err := c.Extensions().Deployments(ns).Get(deploymentName)
if err != nil {
return false, err
}
if deployment.Annotations[deploymentutil.OverlapAnnotation] == expected {
return true, nil
}
return false, nil
})
}
// CheckNewRSAnnotations check if the new RS's annotation is as expected
func CheckNewRSAnnotations(c clientset.Interface, ns, deploymentName string, expectedAnnotations map[string]string) error {
deployment, err := c.Extensions().Deployments(ns).Get(deploymentName)