|
| 1 | +package trigger |
| 2 | + |
| 3 | +import ( |
| 4 | + "time" |
| 5 | + |
| 6 | + g "github.com/onsi/ginkgo" |
| 7 | + o "github.com/onsi/gomega" |
| 8 | + |
| 9 | + appsv1 "k8s.io/api/apps/v1" |
| 10 | + "k8s.io/apimachinery/pkg/types" |
| 11 | + "k8s.io/kubernetes/test/e2e/framework" |
| 12 | + |
| 13 | + exutil "github.com/openshift/origin/test/extended/util" |
| 14 | +) |
| 15 | + |
| 16 | +var ( |
| 17 | + SyncTimeout = 30 * time.Second |
| 18 | +) |
| 19 | + |
| 20 | +var _ = g.Describe("[Feature:AnnotationTrigger] Annotation trigger", func() { |
| 21 | + defer g.GinkgoRecover() |
| 22 | + |
| 23 | + oc := exutil.NewCLI("cli-deployment", exutil.KubeConfigPath()) |
| 24 | + |
| 25 | + var ( |
| 26 | + deploymentFixture = exutil.FixturePath("testdata", "image", "deployment-with-annotation-trigger.yaml") |
| 27 | + ) |
| 28 | + |
| 29 | + g.It("reconciles after the image is overwritten", func() { |
| 30 | + namespace := oc.Namespace() |
| 31 | + |
| 32 | + g.By("creating a Deployment") |
| 33 | + deployment, err := readDeploymentFixture(deploymentFixture) |
| 34 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 35 | + o.Expect(deployment.Spec.Template.Spec.Containers).To(o.HaveLen(1)) |
| 36 | + o.Expect(deployment.Spec.Template.Spec.Containers[0].Image).To(o.Equal(" ")) |
| 37 | + |
| 38 | + deployment, err = oc.KubeClient().AppsV1().Deployments(namespace).Create(deployment) |
| 39 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 40 | + o.Expect(deployment.Spec.Template.Spec.Containers[0].Image).To(o.Equal(" ")) |
| 41 | + |
| 42 | + g.By("tagging the docker.io/library/centos:latest as test:v1 image to create ImageStream") |
| 43 | + out, err := oc.Run("tag").Args("docker.io/library/centos:latest", "test:v1").Output() |
| 44 | + framework.Logf("%s", out) |
| 45 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 46 | + |
| 47 | + g.By("waiting for the initial image to be replaced from ImageStream") |
| 48 | + deployment, err = waitForDeploymentModification(oc.KubeClient().AppsV1(), deployment.ObjectMeta, SyncTimeout, func(d *appsv1.Deployment) (bool, error) { |
| 49 | + return d.Spec.Template.Spec.Containers[0].Image != deployment.Spec.Template.Spec.Containers[0].Image, nil |
| 50 | + }) |
| 51 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 52 | + |
| 53 | + g.By("setting Deployment image repeatedly to ' ' to fight with annotation trigger") |
| 54 | + for i := 0; i < 50; i++ { |
| 55 | + deployment, err = oc.KubeClient().AppsV1().Deployments(namespace).Patch(deployment.Name, types.StrategicMergePatchType, |
| 56 | + []byte(`{"spec":{"template":{"spec":{"containers":[{"name":"test","image":" "}]}}}}`)) |
| 57 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 58 | + o.Expect(deployment.Spec.Template.Spec.Containers[0].Image).To(o.Equal(" ")) |
| 59 | + } |
| 60 | + |
| 61 | + g.By("waiting for the image to be injected by annotation trigger") |
| 62 | + o.Expect(deployment.Spec.Template.Spec.Containers[0].Image).To(o.Equal(" ")) |
| 63 | + deployment, err = waitForDeploymentModification(oc.KubeClient().AppsV1(), deployment.ObjectMeta, SyncTimeout, func(d *appsv1.Deployment) (bool, error) { |
| 64 | + return d.Spec.Template.Spec.Containers[0].Image != deployment.Spec.Template.Spec.Containers[0].Image, nil |
| 65 | + }) |
| 66 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 67 | + }) |
| 68 | +}) |
0 commit comments