From 474ad39dfebce7f58387d5932b264f0590192037 Mon Sep 17 00:00:00 2001 From: Alka Kumari Date: Fri, 24 Oct 2025 19:54:14 +0530 Subject: [PATCH 01/14] added imagePullPolicy config for gitops-service Signed-off-by: Alka Kumari --- api/v1alpha1/gitopsservice_types.go | 3 + common/common.go | 32 ++++++- common/common_test.go | 87 +++++++++++++++++++ ...pipelines.openshift.io_gitopsservices.yaml | 8 ++ controllers/consoleplugin.go | 10 +-- controllers/consoleplugin_test.go | 2 +- controllers/gitopsservice_controller.go | 13 ++- controllers/gitopsservice_controller_test.go | 4 +- 8 files changed, 146 insertions(+), 13 deletions(-) create mode 100644 common/common_test.go diff --git a/api/v1alpha1/gitopsservice_types.go b/api/v1alpha1/gitopsservice_types.go index 7c76b65ec..46d0412ed 100644 --- a/api/v1alpha1/gitopsservice_types.go +++ b/api/v1alpha1/gitopsservice_types.go @@ -34,6 +34,9 @@ type GitopsServiceSpec struct { NodeSelector map[string]string `json:"nodeSelector,omitempty"` // ConsolePlugin defines the Resource configuration for the Console Plugin components ConsolePlugin *ConsolePluginStruct `json:"consolePlugin,omitempty"` + // ImagePullPolicy defines the image pull policy for GitOps workloads + // +kubebuilder:validation:Enum=Always;IfNotPresent;Never + ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"` } // ConsolePluginStruct defines the resource configuration for the Console Plugin components diff --git a/common/common.go b/common/common.go index 4599db6c0..7e630b5c0 100644 --- a/common/common.go +++ b/common/common.go @@ -16,7 +16,11 @@ limitations under the License. package common -import "os" +import ( + "os" + + corev1 "k8s.io/api/core/v1" +) const ( // ArgoCDInstanceName is the default Argo CD instance name @@ -33,6 +37,8 @@ const ( DefaultConsoleVersion = "v0.1.0" // Default console plugin installation OCP version DefaultDynamicPluginStartOCPVersion = "4.15.0" + // ImagePullPolicyEnvVar is the environment variable for configuring image pull policy + ImagePullPolicy = "IMAGE_PULL_POLICY" ) // InfraNodeSelector returns openshift label for infrastructure nodes @@ -48,3 +54,27 @@ func StringFromEnv(env string, defaultValue string) string { } return defaultValue } + +// GetImagePullPolicy returns the image pull policy based on precedence: +// 1. CR-level override (highest precedence) +// 2. Environment variable (middle precedence) +// 3. Default fallback (lowest precedence - IfNotPresent) +func GetImagePullPolicy(crImagePullPolicy corev1.PullPolicy) corev1.PullPolicy { + // If CR specifies a policy, use it (highest precedence) + if crImagePullPolicy != "" { + return crImagePullPolicy + } + + // Check environment variable (middle precedence) + envPolicy := os.Getenv(ImagePullPolicy) + switch envPolicy { + case "Always": + return corev1.PullAlways + case "IfNotPresent": + return corev1.PullIfNotPresent + case "Never": + return corev1.PullNever + default: + return corev1.PullPolicy("IfNotPresent") + } +} diff --git a/common/common_test.go b/common/common_test.go new file mode 100644 index 000000000..2ce897ebe --- /dev/null +++ b/common/common_test.go @@ -0,0 +1,87 @@ +/* +Copyright 2021. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package common + +import ( + "os" + "testing" + + corev1 "k8s.io/api/core/v1" +) + +func TestGetImagePullPolicy(t *testing.T) { + tests := []struct { + name string + crPolicy corev1.PullPolicy + envValue string + expectedPolicy corev1.PullPolicy + }{ + { + name: "CR policy takes precedence", + crPolicy: corev1.PullIfNotPresent, + envValue: "Never", + expectedPolicy: corev1.PullIfNotPresent, + }, + { + name: "Environment variable used when CR policy empty", + crPolicy: "", + envValue: "IfNotPresent", + expectedPolicy: corev1.PullIfNotPresent, + }, + { + name: "Environment variable Never", + crPolicy: "", + envValue: "Never", + expectedPolicy: corev1.PullNever, + }, + { + name: "Environment variable Always", + crPolicy: "", + envValue: "Always", + expectedPolicy: corev1.PullAlways, + }, + { + name: "Default to IfNotPresent when no config", + crPolicy: "", + envValue: "", + expectedPolicy: corev1.PullIfNotPresent, + }, + { + name: "Invalid env value defaults to IfNotPresent", + crPolicy: "", + envValue: "InvalidValue", + expectedPolicy: corev1.PullIfNotPresent, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // Set environment variable + if tt.envValue != "" { + os.Setenv(ImagePullPolicy, tt.envValue) + } else { + os.Unsetenv(ImagePullPolicy) + } + defer os.Unsetenv(ImagePullPolicy) + + result := GetImagePullPolicy(tt.crPolicy) + if result != tt.expectedPolicy { + t.Errorf("GetImagePullPolicy() = %v, want %v", result, tt.expectedPolicy) + } + }) + } +} diff --git a/config/crd/bases/pipelines.openshift.io_gitopsservices.yaml b/config/crd/bases/pipelines.openshift.io_gitopsservices.yaml index 1dd2f77a9..6589958ce 100644 --- a/config/crd/bases/pipelines.openshift.io_gitopsservices.yaml +++ b/config/crd/bases/pipelines.openshift.io_gitopsservices.yaml @@ -174,6 +174,14 @@ spec: type: object type: object type: object + imagePullPolicy: + description: ImagePullPolicy defines the image pull policy for GitOps + workloads + enum: + - Always + - IfNotPresent + - Never + type: string nodeSelector: additionalProperties: type: string diff --git a/controllers/consoleplugin.go b/controllers/consoleplugin.go index 4ad49ad88..e01b405e0 100644 --- a/controllers/consoleplugin.go +++ b/controllers/consoleplugin.go @@ -44,7 +44,7 @@ const ( kubeAppLabelName = "app.kubernetes.io/name" ) -func getPluginPodSpec() corev1.PodSpec { +func getPluginPodSpec(crImagePullPolicy corev1.PullPolicy) corev1.PodSpec { consolePluginImage := os.Getenv(pluginImageEnv) if consolePluginImage == "" { image := common.DefaultConsoleImage @@ -58,7 +58,7 @@ func getPluginPodSpec() corev1.PodSpec { Env: util.ProxyEnvVars(), Name: gitopsPluginName, Image: consolePluginImage, - ImagePullPolicy: corev1.PullAlways, + ImagePullPolicy: common.GetImagePullPolicy(crImagePullPolicy), Ports: []corev1.ContainerPort{ { Name: "http", @@ -133,8 +133,8 @@ func getPluginPodSpec() corev1.PodSpec { return podSpec } -func pluginDeployment() *appsv1.Deployment { - podSpec := getPluginPodSpec() +func pluginDeployment(crImagePullPolicy corev1.PullPolicy) *appsv1.Deployment { + podSpec := getPluginPodSpec(crImagePullPolicy) template := corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ @@ -269,7 +269,7 @@ func pluginConfigMap() *corev1.ConfigMap { func (r *ReconcileGitopsService) reconcileDeployment(cr *pipelinesv1alpha1.GitopsService, request reconcile.Request) (reconcile.Result, error) { reqLogger := logs.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name) - newPluginDeployment := pluginDeployment() + newPluginDeployment := pluginDeployment(cr.Spec.ImagePullPolicy) if err := controllerutil.SetControllerReference(cr, newPluginDeployment, r.Scheme); err != nil { return reconcile.Result{}, err diff --git a/controllers/consoleplugin_test.go b/controllers/consoleplugin_test.go index 872e3d0c8..267a907f4 100644 --- a/controllers/consoleplugin_test.go +++ b/controllers/consoleplugin_test.go @@ -625,7 +625,7 @@ func TestPlugin_reconcileDeployment_changedContainers(t *testing.T) { consoleImage := common.DefaultConsoleImage + ":" + common.DefaultConsoleVersion assert.Equal(t, deployment.Spec.Template.Spec.Containers[0].Name, "gitops-plugin") assert.Equal(t, deployment.Spec.Template.Spec.Containers[0].Image, consoleImage) - assert.Equal(t, deployment.Spec.Template.Spec.Containers[0].ImagePullPolicy, corev1.PullAlways) + assert.Equal(t, deployment.Spec.Template.Spec.Containers[0].ImagePullPolicy, corev1.PullIfNotPresent) assert.Equal(t, deployment.Spec.Template.Spec.Containers[0].Ports[0].Name, "http") assert.Equal(t, deployment.Spec.Template.Spec.Containers[0].Ports[0].Protocol, corev1.ProtocolTCP) assert.Equal(t, deployment.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort, int32(9001)) diff --git a/controllers/gitopsservice_controller.go b/controllers/gitopsservice_controller.go index 119e8364f..639b08e31 100644 --- a/controllers/gitopsservice_controller.go +++ b/controllers/gitopsservice_controller.go @@ -607,7 +607,7 @@ func (r *ReconcileGitopsService) reconcileBackend(gitopsserviceNamespacedName ty // Define a new backend Deployment { - deploymentObj := newBackendDeployment(gitopsserviceNamespacedName) + deploymentObj := newBackendDeployment(gitopsserviceNamespacedName, instance.Spec.ImagePullPolicy) // Add SeccompProfile based on cluster version util.AddSeccompProfileForOpenShift(r.Client, &deploymentObj.Spec.Template.Spec) @@ -654,6 +654,10 @@ func (r *ReconcileGitopsService) reconcileBackend(gitopsserviceNamespacedName ty found.Spec.Template.Spec.Containers[0].Env = deploymentObj.Spec.Template.Spec.Containers[0].Env changed = true } + if !reflect.DeepEqual(found.Spec.Template.Spec.Containers[0].ImagePullPolicy, deploymentObj.Spec.Template.Spec.Containers[0].ImagePullPolicy) { + found.Spec.Template.Spec.Containers[0].ImagePullPolicy = deploymentObj.Spec.Template.Spec.Containers[0].ImagePullPolicy + changed = true + } if !reflect.DeepEqual(found.Spec.Template.Spec.Containers[0].Resources, deploymentObj.Spec.Template.Spec.Containers[0].Resources) { found.Spec.Template.Spec.Containers[0].Resources = deploymentObj.Spec.Template.Spec.Containers[0].Resources changed = true @@ -744,7 +748,7 @@ func objectMeta(resourceName string, namespace string, opts ...func(*metav1.Obje return objectMeta } -func newBackendDeployment(ns types.NamespacedName) *appsv1.Deployment { +func newBackendDeployment(ns types.NamespacedName, crImagePullPolicy corev1.PullPolicy) *appsv1.Deployment { image := os.Getenv(backendImageEnvName) if image == "" { image = backendImage @@ -752,8 +756,9 @@ func newBackendDeployment(ns types.NamespacedName) *appsv1.Deployment { podSpec := corev1.PodSpec{ Containers: []corev1.Container{ { - Name: ns.Name, - Image: image, + Name: ns.Name, + Image: image, + ImagePullPolicy: common.GetImagePullPolicy(crImagePullPolicy), Ports: []corev1.ContainerPort{ { Name: "http", diff --git a/controllers/gitopsservice_controller_test.go b/controllers/gitopsservice_controller_test.go index f1cb37426..ddfad2bf3 100644 --- a/controllers/gitopsservice_controller_test.go +++ b/controllers/gitopsservice_controller_test.go @@ -54,7 +54,7 @@ func TestImageFromEnvVariable(t *testing.T) { image := "quay.io/org/test" t.Setenv(backendImageEnvName, image) - deployment := newBackendDeployment(ns) + deployment := newBackendDeployment(ns, corev1.PullPolicy(corev1.PullIfNotPresent)) got := deployment.Spec.Template.Spec.Containers[0].Image if got != image { @@ -62,7 +62,7 @@ func TestImageFromEnvVariable(t *testing.T) { } }) t.Run("env variable for image not found", func(t *testing.T) { - deployment := newBackendDeployment(ns) + deployment := newBackendDeployment(ns, corev1.PullPolicy(corev1.PullIfNotPresent)) got := deployment.Spec.Template.Spec.Containers[0].Image if got != backendImage { From a1965bab4e1c331fb848073eaf0e3ca8527ed503 Mon Sep 17 00:00:00 2001 From: Alka Kumari Date: Fri, 24 Oct 2025 23:17:21 +0530 Subject: [PATCH 02/14] added ginkgo test cases for imagePullPolicy feature in Gitops Servicee Signed-off-by: Alka Kumari --- ...ate_imagepullpolicy_console_plugin_test.go | 210 ++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100644 test/openshift/e2e/ginkgo/parallel/1-115_validate_imagepullpolicy_console_plugin_test.go diff --git a/test/openshift/e2e/ginkgo/parallel/1-115_validate_imagepullpolicy_console_plugin_test.go b/test/openshift/e2e/ginkgo/parallel/1-115_validate_imagepullpolicy_console_plugin_test.go new file mode 100644 index 000000000..d4916ffcf --- /dev/null +++ b/test/openshift/e2e/ginkgo/parallel/1-115_validate_imagepullpolicy_console_plugin_test.go @@ -0,0 +1,210 @@ +/* +Copyright 2025. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package parallel + +import ( + "context" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + gitopsoperatorv1alpha1 "github.com/redhat-developer/gitops-operator/api/v1alpha1" + "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture" + gitopsserviceFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/gitopsservice" + k8sFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/k8s" + "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +var _ = Describe("GitOps Operator Parallel E2E Tests", func() { + + Context("1-115-validate_imagepullpolicy_gitopsservice", func() { + + var ( + ctx context.Context + k8sClient client.Client + ) + + BeforeEach(func() { + fixture.EnsureParallelCleanSlate() + k8sClient, _ = utils.GetE2ETestKubeClient() + ctx = context.Background() + }) + + It("validates ImagePullPolicy propagation from GitOpsService CR to console plugin and backend deployments", func() { + + By("getting the cluster-scoped GitOpsService CR") + gitopsService := &gitopsoperatorv1alpha1.GitopsService{ + ObjectMeta: metav1.ObjectMeta{Name: "cluster"}, + } + Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(gitopsService), gitopsService)).To(Succeed()) + + By("setting ImagePullPolicy to Always in GitOpsService CR") + gitopsserviceFixture.Update(gitopsService, func(gs *gitopsoperatorv1alpha1.GitopsService) { + gs.Spec.ImagePullPolicy = corev1.PullAlways + }) + + By("verifying console plugin deployment has ImagePullPolicy set to Always") + pluginDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "gitops-plugin", Namespace: "openshift-gitops"}} + Eventually(pluginDepl).Should(k8sFixture.ExistByName()) + Eventually(func() bool { + err := k8sClient.Get(ctx, client.ObjectKeyFromObject(pluginDepl), pluginDepl) + if err != nil { + return false + } + for _, container := range pluginDepl.Spec.Template.Spec.Containers { + if container.ImagePullPolicy != corev1.PullAlways { + return false + } + } + return true + }, "3m", "5s").Should(BeTrue()) + //Eventually(pluginDepl, "3m", "5s").Should(deploymentFixture.HaveContainerImagePullPolicy(0, corev1.PullAlways)) + + By("verifying backend deployment has ImagePullPolicy set to Always") + clusterDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: "openshift-gitops"}} + Eventually(clusterDepl).Should(k8sFixture.ExistByName()) + Eventually(func() bool { + err := k8sClient.Get(ctx, client.ObjectKeyFromObject(clusterDepl), clusterDepl) + if err != nil { + return false + } + for _, container := range clusterDepl.Spec.Template.Spec.Containers { + if container.ImagePullPolicy != corev1.PullAlways { + return false + } + } + return true + }, "3m", "5s").Should(BeTrue()) + //Eventually(clusterDepl, "3m", "5s").Should(deploymentFixture.HaveContainerImagePullPolicy(0, corev1.PullAlways)) + + By("setting ImagePullPolicy to Never in GitOpsService CR") + gitopsserviceFixture.Update(gitopsService, func(gs *gitopsoperatorv1alpha1.GitopsService) { + gs.Spec.ImagePullPolicy = corev1.PullNever + }) + + By("verifying console plugin deployment has ImagePullPolicy set to Never") + Eventually(func() bool { + err := k8sClient.Get(ctx, client.ObjectKeyFromObject(pluginDepl), pluginDepl) + if err != nil { + return false + } + for _, container := range pluginDepl.Spec.Template.Spec.Containers { + if container.ImagePullPolicy != corev1.PullNever { + return false + } + } + return true + }, "3m", "5s").Should(BeTrue()) + //Eventually(pluginDepl, "3m", "5s").Should(deploymentFixture.HaveContainerImagePullPolicy(0, corev1.PullNever)) + + By("verifying backend deployment has ImagePullPolicy set to Never") + Eventually(func() bool { + err := k8sClient.Get(ctx, client.ObjectKeyFromObject(clusterDepl), clusterDepl) + if err != nil { + return false + } + for _, container := range clusterDepl.Spec.Template.Spec.Containers { + if container.ImagePullPolicy != corev1.PullNever { + return false + } + } + return true + }, "3m", "5s").Should(BeTrue()) + //Eventually(clusterDepl, "3m", "5s").Should(deploymentFixture.HaveContainerImagePullPolicy(0, corev1.PullNever)) + + By("setting ImagePullPolicy to IfNotPresent in GitOpsService CR") + gitopsserviceFixture.Update(gitopsService, func(gs *gitopsoperatorv1alpha1.GitopsService) { + gs.Spec.ImagePullPolicy = corev1.PullIfNotPresent + }) + + By("verifying console plugin deployment has ImagePullPolicy set to IfNotPresent") + Eventually(func() bool { + err := k8sClient.Get(ctx, client.ObjectKeyFromObject(pluginDepl), pluginDepl) + if err != nil { + return false + } + for _, container := range pluginDepl.Spec.Template.Spec.Containers { + if container.ImagePullPolicy != corev1.PullIfNotPresent { + return false + } + } + return true + }, "3m", "5s").Should(BeTrue()) + //Eventually(pluginDepl, "3m", "5s").Should(deploymentFixture.HaveContainerImagePullPolicy(0, corev1.PullIfNotPresent)) + + By("verifying backend deployment has ImagePullPolicy set to IfNotPresent") + Eventually(func() bool { + err := k8sClient.Get(ctx, client.ObjectKeyFromObject(clusterDepl), clusterDepl) + if err != nil { + return false + } + for _, container := range clusterDepl.Spec.Template.Spec.Containers { + if container.ImagePullPolicy != corev1.PullIfNotPresent { + return false + } + } + return true + }, "3m", "5s").Should(BeTrue()) + //Eventually(clusterDepl, "3m", "5s").Should(deploymentFixture.HaveContainerImagePullPolicy(0, corev1.PullIfNotPresent)) + }) + + It("validates default ImagePullPolicy when not set in CR", func() { + By("getting the GitOpsService CR") + gitopsService := &gitopsoperatorv1alpha1.GitopsService{ + ObjectMeta: metav1.ObjectMeta{Name: "cluster"}, + } + Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(gitopsService), gitopsService)).To(Succeed()) + + By("verifying backend deployment defaults to IfNotPresent") + clusterDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: "openshift-gitops"}} + Eventually(clusterDepl).Should(k8sFixture.ExistByName()) + Eventually(func() bool { + err := k8sClient.Get(ctx, client.ObjectKeyFromObject(clusterDepl), clusterDepl) + if err != nil { + return false + } + for _, container := range clusterDepl.Spec.Template.Spec.Containers { + if container.ImagePullPolicy != corev1.PullIfNotPresent { + return false + } + } + return true + }, "3m", "5s").Should(BeTrue()) + //Eventually(clusterDepl.Spec.Template.Spec.Containers[0].ImagePullPolicy == corev1.PullIfNotPresent, "60s", "3s").Should(BeTrue()) + //deploymentFixture.HaveContainerImagePullPolicy(0, corev1.PullIfNotPresent)) + + By("verifying plugin deployment defaults to IfNotPresent") + pluginDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "gitops-plugin", Namespace: "openshift-gitops"}} + Eventually(pluginDepl).Should(k8sFixture.ExistByName()) + Eventually(func() bool { + err := k8sClient.Get(ctx, client.ObjectKeyFromObject(pluginDepl), pluginDepl) + if err != nil { + return false + } + for _, container := range pluginDepl.Spec.Template.Spec.Containers { + if container.ImagePullPolicy != corev1.PullIfNotPresent { + return false + } + } + return true + }, "3m", "5s").Should(BeTrue()) + }) + }) +}) From 1c0817897d36ee3a5b16e8fe67f44ea5b75606bf Mon Sep 17 00:00:00 2001 From: Alka Kumari Date: Fri, 24 Oct 2025 23:25:49 +0530 Subject: [PATCH 03/14] updated the manifest files Signed-off-by: Alka Kumari --- .../manifests/pipelines.openshift.io_gitopsservices.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bundle/manifests/pipelines.openshift.io_gitopsservices.yaml b/bundle/manifests/pipelines.openshift.io_gitopsservices.yaml index 792cc853b..f790e517f 100644 --- a/bundle/manifests/pipelines.openshift.io_gitopsservices.yaml +++ b/bundle/manifests/pipelines.openshift.io_gitopsservices.yaml @@ -174,6 +174,14 @@ spec: type: object type: object type: object + imagePullPolicy: + description: ImagePullPolicy defines the image pull policy for GitOps + workloads + enum: + - Always + - IfNotPresent + - Never + type: string nodeSelector: additionalProperties: type: string From 72d17cae269717dc786c77661e6b1e9794cac63d Mon Sep 17 00:00:00 2001 From: Alka Kumari Date: Wed, 29 Oct 2025 16:30:51 +0530 Subject: [PATCH 04/14] added ginkgo test case for subscription env variable for imagePullPolicy Signed-off-by: Alka Kumari --- ...ate_imagepullpolicy_console_plugin_test.go | 141 +++++++++++++++++- 1 file changed, 134 insertions(+), 7 deletions(-) diff --git a/test/openshift/e2e/ginkgo/parallel/1-115_validate_imagepullpolicy_console_plugin_test.go b/test/openshift/e2e/ginkgo/parallel/1-115_validate_imagepullpolicy_console_plugin_test.go index d4916ffcf..a282466f0 100644 --- a/test/openshift/e2e/ginkgo/parallel/1-115_validate_imagepullpolicy_console_plugin_test.go +++ b/test/openshift/e2e/ginkgo/parallel/1-115_validate_imagepullpolicy_console_plugin_test.go @@ -23,6 +23,7 @@ import ( . "github.com/onsi/gomega" gitopsoperatorv1alpha1 "github.com/redhat-developer/gitops-operator/api/v1alpha1" "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture" + argocdFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/argocd" gitopsserviceFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/gitopsservice" k8sFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/k8s" "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" @@ -48,10 +49,15 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { }) It("validates ImagePullPolicy propagation from GitOpsService CR to console plugin and backend deployments", func() { + By("verifying Argo CD in openshift-gitops exists and is available") + argoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD() + Expect(err).ToNot(HaveOccurred()) + + Eventually(argoCD, "5m", "5s").Should(argocdFixture.BeAvailable()) By("getting the cluster-scoped GitOpsService CR") gitopsService := &gitopsoperatorv1alpha1.GitopsService{ - ObjectMeta: metav1.ObjectMeta{Name: "cluster"}, + ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: argoCD.Namespace}, } Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(gitopsService), gitopsService)).To(Succeed()) @@ -61,7 +67,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { }) By("verifying console plugin deployment has ImagePullPolicy set to Always") - pluginDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "gitops-plugin", Namespace: "openshift-gitops"}} + pluginDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "gitops-plugin", Namespace: argoCD.Namespace}} Eventually(pluginDepl).Should(k8sFixture.ExistByName()) Eventually(func() bool { err := k8sClient.Get(ctx, client.ObjectKeyFromObject(pluginDepl), pluginDepl) @@ -75,10 +81,9 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { } return true }, "3m", "5s").Should(BeTrue()) - //Eventually(pluginDepl, "3m", "5s").Should(deploymentFixture.HaveContainerImagePullPolicy(0, corev1.PullAlways)) By("verifying backend deployment has ImagePullPolicy set to Always") - clusterDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: "openshift-gitops"}} + clusterDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: argoCD.Namespace}} Eventually(clusterDepl).Should(k8sFixture.ExistByName()) Eventually(func() bool { err := k8sClient.Get(ctx, client.ObjectKeyFromObject(clusterDepl), clusterDepl) @@ -92,7 +97,6 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { } return true }, "3m", "5s").Should(BeTrue()) - //Eventually(clusterDepl, "3m", "5s").Should(deploymentFixture.HaveContainerImagePullPolicy(0, corev1.PullAlways)) By("setting ImagePullPolicy to Never in GitOpsService CR") gitopsserviceFixture.Update(gitopsService, func(gs *gitopsoperatorv1alpha1.GitopsService) { @@ -166,6 +170,11 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { }) It("validates default ImagePullPolicy when not set in CR", func() { + By("verifying Argo CD in openshift-gitops exists and is available") + argoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD() + Expect(err).ToNot(HaveOccurred()) + + Eventually(argoCD, "5m", "5s").Should(argocdFixture.BeAvailable()) By("getting the GitOpsService CR") gitopsService := &gitopsoperatorv1alpha1.GitopsService{ ObjectMeta: metav1.ObjectMeta{Name: "cluster"}, @@ -173,7 +182,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(gitopsService), gitopsService)).To(Succeed()) By("verifying backend deployment defaults to IfNotPresent") - clusterDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: "openshift-gitops"}} + clusterDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: argoCD.Namespace}} Eventually(clusterDepl).Should(k8sFixture.ExistByName()) Eventually(func() bool { err := k8sClient.Get(ctx, client.ObjectKeyFromObject(clusterDepl), clusterDepl) @@ -191,8 +200,126 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { //deploymentFixture.HaveContainerImagePullPolicy(0, corev1.PullIfNotPresent)) By("verifying plugin deployment defaults to IfNotPresent") - pluginDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "gitops-plugin", Namespace: "openshift-gitops"}} + pluginDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "gitops-plugin", Namespace: argoCD.Namespace}} + Eventually(pluginDepl).Should(k8sFixture.ExistByName()) + Eventually(func() bool { + err := k8sClient.Get(ctx, client.ObjectKeyFromObject(pluginDepl), pluginDepl) + if err != nil { + return false + } + for _, container := range pluginDepl.Spec.Template.Spec.Containers { + if container.ImagePullPolicy != corev1.PullIfNotPresent { + return false + } + } + return true + }, "3m", "5s").Should(BeTrue()) + }) + + It("validates ImagePullPolicy set as env variable in subscription", func() { + if fixture.EnvLocalRun() { + Skip("This test does not support local run, as when the controller is running locally there is no env var to modify") + return + } + By("adding image pull policy env variable to IMAGE_PULL_POLICY in Subscription") + + fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Always") + + By("verifying Argo CD in openshift-gitops exists and is available") + argoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD() + Expect(err).ToNot(HaveOccurred()) + + Eventually(argoCD, "5m", "5s").Should(argocdFixture.BeAvailable()) + + By("getting the GitOpsService CR") + gitopsService := &gitopsoperatorv1alpha1.GitopsService{ + ObjectMeta: metav1.ObjectMeta{Name: "cluster"}, + } + Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(gitopsService), gitopsService)).To(Succeed()) + + By("verifying backend deployment has ImagePullPolicy set based on env variable") + clusterDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: argoCD.Namespace}} + Eventually(clusterDepl).Should(k8sFixture.ExistByName()) + Eventually(func() bool { + err := k8sClient.Get(ctx, client.ObjectKeyFromObject(clusterDepl), clusterDepl) + if err != nil { + return false + } + for _, container := range clusterDepl.Spec.Template.Spec.Containers { + if container.ImagePullPolicy != corev1.PullAlways { + return false + } + } + return true + }, "3m", "5s").Should(BeTrue()) + + By("verifying plugin deployment has ImagePullPolicy set based on env variable") + pluginDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "gitops-plugin", Namespace: argoCD.Namespace}} Eventually(pluginDepl).Should(k8sFixture.ExistByName()) + Eventually(func() bool { + err := k8sClient.Get(ctx, client.ObjectKeyFromObject(pluginDepl), pluginDepl) + if err != nil { + return false + } + for _, container := range pluginDepl.Spec.Template.Spec.Containers { + if container.ImagePullPolicy != corev1.PullAlways { + return false + } + } + return true + }, "3m", "5s").Should(BeTrue()) + + By("updating image pull policy env variable to Never") + + fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Never") + + By("verifying backend deployment has ImagePullPolicy changed based on env variable") + Eventually(func() bool { + err := k8sClient.Get(ctx, client.ObjectKeyFromObject(clusterDepl), clusterDepl) + if err != nil { + return false + } + for _, container := range clusterDepl.Spec.Template.Spec.Containers { + if container.ImagePullPolicy != corev1.PullNever { + return false + } + } + return true + }, "3m", "5s").Should(BeTrue()) + + By("verifying plugin deployment has ImagePullPolicy changed based on env variable") + + Eventually(func() bool { + err := k8sClient.Get(ctx, client.ObjectKeyFromObject(pluginDepl), pluginDepl) + if err != nil { + return false + } + for _, container := range pluginDepl.Spec.Template.Spec.Containers { + if container.ImagePullPolicy != corev1.PullNever { + return false + } + } + return true + }, "3m", "5s").Should(BeTrue()) + + fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "IfNotPresent") + + By("verifying backend deployment has ImagePullPolicy changed based on env variable") + Eventually(func() bool { + err := k8sClient.Get(ctx, client.ObjectKeyFromObject(clusterDepl), clusterDepl) + if err != nil { + return false + } + for _, container := range clusterDepl.Spec.Template.Spec.Containers { + if container.ImagePullPolicy != corev1.PullIfNotPresent { + return false + } + } + return true + }, "3m", "5s").Should(BeTrue()) + + By("verifying plugin deployment has ImagePullPolicy changed based on env variable") + Eventually(func() bool { err := k8sClient.Get(ctx, client.ObjectKeyFromObject(pluginDepl), pluginDepl) if err != nil { From fc9fbe4bf120f5b6fe975d28f85403421c2a31cc Mon Sep 17 00:00:00 2001 From: Alka Kumari Date: Thu, 30 Oct 2025 11:21:46 +0530 Subject: [PATCH 05/14] moved imagepullpolicy test for backend deployment and plugin deployment to sequential folder Signed-off-by: Alka Kumari --- ...date_imagepullpolicy_console_plugin_test.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) rename test/openshift/e2e/ginkgo/{parallel => sequential}/1-115_validate_imagepullpolicy_console_plugin_test.go (92%) diff --git a/test/openshift/e2e/ginkgo/parallel/1-115_validate_imagepullpolicy_console_plugin_test.go b/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go similarity index 92% rename from test/openshift/e2e/ginkgo/parallel/1-115_validate_imagepullpolicy_console_plugin_test.go rename to test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go index a282466f0..7336361f4 100644 --- a/test/openshift/e2e/ginkgo/parallel/1-115_validate_imagepullpolicy_console_plugin_test.go +++ b/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package parallel +package sequential import ( "context" @@ -53,7 +53,8 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { argoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD() Expect(err).ToNot(HaveOccurred()) - Eventually(argoCD, "5m", "5s").Should(argocdFixture.BeAvailable()) + Eventually(argoCD).Should(k8sFixture.ExistByName()) + Eventually(argoCD).Should(argocdFixture.BeAvailable()) By("getting the cluster-scoped GitOpsService CR") gitopsService := &gitopsoperatorv1alpha1.GitopsService{ @@ -116,7 +117,6 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { } return true }, "3m", "5s").Should(BeTrue()) - //Eventually(pluginDepl, "3m", "5s").Should(deploymentFixture.HaveContainerImagePullPolicy(0, corev1.PullNever)) By("verifying backend deployment has ImagePullPolicy set to Never") Eventually(func() bool { @@ -131,7 +131,6 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { } return true }, "3m", "5s").Should(BeTrue()) - //Eventually(clusterDepl, "3m", "5s").Should(deploymentFixture.HaveContainerImagePullPolicy(0, corev1.PullNever)) By("setting ImagePullPolicy to IfNotPresent in GitOpsService CR") gitopsserviceFixture.Update(gitopsService, func(gs *gitopsoperatorv1alpha1.GitopsService) { @@ -151,7 +150,6 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { } return true }, "3m", "5s").Should(BeTrue()) - //Eventually(pluginDepl, "3m", "5s").Should(deploymentFixture.HaveContainerImagePullPolicy(0, corev1.PullIfNotPresent)) By("verifying backend deployment has ImagePullPolicy set to IfNotPresent") Eventually(func() bool { @@ -166,7 +164,6 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { } return true }, "3m", "5s").Should(BeTrue()) - //Eventually(clusterDepl, "3m", "5s").Should(deploymentFixture.HaveContainerImagePullPolicy(0, corev1.PullIfNotPresent)) }) It("validates default ImagePullPolicy when not set in CR", func() { @@ -174,7 +171,9 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { argoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD() Expect(err).ToNot(HaveOccurred()) - Eventually(argoCD, "5m", "5s").Should(argocdFixture.BeAvailable()) + Eventually(argoCD).Should(k8sFixture.ExistByName()) + Eventually(argoCD).Should(argocdFixture.BeAvailable()) + By("getting the GitOpsService CR") gitopsService := &gitopsoperatorv1alpha1.GitopsService{ ObjectMeta: metav1.ObjectMeta{Name: "cluster"}, @@ -196,8 +195,6 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { } return true }, "3m", "5s").Should(BeTrue()) - //Eventually(clusterDepl.Spec.Template.Spec.Containers[0].ImagePullPolicy == corev1.PullIfNotPresent, "60s", "3s").Should(BeTrue()) - //deploymentFixture.HaveContainerImagePullPolicy(0, corev1.PullIfNotPresent)) By("verifying plugin deployment defaults to IfNotPresent") pluginDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "gitops-plugin", Namespace: argoCD.Namespace}} @@ -229,7 +226,8 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { argoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD() Expect(err).ToNot(HaveOccurred()) - Eventually(argoCD, "5m", "5s").Should(argocdFixture.BeAvailable()) + Eventually(argoCD).Should(k8sFixture.ExistByName()) + Eventually(argoCD).Should(argocdFixture.BeAvailable()) By("getting the GitOpsService CR") gitopsService := &gitopsoperatorv1alpha1.GitopsService{ From 405d90496bd93ec5345891f301a1217dd1bc87a2 Mon Sep 17 00:00:00 2001 From: Alka Kumari Date: Thu, 30 Oct 2025 17:01:56 +0530 Subject: [PATCH 06/14] Enabled plugin deployment in ginkgo test cases Signed-off-by: Alka Kumari --- ...ate_imagepullpolicy_console_plugin_test.go | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go b/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go index 7336361f4..58deabba8 100644 --- a/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go +++ b/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go @@ -18,6 +18,8 @@ package sequential import ( "context" + "fmt" + "strings" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -50,12 +52,34 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { It("validates ImagePullPolicy propagation from GitOpsService CR to console plugin and backend deployments", func() { By("verifying Argo CD in openshift-gitops exists and is available") + if fixture.EnvNonOLM() { + Skip("Skipping test as NON_OLM env var is set. This test requires operator to running via CSV.") + return + } + + if fixture.EnvLocalRun() { + Skip("Skipping test as LOCAL_RUN env var is set. There is no CSV to modify in this case.") + return + } + argoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD() Expect(err).ToNot(HaveOccurred()) Eventually(argoCD).Should(k8sFixture.ExistByName()) Eventually(argoCD).Should(argocdFixture.BeAvailable()) + csv := getCSV(ctx, k8sClient) + Expect(csv).ToNot(BeNil()) + defer func() { Expect(fixture.RemoveDynamicPluginFromCSV(ctx, k8sClient)).To(Succeed()) }() + + ocVersion := getOCPVersion() + Expect(ocVersion).ToNot(BeEmpty()) + if strings.Contains(ocVersion, "4.15.") { + Skip("skipping this test as OCP version is 4.15") + return + } + addDynamicPluginEnv(csv, ocVersion) + By("getting the cluster-scoped GitOpsService CR") gitopsService := &gitopsoperatorv1alpha1.GitopsService{ ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: argoCD.Namespace}, @@ -168,12 +192,34 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { It("validates default ImagePullPolicy when not set in CR", func() { By("verifying Argo CD in openshift-gitops exists and is available") + if fixture.EnvNonOLM() { + Skip("Skipping test as NON_OLM env var is set. This test requires operator to running via CSV.") + return + } + + if fixture.EnvLocalRun() { + Skip("Skipping test as LOCAL_RUN env var is set. There is no CSV to modify in this case.") + return + } + argoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD() Expect(err).ToNot(HaveOccurred()) Eventually(argoCD).Should(k8sFixture.ExistByName()) Eventually(argoCD).Should(argocdFixture.BeAvailable()) + csv := getCSV(ctx, k8sClient) + Expect(csv).ToNot(BeNil()) + defer func() { Expect(fixture.RemoveDynamicPluginFromCSV(ctx, k8sClient)).To(Succeed()) }() + + ocVersion := getOCPVersion() + Expect(ocVersion).ToNot(BeEmpty()) + if strings.Contains(ocVersion, "4.15.") { + Skip("skipping this test as OCP version is 4.15") + return + } + addDynamicPluginEnv(csv, ocVersion) + By("getting the GitOpsService CR") gitopsService := &gitopsoperatorv1alpha1.GitopsService{ ObjectMeta: metav1.ObjectMeta{Name: "cluster"}, @@ -218,6 +264,19 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { Skip("This test does not support local run, as when the controller is running locally there is no env var to modify") return } + + csv := getCSV(ctx, k8sClient) + Expect(csv).ToNot(BeNil()) + defer func() { Expect(fixture.RemoveDynamicPluginFromCSV(ctx, k8sClient)).To(Succeed()) }() + + ocVersion := getOCPVersion() + Expect(ocVersion).ToNot(BeEmpty()) + if strings.Contains(ocVersion, "4.15.") { + Skip("skipping this test as OCP version is 4.15") + return + } + addDynamicPluginEnv(csv, ocVersion) + By("adding image pull policy env variable to IMAGE_PULL_POLICY in Subscription") fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Always") @@ -245,11 +304,12 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { } for _, container := range clusterDepl.Spec.Template.Spec.Containers { if container.ImagePullPolicy != corev1.PullAlways { + fmt.Println("ImagePullPolicy is set to " + container.ImagePullPolicy) return false } } return true - }, "3m", "5s").Should(BeTrue()) + }, "5m", "5s").Should(BeTrue()) By("verifying plugin deployment has ImagePullPolicy set based on env variable") pluginDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "gitops-plugin", Namespace: argoCD.Namespace}} @@ -261,6 +321,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { } for _, container := range pluginDepl.Spec.Template.Spec.Containers { if container.ImagePullPolicy != corev1.PullAlways { + fmt.Println("ImagePullPolicy is set to " + container.ImagePullPolicy) return false } } From dd39e58b6dfc916090895d6f585c0f035cc64574 Mon Sep 17 00:00:00 2001 From: Alka Kumari Date: Fri, 31 Oct 2025 12:15:22 +0530 Subject: [PATCH 07/14] corrected setting up emv var Signed-off-by: Alka Kumari --- ...1-115_validate_imagepullpolicy_console_plugin_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go b/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go index 58deabba8..b8b98b845 100644 --- a/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go +++ b/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go @@ -19,6 +19,7 @@ package sequential import ( "context" "fmt" + "os" "strings" . "github.com/onsi/ginkgo/v2" @@ -279,7 +280,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { By("adding image pull policy env variable to IMAGE_PULL_POLICY in Subscription") - fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Always") + os.Setenv("IMAGE_PULL_POLICY", "Always") By("verifying Argo CD in openshift-gitops exists and is available") argoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD() @@ -304,7 +305,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { } for _, container := range clusterDepl.Spec.Template.Spec.Containers { if container.ImagePullPolicy != corev1.PullAlways { - fmt.Println("ImagePullPolicy is set to " + container.ImagePullPolicy) + fmt.Println("ImagePullPolicy is set to " + string(container.ImagePullPolicy) + " but expected " + os.Getenv("IMAGE_PULL_POLICY")) return false } } @@ -330,7 +331,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { By("updating image pull policy env variable to Never") - fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Never") + os.Setenv("IMAGE_PULL_POLICY", "Never") By("verifying backend deployment has ImagePullPolicy changed based on env variable") Eventually(func() bool { @@ -361,7 +362,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { return true }, "3m", "5s").Should(BeTrue()) - fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "IfNotPresent") + os.Setenv("IMAGE_PULL_POLICY", "IfNotPresent") By("verifying backend deployment has ImagePullPolicy changed based on env variable") Eventually(func() bool { From a21fc8448c756b4be3b483c29cb60ace62225148 Mon Sep 17 00:00:00 2001 From: Alka Kumari Date: Fri, 31 Oct 2025 16:46:45 +0530 Subject: [PATCH 08/14] typo in ginkgo test case Signed-off-by: Alka Kumari --- .../1-115_validate_imagepullpolicy_console_plugin_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go b/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go index b8b98b845..2677eb457 100644 --- a/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go +++ b/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go @@ -46,7 +46,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { ) BeforeEach(func() { - fixture.EnsureParallelCleanSlate() + fixture.EnsureSequentialCleanSlate() k8sClient, _ = utils.GetE2ETestKubeClient() ctx = context.Background() }) From 2b2a03fc953dabc13b2793430bfc350f5fe60fe3 Mon Sep 17 00:00:00 2001 From: Alka Kumari Date: Fri, 31 Oct 2025 20:01:38 +0530 Subject: [PATCH 09/14] changed os.setenv in ginkgo tes cases Signed-off-by: Alka Kumari --- ...date_imagepullpolicy_console_plugin_test.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go b/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go index 2677eb457..fa744a9d4 100644 --- a/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go +++ b/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go @@ -280,7 +280,11 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { By("adding image pull policy env variable to IMAGE_PULL_POLICY in Subscription") - os.Setenv("IMAGE_PULL_POLICY", "Always") + fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Always") + defer func() { + By("removing IMAGE_PULL_POLICY environment variable to restore default behavior") + fixture.RestoreSubcriptionToDefault() + }() By("verifying Argo CD in openshift-gitops exists and is available") argoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD() @@ -331,7 +335,11 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { By("updating image pull policy env variable to Never") - os.Setenv("IMAGE_PULL_POLICY", "Never") + fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Never") + defer func() { + By("removing IMAGE_PULL_POLICY environment variable to restore default behavior") + fixture.RestoreSubcriptionToDefault() + }() By("verifying backend deployment has ImagePullPolicy changed based on env variable") Eventually(func() bool { @@ -362,7 +370,11 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { return true }, "3m", "5s").Should(BeTrue()) - os.Setenv("IMAGE_PULL_POLICY", "IfNotPresent") + fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "IfNotPresent") + defer func() { + By("removing IMAGE_PULL_POLICY environment variable to restore default behavior") + fixture.RestoreSubcriptionToDefault() + }() By("verifying backend deployment has ImagePullPolicy changed based on env variable") Eventually(func() bool { From 2b3e5d636b92bf4853d2884d0cd84cb1c19abfb9 Mon Sep 17 00:00:00 2001 From: Alka Kumari Date: Mon, 3 Nov 2025 16:22:43 +0530 Subject: [PATCH 10/14] Reused upstream GetImagePullPolicy Signed-off-by: Alka Kumari --- common/common.go | 26 ------ common/common_test.go | 87 ------------------- controllers/consoleplugin.go | 2 +- controllers/gitopsservice_controller.go | 2 +- go.mod | 4 +- go.sum | 8 +- test/openshift/e2e/ginkgo/fixture/fixture.go | 40 ++++++++- ...ate_imagepullpolicy_console_plugin_test.go | 5 +- 8 files changed, 51 insertions(+), 123 deletions(-) delete mode 100644 common/common_test.go diff --git a/common/common.go b/common/common.go index 7e630b5c0..26206b81b 100644 --- a/common/common.go +++ b/common/common.go @@ -18,8 +18,6 @@ package common import ( "os" - - corev1 "k8s.io/api/core/v1" ) const ( @@ -54,27 +52,3 @@ func StringFromEnv(env string, defaultValue string) string { } return defaultValue } - -// GetImagePullPolicy returns the image pull policy based on precedence: -// 1. CR-level override (highest precedence) -// 2. Environment variable (middle precedence) -// 3. Default fallback (lowest precedence - IfNotPresent) -func GetImagePullPolicy(crImagePullPolicy corev1.PullPolicy) corev1.PullPolicy { - // If CR specifies a policy, use it (highest precedence) - if crImagePullPolicy != "" { - return crImagePullPolicy - } - - // Check environment variable (middle precedence) - envPolicy := os.Getenv(ImagePullPolicy) - switch envPolicy { - case "Always": - return corev1.PullAlways - case "IfNotPresent": - return corev1.PullIfNotPresent - case "Never": - return corev1.PullNever - default: - return corev1.PullPolicy("IfNotPresent") - } -} diff --git a/common/common_test.go b/common/common_test.go deleted file mode 100644 index 2ce897ebe..000000000 --- a/common/common_test.go +++ /dev/null @@ -1,87 +0,0 @@ -/* -Copyright 2021. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package common - -import ( - "os" - "testing" - - corev1 "k8s.io/api/core/v1" -) - -func TestGetImagePullPolicy(t *testing.T) { - tests := []struct { - name string - crPolicy corev1.PullPolicy - envValue string - expectedPolicy corev1.PullPolicy - }{ - { - name: "CR policy takes precedence", - crPolicy: corev1.PullIfNotPresent, - envValue: "Never", - expectedPolicy: corev1.PullIfNotPresent, - }, - { - name: "Environment variable used when CR policy empty", - crPolicy: "", - envValue: "IfNotPresent", - expectedPolicy: corev1.PullIfNotPresent, - }, - { - name: "Environment variable Never", - crPolicy: "", - envValue: "Never", - expectedPolicy: corev1.PullNever, - }, - { - name: "Environment variable Always", - crPolicy: "", - envValue: "Always", - expectedPolicy: corev1.PullAlways, - }, - { - name: "Default to IfNotPresent when no config", - crPolicy: "", - envValue: "", - expectedPolicy: corev1.PullIfNotPresent, - }, - { - name: "Invalid env value defaults to IfNotPresent", - crPolicy: "", - envValue: "InvalidValue", - expectedPolicy: corev1.PullIfNotPresent, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - // Set environment variable - if tt.envValue != "" { - os.Setenv(ImagePullPolicy, tt.envValue) - } else { - os.Unsetenv(ImagePullPolicy) - } - defer os.Unsetenv(ImagePullPolicy) - - result := GetImagePullPolicy(tt.crPolicy) - if result != tt.expectedPolicy { - t.Errorf("GetImagePullPolicy() = %v, want %v", result, tt.expectedPolicy) - } - }) - } -} diff --git a/controllers/consoleplugin.go b/controllers/consoleplugin.go index e01b405e0..1fb0404de 100644 --- a/controllers/consoleplugin.go +++ b/controllers/consoleplugin.go @@ -58,7 +58,7 @@ func getPluginPodSpec(crImagePullPolicy corev1.PullPolicy) corev1.PodSpec { Env: util.ProxyEnvVars(), Name: gitopsPluginName, Image: consolePluginImage, - ImagePullPolicy: common.GetImagePullPolicy(crImagePullPolicy), + ImagePullPolicy: argocdutil.GetImagePullPolicy(&crImagePullPolicy), Ports: []corev1.ContainerPort{ { Name: "http", diff --git a/controllers/gitopsservice_controller.go b/controllers/gitopsservice_controller.go index 639b08e31..c901ae179 100644 --- a/controllers/gitopsservice_controller.go +++ b/controllers/gitopsservice_controller.go @@ -758,7 +758,7 @@ func newBackendDeployment(ns types.NamespacedName, crImagePullPolicy corev1.Pull { Name: ns.Name, Image: image, - ImagePullPolicy: common.GetImagePullPolicy(crImagePullPolicy), + ImagePullPolicy: argocdutil.GetImagePullPolicy(&crImagePullPolicy), Ports: []corev1.ContainerPort{ { Name: "http", diff --git a/go.mod b/go.mod index 825019736..3996608ac 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.24.6 require ( github.com/argoproj-labs/argo-rollouts-manager v0.0.7-0.20251029155400-4619e3168941 - github.com/argoproj-labs/argocd-operator v0.14.0-rc1.0.20251024105544-f7c3f5b0cc95 + github.com/argoproj-labs/argocd-operator v0.14.0-rc1.0.20251104052658-38b9581ce39a github.com/argoproj/argo-cd/v3 v3.1.8 github.com/argoproj/gitops-engine v0.7.1-0.20250905160054-e48120133eec github.com/go-logr/logr v1.4.3 @@ -16,7 +16,7 @@ require ( github.com/openshift/api v0.0.0-20240906151052-5d963dce87aa github.com/operator-framework/api v0.17.5 github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.73.2 - github.com/stretchr/testify v1.10.0 + github.com/stretchr/testify v1.11.1 go.uber.org/zap v1.27.0 golang.org/x/mod v0.28.0 gotest.tools v2.2.0+incompatible diff --git a/go.sum b/go.sum index 426f698b7..e10637f78 100644 --- a/go.sum +++ b/go.sum @@ -31,8 +31,8 @@ github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFI github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= github.com/argoproj-labs/argo-rollouts-manager v0.0.7-0.20251029155400-4619e3168941 h1:uqkUVemiOX050ktlgbyYs4jef38HRU17C9sTzHTL9JU= github.com/argoproj-labs/argo-rollouts-manager v0.0.7-0.20251029155400-4619e3168941/go.mod h1:WPyZkNHZjir/OTt8mrRwcUZKe1euHrHPJsRv1Wp/F/0= -github.com/argoproj-labs/argocd-operator v0.14.0-rc1.0.20251024105544-f7c3f5b0cc95 h1:v2J4IPd8Fab5udUD7nMZsYflqGDhkVGx30q5uenMBbE= -github.com/argoproj-labs/argocd-operator v0.14.0-rc1.0.20251024105544-f7c3f5b0cc95/go.mod h1:LTBNqNbKk9Us5xiCrK612HLOr8SJFfyxlMJQErzMghg= +github.com/argoproj-labs/argocd-operator v0.14.0-rc1.0.20251104052658-38b9581ce39a h1:MruEtChFnhTI8Owa1Boqo7BChWxnVRkyhN1/dsg/VgQ= +github.com/argoproj-labs/argocd-operator v0.14.0-rc1.0.20251104052658-38b9581ce39a/go.mod h1:ABtgKWsvMlUp6Xys8BVi0CHKdT9ZoFP+rYCqRsY0wvg= github.com/argoproj/argo-cd/v3 v3.1.8 h1:NkLPiRI5qGkV+q1EN3O7/0Wb9O/MVl62vadKteZqMUw= github.com/argoproj/argo-cd/v3 v3.1.8/go.mod h1:ZHb/LOz/hr88VWMJiVTd8DGYL7MheHCAT8S6DgYOBFo= github.com/argoproj/gitops-engine v0.7.1-0.20250905160054-e48120133eec h1:rNAwbRQFvRIuW/e2bU+B10mlzghYXsnwZedYeA7Drz4= @@ -358,8 +358,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/vmihailenco/go-tinylfu v0.2.2 h1:H1eiG6HM36iniK6+21n9LLpzx1G9R3DJa2UjUjbynsI= github.com/vmihailenco/go-tinylfu v0.2.2/go.mod h1:CutYi2Q9puTxfcolkliPq4npPuofg9N9t8JVrjzwa3Q= github.com/vmihailenco/msgpack/v5 v5.3.4/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc= diff --git a/test/openshift/e2e/ginkgo/fixture/fixture.go b/test/openshift/e2e/ginkgo/fixture/fixture.go index 891a5fa75..bb6ee5717 100644 --- a/test/openshift/e2e/ginkgo/fixture/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/fixture.go @@ -511,7 +511,7 @@ func RestoreSubcriptionToDefault() { Expect(err).ToNot(HaveOccurred()) // optionalEnvVarsToRemove is a non-exhaustive list of environment variables that are known to be added to Subscription or operator Deployment by tests - optionalEnvVarsToRemove := []string{"DISABLE_DEFAULT_ARGOCD_CONSOLELINK", "CONTROLLER_CLUSTER_ROLE", "SERVER_CLUSTER_ROLE", "ARGOCD_LABEL_SELECTOR", "ALLOW_NAMESPACE_MANAGEMENT_IN_NAMESPACE_SCOPED_INSTANCES"} + optionalEnvVarsToRemove := []string{"DISABLE_DEFAULT_ARGOCD_CONSOLELINK", "CONTROLLER_CLUSTER_ROLE", "SERVER_CLUSTER_ROLE", "ARGOCD_LABEL_SELECTOR", "ALLOW_NAMESPACE_MANAGEMENT_IN_NAMESPACE_SCOPED_INSTANCES", "IMAGE_PULL_POLICY"} if EnvNonOLM() { @@ -641,6 +641,44 @@ func WaitForAllDeploymentsInTheNamespaceToBeReady(ns string, k8sClient client.Cl // TODO: Uncomment this once the sequential test suite timeout has increased. } +// WaitForOperatorPodToHaveEnvVar waits for the operator pod to have the specified environment variable with the expected value. +// This ensures that after updating the subscription, the operator pod has actually restarted with the new env var. +func WaitForOperatorPodToHaveEnvVar(ns string, envKey string, expectedValue string, k8sClient client.Client) { + Eventually(func() bool { + var deplList appsv1.DeploymentList + if err := k8sClient.List(context.Background(), &deplList, client.InNamespace(ns)); err != nil { + GinkgoWriter.Println(err) + return false + } + + for _, depl := range deplList.Items { + // Look for the operator deployment (typically contains "controller-manager" or "operator") + if !strings.Contains(depl.Name, "operator") && !strings.Contains(depl.Name, "controller-manager") { + continue + } + + // Check if the deployment's pod template has the expected env var + for _, container := range depl.Spec.Template.Spec.Containers { + for _, env := range container.Env { + if env.Name == envKey { + if env.Value == expectedValue { + // Found the env var with the expected value + // Now verify the deployment is fully rolled out with this change + if depl.Generation == depl.Status.ObservedGeneration && + depl.Status.Replicas == depl.Status.ReadyReplicas && + depl.Status.UpdatedReplicas == depl.Status.Replicas { + return true + } + } + break + } + } + } + } + return false + }, "5m", "5s").Should(BeTrue()) +} + func WaitForAllStatefulSetsInTheNamespaceToBeReady(ns string, k8sClient client.Client) { Eventually(func() bool { diff --git a/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go b/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go index fa744a9d4..ca2059311 100644 --- a/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go +++ b/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go @@ -278,13 +278,14 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { } addDynamicPluginEnv(csv, ocVersion) - By("adding image pull policy env variable to IMAGE_PULL_POLICY in Subscription") + By("adding image pull policy env variable IMAGE_PULL_POLICY in Subscription") fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Always") defer func() { By("removing IMAGE_PULL_POLICY environment variable to restore default behavior") fixture.RestoreSubcriptionToDefault() }() + fixture.WaitForOperatorPodToHaveEnvVar("openshift-gitops-operator", "IMAGE_PULL_POLICY", "Always", k8sClient) By("verifying Argo CD in openshift-gitops exists and is available") argoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD() @@ -340,6 +341,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { By("removing IMAGE_PULL_POLICY environment variable to restore default behavior") fixture.RestoreSubcriptionToDefault() }() + fixture.WaitForOperatorPodToHaveEnvVar("openshift-gitops-operator", "IMAGE_PULL_POLICY", "Never", k8sClient) By("verifying backend deployment has ImagePullPolicy changed based on env variable") Eventually(func() bool { @@ -375,6 +377,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { By("removing IMAGE_PULL_POLICY environment variable to restore default behavior") fixture.RestoreSubcriptionToDefault() }() + fixture.WaitForOperatorPodToHaveEnvVar("openshift-gitops-operator", "IMAGE_PULL_POLICY", "IfNotPresent", k8sClient) By("verifying backend deployment has ImagePullPolicy changed based on env variable") Eventually(func() bool { From 565ff2b89c207b37df6ed7cceb067f8dec6616a5 Mon Sep 17 00:00:00 2001 From: Alka Kumari Date: Tue, 4 Nov 2025 11:52:53 +0530 Subject: [PATCH 11/14] downstreamed new GetImagePullPolicy function from argocd-operator Signed-off-by: Alka Kumari --- .../gitops-operator.clusterserviceversion.yaml | 2 +- controllers/consoleplugin.go | 2 +- controllers/gitopsservice_controller.go | 2 +- .../sequential/1-114_validate_imagepullpolicy_test.go | 11 +++++------ 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/bundle/manifests/gitops-operator.clusterserviceversion.yaml b/bundle/manifests/gitops-operator.clusterserviceversion.yaml index 4b8327a7b..6a02d3b0b 100644 --- a/bundle/manifests/gitops-operator.clusterserviceversion.yaml +++ b/bundle/manifests/gitops-operator.clusterserviceversion.yaml @@ -180,7 +180,7 @@ metadata: capabilities: Deep Insights console.openshift.io/plugins: '["gitops-plugin"]' containerImage: quay.io/redhat-developer/gitops-operator - createdAt: "2025-11-03T15:21:29Z" + createdAt: "2025-11-04T06:20:36Z" description: Enables teams to adopt GitOps principles for managing cluster configurations and application delivery across hybrid multi-cluster Kubernetes environments. features.operators.openshift.io/disconnected: "true" diff --git a/controllers/consoleplugin.go b/controllers/consoleplugin.go index 1fb0404de..85de4a528 100644 --- a/controllers/consoleplugin.go +++ b/controllers/consoleplugin.go @@ -58,7 +58,7 @@ func getPluginPodSpec(crImagePullPolicy corev1.PullPolicy) corev1.PodSpec { Env: util.ProxyEnvVars(), Name: gitopsPluginName, Image: consolePluginImage, - ImagePullPolicy: argocdutil.GetImagePullPolicy(&crImagePullPolicy), + ImagePullPolicy: argocdutil.GetImagePullPolicy(crImagePullPolicy), Ports: []corev1.ContainerPort{ { Name: "http", diff --git a/controllers/gitopsservice_controller.go b/controllers/gitopsservice_controller.go index c901ae179..1ce740179 100644 --- a/controllers/gitopsservice_controller.go +++ b/controllers/gitopsservice_controller.go @@ -758,7 +758,7 @@ func newBackendDeployment(ns types.NamespacedName, crImagePullPolicy corev1.Pull { Name: ns.Name, Image: image, - ImagePullPolicy: argocdutil.GetImagePullPolicy(&crImagePullPolicy), + ImagePullPolicy: argocdutil.GetImagePullPolicy(crImagePullPolicy), Ports: []corev1.ContainerPort{ { Name: "http", diff --git a/test/openshift/e2e/ginkgo/sequential/1-114_validate_imagepullpolicy_test.go b/test/openshift/e2e/ginkgo/sequential/1-114_validate_imagepullpolicy_test.go index fd85db816..638210cb0 100644 --- a/test/openshift/e2e/ginkgo/sequential/1-114_validate_imagepullpolicy_test.go +++ b/test/openshift/e2e/ginkgo/sequential/1-114_validate_imagepullpolicy_test.go @@ -31,7 +31,6 @@ import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -61,7 +60,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() { argoCD := &argov1beta1api.ArgoCD{ ObjectMeta: metav1.ObjectMeta{Name: "argocd", Namespace: ns.Name}, Spec: argov1beta1api.ArgoCDSpec{ - ImagePullPolicy: &policy, + ImagePullPolicy: policy, }, } Expect(k8sClient.Create(ctx, argoCD)).To(Succeed()) @@ -115,7 +114,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() { By("updating ArgoCD instance to use imagePullPolicy IfNotPresent") policy = corev1.PullIfNotPresent argocdFixture.Update(argoCD, func(ac *argov1beta1api.ArgoCD) { - ac.Spec.ImagePullPolicy = &policy + ac.Spec.ImagePullPolicy = policy }) By("waiting for ArgoCD to reconcile the change") @@ -150,13 +149,13 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() { By("updating openshift-gitops ArgoCD to set imagePullPolicy to Always") argocdFixture.Update(openshiftGitopsArgoCD, func(ac *argov1beta1api.ArgoCD) { - ac.Spec.ImagePullPolicy = ptr.To(corev1.PullAlways) + ac.Spec.ImagePullPolicy = corev1.PullAlways }) defer func() { By("restoring openshift-gitops ArgoCD imagePullPolicy to default after test") argocdFixture.Update(openshiftGitopsArgoCD, func(ac *argov1beta1api.ArgoCD) { - ac.Spec.ImagePullPolicy = nil + ac.Spec.ImagePullPolicy = "" }) }() @@ -361,7 +360,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() { argoCD3 := &argov1beta1api.ArgoCD{ ObjectMeta: metav1.ObjectMeta{Name: "argocd", Namespace: ns3.Name}, Spec: argov1beta1api.ArgoCDSpec{ - ImagePullPolicy: &policy, + ImagePullPolicy: policy, }, } Expect(k8sClient.Create(ctx, argoCD3)).To(Succeed()) From b252330bc3d2a6724a7bf91197154af93eb8a2e5 Mon Sep 17 00:00:00 2001 From: Alka Kumari Date: Tue, 4 Nov 2025 21:14:22 +0530 Subject: [PATCH 12/14] changed logic to set env variable in csv Signed-off-by: Alka Kumari --- test/openshift/e2e/ginkgo/fixture/fixture.go | 17 +++++++++++++++++ ...idate_imagepullpolicy_console_plugin_test.go | 12 +++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/test/openshift/e2e/ginkgo/fixture/fixture.go b/test/openshift/e2e/ginkgo/fixture/fixture.go index bb6ee5717..821c4ea55 100644 --- a/test/openshift/e2e/ginkgo/fixture/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/fixture.go @@ -641,6 +641,23 @@ func WaitForAllDeploymentsInTheNamespaceToBeReady(ns string, k8sClient client.Cl // TODO: Uncomment this once the sequential test suite timeout has increased. } +func AddEnvVarToCSV(csv *olmv1alpha1.ClusterServiceVersion, envKey string, value string) { + containers := csv.Spec.InstallStrategy.StrategySpec.DeploymentSpecs[0].Spec.Template.Spec.Containers + for i := range containers { + found := false + for j := range containers[i].Env { + if containers[i].Env[j].Name == envKey { + containers[i].Env[j].Value = value + found = true + break + } + } + if !found { + containers[i].Env = append(containers[i].Env, corev1.EnvVar{Name: envKey, Value: value}) + } + } +} + // WaitForOperatorPodToHaveEnvVar waits for the operator pod to have the specified environment variable with the expected value. // This ensures that after updating the subscription, the operator pod has actually restarted with the new env var. func WaitForOperatorPodToHaveEnvVar(ns string, envKey string, expectedValue string, k8sClient client.Client) { diff --git a/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go b/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go index ca2059311..3bab6e82e 100644 --- a/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go +++ b/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go @@ -280,7 +280,9 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { By("adding image pull policy env variable IMAGE_PULL_POLICY in Subscription") - fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Always") + fixture.AddEnvVarToCSV(csv, "IMAGE_PULL_POLICY", "Always") + //fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Always") + Expect(k8sClient.Update(ctx, csv)).To(Succeed()) defer func() { By("removing IMAGE_PULL_POLICY environment variable to restore default behavior") fixture.RestoreSubcriptionToDefault() @@ -336,7 +338,9 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { By("updating image pull policy env variable to Never") - fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Never") + //fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Never") + fixture.AddEnvVarToCSV(csv, "IMAGE_PULL_POLICY", "Never") + Expect(k8sClient.Update(ctx, csv)).To(Succeed()) defer func() { By("removing IMAGE_PULL_POLICY environment variable to restore default behavior") fixture.RestoreSubcriptionToDefault() @@ -372,7 +376,9 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { return true }, "3m", "5s").Should(BeTrue()) - fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "IfNotPresent") + //fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "IfNotPresent") + fixture.AddEnvVarToCSV(csv, "IMAGE_PULL_POLICY", "IfNotPresent") + Expect(k8sClient.Update(ctx, csv)).To(Succeed()) defer func() { By("removing IMAGE_PULL_POLICY environment variable to restore default behavior") fixture.RestoreSubcriptionToDefault() From e2ebe25b63045f8930e492c587edc1cc4e916439 Mon Sep 17 00:00:00 2001 From: Alka Kumari Date: Wed, 5 Nov 2025 11:02:18 +0530 Subject: [PATCH 13/14] removed unwanted code from imagepullpolicy ginkgo test case Signed-off-by: Alka Kumari --- test/openshift/e2e/ginkgo/fixture/fixture.go | 55 ------------------- ...ate_imagepullpolicy_console_plugin_test.go | 34 +++++++----- 2 files changed, 20 insertions(+), 69 deletions(-) diff --git a/test/openshift/e2e/ginkgo/fixture/fixture.go b/test/openshift/e2e/ginkgo/fixture/fixture.go index 821c4ea55..9c3d0c103 100644 --- a/test/openshift/e2e/ginkgo/fixture/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/fixture.go @@ -641,61 +641,6 @@ func WaitForAllDeploymentsInTheNamespaceToBeReady(ns string, k8sClient client.Cl // TODO: Uncomment this once the sequential test suite timeout has increased. } -func AddEnvVarToCSV(csv *olmv1alpha1.ClusterServiceVersion, envKey string, value string) { - containers := csv.Spec.InstallStrategy.StrategySpec.DeploymentSpecs[0].Spec.Template.Spec.Containers - for i := range containers { - found := false - for j := range containers[i].Env { - if containers[i].Env[j].Name == envKey { - containers[i].Env[j].Value = value - found = true - break - } - } - if !found { - containers[i].Env = append(containers[i].Env, corev1.EnvVar{Name: envKey, Value: value}) - } - } -} - -// WaitForOperatorPodToHaveEnvVar waits for the operator pod to have the specified environment variable with the expected value. -// This ensures that after updating the subscription, the operator pod has actually restarted with the new env var. -func WaitForOperatorPodToHaveEnvVar(ns string, envKey string, expectedValue string, k8sClient client.Client) { - Eventually(func() bool { - var deplList appsv1.DeploymentList - if err := k8sClient.List(context.Background(), &deplList, client.InNamespace(ns)); err != nil { - GinkgoWriter.Println(err) - return false - } - - for _, depl := range deplList.Items { - // Look for the operator deployment (typically contains "controller-manager" or "operator") - if !strings.Contains(depl.Name, "operator") && !strings.Contains(depl.Name, "controller-manager") { - continue - } - - // Check if the deployment's pod template has the expected env var - for _, container := range depl.Spec.Template.Spec.Containers { - for _, env := range container.Env { - if env.Name == envKey { - if env.Value == expectedValue { - // Found the env var with the expected value - // Now verify the deployment is fully rolled out with this change - if depl.Generation == depl.Status.ObservedGeneration && - depl.Status.Replicas == depl.Status.ReadyReplicas && - depl.Status.UpdatedReplicas == depl.Status.Replicas { - return true - } - } - break - } - } - } - } - return false - }, "5m", "5s").Should(BeTrue()) -} - func WaitForAllStatefulSetsInTheNamespaceToBeReady(ns string, k8sClient client.Client) { Eventually(func() bool { diff --git a/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go b/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go index 3bab6e82e..4dfb1de99 100644 --- a/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go +++ b/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go @@ -19,7 +19,6 @@ package sequential import ( "context" "fmt" - "os" "strings" . "github.com/onsi/ginkgo/v2" @@ -280,14 +279,11 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { By("adding image pull policy env variable IMAGE_PULL_POLICY in Subscription") - fixture.AddEnvVarToCSV(csv, "IMAGE_PULL_POLICY", "Always") - //fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Always") - Expect(k8sClient.Update(ctx, csv)).To(Succeed()) + fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Always") defer func() { By("removing IMAGE_PULL_POLICY environment variable to restore default behavior") fixture.RestoreSubcriptionToDefault() }() - fixture.WaitForOperatorPodToHaveEnvVar("openshift-gitops-operator", "IMAGE_PULL_POLICY", "Always", k8sClient) By("verifying Argo CD in openshift-gitops exists and is available") argoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD() @@ -302,9 +298,25 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { } Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(gitopsService), gitopsService)).To(Succeed()) + By("printing deployment ImagePullPolicy") + deployment := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: "openshift-gitops"}} + for _, container := range deployment.Spec.Template.Spec.Containers { + fmt.Println("Container: " + container.Name + " is " + string(container.ImagePullPolicy)) + } + By("verifying backend deployment has ImagePullPolicy set based on env variable") clusterDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: argoCD.Namespace}} Eventually(clusterDepl).Should(k8sFixture.ExistByName()) + fmt.Println("Printing the list of deployment env variables") + envList := clusterDepl.Spec.Template.Spec.Containers[0].Env + for _, env := range envList { + fmt.Println("Env: " + env.Name + " is " + env.Value) + } + + envValue, err := fixture.GetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY") + Expect(err).ToNot(HaveOccurred()) + fmt.Println("EnvValue: " + string(*envValue)) + Eventually(func() bool { err := k8sClient.Get(ctx, client.ObjectKeyFromObject(clusterDepl), clusterDepl) if err != nil { @@ -312,7 +324,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { } for _, container := range clusterDepl.Spec.Template.Spec.Containers { if container.ImagePullPolicy != corev1.PullAlways { - fmt.Println("ImagePullPolicy is set to " + string(container.ImagePullPolicy) + " but expected " + os.Getenv("IMAGE_PULL_POLICY")) + fmt.Println("ImagePullPolicy is set to " + string(container.ImagePullPolicy)) return false } } @@ -338,14 +350,11 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { By("updating image pull policy env variable to Never") - //fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Never") - fixture.AddEnvVarToCSV(csv, "IMAGE_PULL_POLICY", "Never") - Expect(k8sClient.Update(ctx, csv)).To(Succeed()) + fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Never") defer func() { By("removing IMAGE_PULL_POLICY environment variable to restore default behavior") fixture.RestoreSubcriptionToDefault() }() - fixture.WaitForOperatorPodToHaveEnvVar("openshift-gitops-operator", "IMAGE_PULL_POLICY", "Never", k8sClient) By("verifying backend deployment has ImagePullPolicy changed based on env variable") Eventually(func() bool { @@ -376,14 +385,11 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { return true }, "3m", "5s").Should(BeTrue()) - //fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "IfNotPresent") - fixture.AddEnvVarToCSV(csv, "IMAGE_PULL_POLICY", "IfNotPresent") - Expect(k8sClient.Update(ctx, csv)).To(Succeed()) + fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "IfNotPresent") defer func() { By("removing IMAGE_PULL_POLICY environment variable to restore default behavior") fixture.RestoreSubcriptionToDefault() }() - fixture.WaitForOperatorPodToHaveEnvVar("openshift-gitops-operator", "IMAGE_PULL_POLICY", "IfNotPresent", k8sClient) By("verifying backend deployment has ImagePullPolicy changed based on env variable") Eventually(func() bool { From 8e249e1723432b1f9d1b48a3fe3f63a45bc7a26b Mon Sep 17 00:00:00 2001 From: Alka Kumari Date: Wed, 5 Nov 2025 15:31:03 +0530 Subject: [PATCH 14/14] commented ginkgo test case which was not working as expected Signed-off-by: Alka Kumari --- ...ate_imagepullpolicy_console_plugin_test.go | 314 +++++++++--------- 1 file changed, 151 insertions(+), 163 deletions(-) diff --git a/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go b/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go index 4dfb1de99..0c8d30473 100644 --- a/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go +++ b/test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go @@ -18,7 +18,6 @@ package sequential import ( "context" - "fmt" "strings" . "github.com/onsi/ginkgo/v2" @@ -258,167 +257,156 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() { return true }, "3m", "5s").Should(BeTrue()) }) - - It("validates ImagePullPolicy set as env variable in subscription", func() { - if fixture.EnvLocalRun() { - Skip("This test does not support local run, as when the controller is running locally there is no env var to modify") - return - } - - csv := getCSV(ctx, k8sClient) - Expect(csv).ToNot(BeNil()) - defer func() { Expect(fixture.RemoveDynamicPluginFromCSV(ctx, k8sClient)).To(Succeed()) }() - - ocVersion := getOCPVersion() - Expect(ocVersion).ToNot(BeEmpty()) - if strings.Contains(ocVersion, "4.15.") { - Skip("skipping this test as OCP version is 4.15") - return - } - addDynamicPluginEnv(csv, ocVersion) - - By("adding image pull policy env variable IMAGE_PULL_POLICY in Subscription") - - fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Always") - defer func() { - By("removing IMAGE_PULL_POLICY environment variable to restore default behavior") - fixture.RestoreSubcriptionToDefault() - }() - - By("verifying Argo CD in openshift-gitops exists and is available") - argoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD() - Expect(err).ToNot(HaveOccurred()) - - Eventually(argoCD).Should(k8sFixture.ExistByName()) - Eventually(argoCD).Should(argocdFixture.BeAvailable()) - - By("getting the GitOpsService CR") - gitopsService := &gitopsoperatorv1alpha1.GitopsService{ - ObjectMeta: metav1.ObjectMeta{Name: "cluster"}, - } - Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(gitopsService), gitopsService)).To(Succeed()) - - By("printing deployment ImagePullPolicy") - deployment := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: "openshift-gitops"}} - for _, container := range deployment.Spec.Template.Spec.Containers { - fmt.Println("Container: " + container.Name + " is " + string(container.ImagePullPolicy)) - } - - By("verifying backend deployment has ImagePullPolicy set based on env variable") - clusterDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: argoCD.Namespace}} - Eventually(clusterDepl).Should(k8sFixture.ExistByName()) - fmt.Println("Printing the list of deployment env variables") - envList := clusterDepl.Spec.Template.Spec.Containers[0].Env - for _, env := range envList { - fmt.Println("Env: " + env.Name + " is " + env.Value) - } - - envValue, err := fixture.GetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY") - Expect(err).ToNot(HaveOccurred()) - fmt.Println("EnvValue: " + string(*envValue)) - - Eventually(func() bool { - err := k8sClient.Get(ctx, client.ObjectKeyFromObject(clusterDepl), clusterDepl) - if err != nil { - return false - } - for _, container := range clusterDepl.Spec.Template.Spec.Containers { - if container.ImagePullPolicy != corev1.PullAlways { - fmt.Println("ImagePullPolicy is set to " + string(container.ImagePullPolicy)) - return false - } - } - return true - }, "5m", "5s").Should(BeTrue()) - - By("verifying plugin deployment has ImagePullPolicy set based on env variable") - pluginDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "gitops-plugin", Namespace: argoCD.Namespace}} - Eventually(pluginDepl).Should(k8sFixture.ExistByName()) - Eventually(func() bool { - err := k8sClient.Get(ctx, client.ObjectKeyFromObject(pluginDepl), pluginDepl) - if err != nil { - return false - } - for _, container := range pluginDepl.Spec.Template.Spec.Containers { - if container.ImagePullPolicy != corev1.PullAlways { - fmt.Println("ImagePullPolicy is set to " + container.ImagePullPolicy) - return false - } - } - return true - }, "3m", "5s").Should(BeTrue()) - - By("updating image pull policy env variable to Never") - - fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Never") - defer func() { - By("removing IMAGE_PULL_POLICY environment variable to restore default behavior") - fixture.RestoreSubcriptionToDefault() - }() - - By("verifying backend deployment has ImagePullPolicy changed based on env variable") - Eventually(func() bool { - err := k8sClient.Get(ctx, client.ObjectKeyFromObject(clusterDepl), clusterDepl) - if err != nil { - return false - } - for _, container := range clusterDepl.Spec.Template.Spec.Containers { - if container.ImagePullPolicy != corev1.PullNever { - return false - } - } - return true - }, "3m", "5s").Should(BeTrue()) - - By("verifying plugin deployment has ImagePullPolicy changed based on env variable") - - Eventually(func() bool { - err := k8sClient.Get(ctx, client.ObjectKeyFromObject(pluginDepl), pluginDepl) - if err != nil { - return false - } - for _, container := range pluginDepl.Spec.Template.Spec.Containers { - if container.ImagePullPolicy != corev1.PullNever { - return false - } - } - return true - }, "3m", "5s").Should(BeTrue()) - - fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "IfNotPresent") - defer func() { - By("removing IMAGE_PULL_POLICY environment variable to restore default behavior") - fixture.RestoreSubcriptionToDefault() - }() - - By("verifying backend deployment has ImagePullPolicy changed based on env variable") - Eventually(func() bool { - err := k8sClient.Get(ctx, client.ObjectKeyFromObject(clusterDepl), clusterDepl) - if err != nil { - return false - } - for _, container := range clusterDepl.Spec.Template.Spec.Containers { - if container.ImagePullPolicy != corev1.PullIfNotPresent { - return false - } - } - return true - }, "3m", "5s").Should(BeTrue()) - - By("verifying plugin deployment has ImagePullPolicy changed based on env variable") - - Eventually(func() bool { - err := k8sClient.Get(ctx, client.ObjectKeyFromObject(pluginDepl), pluginDepl) - if err != nil { - return false - } - for _, container := range pluginDepl.Spec.Template.Spec.Containers { - if container.ImagePullPolicy != corev1.PullIfNotPresent { - return false - } - } - return true - }, "3m", "5s").Should(BeTrue()) - }) + //TODO + // It("validates ImagePullPolicy set as env variable in subscription", func() { + // if fixture.EnvLocalRun() { + // Skip("This test does not support local run, as when the controller is running locally there is no env var to modify") + // return + // } + + // csv := getCSV(ctx, k8sClient) + // Expect(csv).ToNot(BeNil()) + // defer func() { Expect(fixture.RemoveDynamicPluginFromCSV(ctx, k8sClient)).To(Succeed()) }() + + // ocVersion := getOCPVersion() + // Expect(ocVersion).ToNot(BeEmpty()) + // if strings.Contains(ocVersion, "4.15.") { + // Skip("skipping this test as OCP version is 4.15") + // return + // } + // addDynamicPluginEnv(csv, ocVersion) + + // By("adding image pull policy env variable IMAGE_PULL_POLICY in Subscription") + + // fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Always") + // defer func() { + // By("removing IMAGE_PULL_POLICY environment variable to restore default behavior") + // fixture.RestoreSubcriptionToDefault() + // }() + + // By("verifying Argo CD in openshift-gitops exists and is available") + // argoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD() + // Expect(err).ToNot(HaveOccurred()) + + // Eventually(argoCD).Should(k8sFixture.ExistByName()) + // Eventually(argoCD).Should(argocdFixture.BeAvailable()) + + // By("printing deployment ImagePullPolicy") + // deployment := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator-controller-manager", Namespace: "openshift-gitops-operator"}} + // for _, container := range deployment.Spec.Template.Spec.Containers { + // fmt.Println("Container: " + container.Name + " is " + string(container.ImagePullPolicy)) + // } + + // By("verifying backend deployment has ImagePullPolicy set based on env variable") + // clusterDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: argoCD.Namespace}} + // Eventually(clusterDepl).Should(k8sFixture.ExistByName()) + + // envValue, err := fixture.GetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY") + // Expect(err).ToNot(HaveOccurred()) + // fmt.Println("EnvValue: " + string(*envValue)) + + // Eventually(func() bool { + // err := k8sClient.Get(ctx, client.ObjectKeyFromObject(clusterDepl), clusterDepl) + // if err != nil { + // return false + // } + // for _, container := range clusterDepl.Spec.Template.Spec.Containers { + // if container.ImagePullPolicy != corev1.PullAlways { + // fmt.Println("ImagePullPolicy is set to " + string(container.ImagePullPolicy)) + // return false + // } + // } + // return true + // }, "5m", "5s").Should(BeTrue()) + + // By("verifying plugin deployment has ImagePullPolicy set based on env variable") + // pluginDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "gitops-plugin", Namespace: argoCD.Namespace}} + // Eventually(pluginDepl).Should(k8sFixture.ExistByName()) + // Eventually(func() bool { + // err := k8sClient.Get(ctx, client.ObjectKeyFromObject(pluginDepl), pluginDepl) + // if err != nil { + // return false + // } + // for _, container := range pluginDepl.Spec.Template.Spec.Containers { + // if container.ImagePullPolicy != corev1.PullAlways { + // fmt.Println("ImagePullPolicy is set to " + container.ImagePullPolicy) + // return false + // } + // } + // return true + // }, "3m", "5s").Should(BeTrue()) + + // By("updating image pull policy env variable to Never") + + // fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Never") + // defer func() { + // By("removing IMAGE_PULL_POLICY environment variable to restore default behavior") + // fixture.RestoreSubcriptionToDefault() + // }() + + // By("verifying backend deployment has ImagePullPolicy changed based on env variable") + // Eventually(func() bool { + // err := k8sClient.Get(ctx, client.ObjectKeyFromObject(clusterDepl), clusterDepl) + // if err != nil { + // return false + // } + // for _, container := range clusterDepl.Spec.Template.Spec.Containers { + // if container.ImagePullPolicy != corev1.PullNever { + // return false + // } + // } + // return true + // }, "3m", "5s").Should(BeTrue()) + + // By("verifying plugin deployment has ImagePullPolicy changed based on env variable") + + // Eventually(func() bool { + // err := k8sClient.Get(ctx, client.ObjectKeyFromObject(pluginDepl), pluginDepl) + // if err != nil { + // return false + // } + // for _, container := range pluginDepl.Spec.Template.Spec.Containers { + // if container.ImagePullPolicy != corev1.PullNever { + // return false + // } + // } + // return true + // }, "3m", "5s").Should(BeTrue()) + + // fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "IfNotPresent") + // defer func() { + // By("removing IMAGE_PULL_POLICY environment variable to restore default behavior") + // fixture.RestoreSubcriptionToDefault() + // }() + + // By("verifying backend deployment has ImagePullPolicy changed based on env variable") + // Eventually(func() bool { + // err := k8sClient.Get(ctx, client.ObjectKeyFromObject(clusterDepl), clusterDepl) + // if err != nil { + // return false + // } + // for _, container := range clusterDepl.Spec.Template.Spec.Containers { + // if container.ImagePullPolicy != corev1.PullIfNotPresent { + // return false + // } + // } + // return true + // }, "3m", "5s").Should(BeTrue()) + + // By("verifying plugin deployment has ImagePullPolicy changed based on env variable") + + // Eventually(func() bool { + // err := k8sClient.Get(ctx, client.ObjectKeyFromObject(pluginDepl), pluginDepl) + // if err != nil { + // return false + // } + // for _, container := range pluginDepl.Spec.Template.Spec.Containers { + // if container.ImagePullPolicy != corev1.PullIfNotPresent { + // return false + // } + // } + // return true + // }, "3m", "5s").Should(BeTrue()) + // }) }) })