|
| 1 | +/* |
| 2 | +Copyright 2025. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package sequential |
| 18 | + |
| 19 | +import ( |
| 20 | + "context" |
| 21 | + |
| 22 | + rolloutmanagerv1alpha1 "github.com/argoproj-labs/argo-rollouts-manager/api/v1alpha1" |
| 23 | + . "github.com/onsi/ginkgo/v2" |
| 24 | + . "github.com/onsi/gomega" |
| 25 | + "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture" |
| 26 | + deploymentFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/deployment" |
| 27 | + k8sFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/k8s" |
| 28 | + "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" |
| 29 | + appsv1 "k8s.io/api/apps/v1" |
| 30 | + corev1 "k8s.io/api/core/v1" |
| 31 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 32 | + "sigs.k8s.io/controller-runtime/pkg/client" |
| 33 | +) |
| 34 | + |
| 35 | +var _ = Describe("GitOps Operator Sequential E2E Tests", func() { |
| 36 | + |
| 37 | + Context("1-103_validate_rollouts_imagepullpolicy", func() { |
| 38 | + |
| 39 | + var ( |
| 40 | + ctx context.Context |
| 41 | + k8sClient client.Client |
| 42 | + ) |
| 43 | + |
| 44 | + BeforeEach(func() { |
| 45 | + |
| 46 | + fixture.EnsureSequentialCleanSlate() |
| 47 | + k8sClient, _ = utils.GetE2ETestKubeClient() |
| 48 | + ctx = context.Background() |
| 49 | + }) |
| 50 | + |
| 51 | + It("creates a cluster-scopes Argo Rollouts instance and verifies the default image pull policy", func() { |
| 52 | + |
| 53 | + By("creating simple cluster-scoped Argo Rollouts instance via RolloutManager in openshift-gitops namespace") |
| 54 | + |
| 55 | + rm := &rolloutmanagerv1alpha1.RolloutManager{ |
| 56 | + ObjectMeta: metav1.ObjectMeta{ |
| 57 | + Name: "example-rollout-manager", |
| 58 | + Namespace: "openshift-gitops", |
| 59 | + }, |
| 60 | + } |
| 61 | + Expect(k8sClient.Create(ctx, rm)).To(Succeed()) |
| 62 | + |
| 63 | + By("verifying deplyment exists") |
| 64 | + deplName := "argo-rollouts" |
| 65 | + depl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: deplName, Namespace: "openshift-gitops"}} |
| 66 | + Eventually(depl).Should(k8sFixture.ExistByName()) |
| 67 | + Eventually(depl, "4m", "5s").Should(deploymentFixture.HaveReadyReplicas(1)) |
| 68 | + |
| 69 | + By("verifying deployment has ImagePullPolicy set to default(IfNotPresent)") |
| 70 | + Eventually(deploymentFixture.VerifyDeploymentImagePullPolicy(deplName, "openshift-gitops", corev1.PullIfNotPresent, depl), "3m", "5s").Should(BeTrue(), |
| 71 | + "Deployment %s should have all containers with ImagePullPolicy set to IfNotPresent", deplName) |
| 72 | + |
| 73 | + }) |
| 74 | + |
| 75 | + It("creates a cluster-scopes Argo Rollouts instance and verifies the CR value imagePullPolicy is applied", func() { |
| 76 | + |
| 77 | + By("creating simple cluster-scoped Argo Rollouts instance via RolloutManager in openshift-gitops namespace with imagePullPolicy set to Always") |
| 78 | + |
| 79 | + rm := &rolloutmanagerv1alpha1.RolloutManager{ |
| 80 | + ObjectMeta: metav1.ObjectMeta{ |
| 81 | + Name: "example-rollout-manager", |
| 82 | + Namespace: "openshift-gitops", |
| 83 | + }, |
| 84 | + Spec: rolloutmanagerv1alpha1.RolloutManagerSpec{ |
| 85 | + ImagePullPolicy: corev1.PullAlways, |
| 86 | + }, |
| 87 | + } |
| 88 | + Expect(k8sClient.Create(ctx, rm)).To(Succeed()) |
| 89 | + |
| 90 | + By("verifying deplyment exists") |
| 91 | + deplName := "argo-rollouts" |
| 92 | + depl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: deplName, Namespace: "openshift-gitops"}} |
| 93 | + Eventually(depl).Should(k8sFixture.ExistByName()) |
| 94 | + Eventually(depl, "4m", "5s").Should(deploymentFixture.HaveReadyReplicas(1)) |
| 95 | + |
| 96 | + By("verifying deployment has ImagePullPolicy set to the CR value(Always)") |
| 97 | + Eventually(deploymentFixture.VerifyDeploymentImagePullPolicy(deplName, "openshift-gitops", corev1.PullAlways, depl), "3m", "5s").Should(BeTrue(), |
| 98 | + "Deployment %s should have all containers with ImagePullPolicy set to Always", deplName) |
| 99 | + |
| 100 | + By("updating the RolloutManager CR to set imagePullPolicy to Never") |
| 101 | + patch := client.MergeFrom(rm.DeepCopy()) |
| 102 | + rm.Spec.ImagePullPolicy = corev1.PullNever |
| 103 | + Expect(k8sClient.Patch(ctx, rm, patch)).To(Succeed()) |
| 104 | + |
| 105 | + By("verifying deployment has ImagePullPolicy set to the CR value(Never)") |
| 106 | + Eventually(deploymentFixture.VerifyDeploymentImagePullPolicy(deplName, "openshift-gitops", corev1.PullNever, depl), "3m", "5s").Should(BeTrue(), |
| 107 | + "Deployment %s should have all containers with ImagePullPolicy set to Never", deplName) |
| 108 | + |
| 109 | + By("Removing the imagePullPolicy from the CR and check if the deployment has the imagePullPolicy set to default(IfNotPresent)") |
| 110 | + rm.Spec.ImagePullPolicy = "" |
| 111 | + Expect(k8sClient.Patch(ctx, rm, patch)).To(Succeed()) |
| 112 | + |
| 113 | + By("verifying deployment has ImagePullPolicy set to default(IfNotPresent)") |
| 114 | + Eventually(deploymentFixture.VerifyDeploymentImagePullPolicy(deplName, "openshift-gitops", corev1.PullIfNotPresent, depl), "3m", "5s").Should(BeTrue(), |
| 115 | + "Deployment %s should have all containers with ImagePullPolicy set to IfNotPresent", deplName) |
| 116 | + }) |
| 117 | + |
| 118 | + It("creates a cluster-scopes Argo Rollouts instance and verifies subscription image pull policy is applied", func() { |
| 119 | + if fixture.EnvLocalRun() { |
| 120 | + Skip("This test does not support local run, as when the controller is running locally there is no env var to modify") |
| 121 | + return |
| 122 | + } |
| 123 | + |
| 124 | + By("setting the IMAGE_PULL_POLICY environment variable to Always") |
| 125 | + fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Always") |
| 126 | + defer func() { |
| 127 | + By("removing IMAGE_PULL_POLICY environment variable to restore default behavior") |
| 128 | + fixture.RestoreSubcriptionToDefault() |
| 129 | + }() |
| 130 | + |
| 131 | + By("creating simple cluster-scoped Argo Rollouts instance via RolloutManager in openshift-gitops namespace") |
| 132 | + rm := &rolloutmanagerv1alpha1.RolloutManager{ |
| 133 | + ObjectMeta: metav1.ObjectMeta{ |
| 134 | + Name: "example-rollout-manager", |
| 135 | + Namespace: "openshift-gitops", |
| 136 | + }, |
| 137 | + } |
| 138 | + Expect(k8sClient.Create(ctx, rm)).To(Succeed()) |
| 139 | + |
| 140 | + By("verifying deplyment exists") |
| 141 | + deplName := "argo-rollouts" |
| 142 | + depl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: deplName, Namespace: "openshift-gitops"}} |
| 143 | + Eventually(depl).Should(k8sFixture.ExistByName()) |
| 144 | + Eventually(depl, "4m", "5s").Should(deploymentFixture.HaveReadyReplicas(1)) |
| 145 | + |
| 146 | + By("verifying deployment has ImagePullPolicy set to Always") |
| 147 | + Eventually(deploymentFixture.VerifyDeploymentImagePullPolicy(deplName, "openshift-gitops", corev1.PullAlways, depl), "3m", "5s").Should(BeTrue(), |
| 148 | + "Deployment %s should have all containers with ImagePullPolicy set to Always", deplName) |
| 149 | + |
| 150 | + By("changing the subscription image pull policy to Never") |
| 151 | + fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Never") |
| 152 | + |
| 153 | + By("verifying deployment has ImagePullPolicy set to Never") |
| 154 | + Eventually(deploymentFixture.VerifyDeploymentImagePullPolicy(deplName, "openshift-gitops", corev1.PullNever, depl), "3m", "5s").Should(BeTrue(), |
| 155 | + "Deployment %s should have all containers with ImagePullPolicy set to Never", deplName) |
| 156 | + |
| 157 | + By("changing the subscription image pull policy to IfNotPresent") |
| 158 | + fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "IfNotPresent") |
| 159 | + |
| 160 | + By("verifying deployment has ImagePullPolicy set to IfNotPresent") |
| 161 | + Eventually(deploymentFixture.VerifyDeploymentImagePullPolicy(deplName, "openshift-gitops", corev1.PullIfNotPresent, depl), "3m", "5s").Should(BeTrue(), |
| 162 | + "Deployment %s should have all containers with ImagePullPolicy set to IfNotPresent", deplName) |
| 163 | + |
| 164 | + By("setting imagePullPolicy in CR and verify if the deployment has the imagePullPolicy set to the CR value") |
| 165 | + patch := client.MergeFrom(rm.DeepCopy()) |
| 166 | + rm.Spec.ImagePullPolicy = corev1.PullAlways |
| 167 | + Expect(k8sClient.Patch(ctx, rm, patch)).To(Succeed()) |
| 168 | + Eventually(deploymentFixture.VerifyDeploymentImagePullPolicy(deplName, "openshift-gitops", corev1.PullAlways, depl), "3m", "5s").Should(BeTrue(), |
| 169 | + "Deployment %s should have all containers with ImagePullPolicy set to Always", deplName) |
| 170 | + |
| 171 | + }) |
| 172 | + |
| 173 | + }) |
| 174 | + |
| 175 | +}) |
0 commit comments