Skip to content

Commit a09f458

Browse files
committed
removed unwanted code from imagepullpolicy ginkgo test case
Signed-off-by: Alka Kumari <alkumari@redhat.com>
1 parent b17a23b commit a09f458

File tree

2 files changed

+20
-69
lines changed

2 files changed

+20
-69
lines changed

test/openshift/e2e/ginkgo/fixture/fixture.go

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -636,61 +636,6 @@ func WaitForAllDeploymentsInTheNamespaceToBeReady(ns string, k8sClient client.Cl
636636

637637
}
638638

639-
func AddEnvVarToCSV(csv *olmv1alpha1.ClusterServiceVersion, envKey string, value string) {
640-
containers := csv.Spec.InstallStrategy.StrategySpec.DeploymentSpecs[0].Spec.Template.Spec.Containers
641-
for i := range containers {
642-
found := false
643-
for j := range containers[i].Env {
644-
if containers[i].Env[j].Name == envKey {
645-
containers[i].Env[j].Value = value
646-
found = true
647-
break
648-
}
649-
}
650-
if !found {
651-
containers[i].Env = append(containers[i].Env, corev1.EnvVar{Name: envKey, Value: value})
652-
}
653-
}
654-
}
655-
656-
// WaitForOperatorPodToHaveEnvVar waits for the operator pod to have the specified environment variable with the expected value.
657-
// This ensures that after updating the subscription, the operator pod has actually restarted with the new env var.
658-
func WaitForOperatorPodToHaveEnvVar(ns string, envKey string, expectedValue string, k8sClient client.Client) {
659-
Eventually(func() bool {
660-
var deplList appsv1.DeploymentList
661-
if err := k8sClient.List(context.Background(), &deplList, client.InNamespace(ns)); err != nil {
662-
GinkgoWriter.Println(err)
663-
return false
664-
}
665-
666-
for _, depl := range deplList.Items {
667-
// Look for the operator deployment (typically contains "controller-manager" or "operator")
668-
if !strings.Contains(depl.Name, "operator") && !strings.Contains(depl.Name, "controller-manager") {
669-
continue
670-
}
671-
672-
// Check if the deployment's pod template has the expected env var
673-
for _, container := range depl.Spec.Template.Spec.Containers {
674-
for _, env := range container.Env {
675-
if env.Name == envKey {
676-
if env.Value == expectedValue {
677-
// Found the env var with the expected value
678-
// Now verify the deployment is fully rolled out with this change
679-
if depl.Generation == depl.Status.ObservedGeneration &&
680-
depl.Status.Replicas == depl.Status.ReadyReplicas &&
681-
depl.Status.UpdatedReplicas == depl.Status.Replicas {
682-
return true
683-
}
684-
}
685-
break
686-
}
687-
}
688-
}
689-
}
690-
return false
691-
}, "5m", "5s").Should(BeTrue())
692-
}
693-
694639
func WaitForAllStatefulSetsInTheNamespaceToBeReady(ns string, k8sClient client.Client) {
695640

696641
Eventually(func() bool {

test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package sequential
1919
import (
2020
"context"
2121
"fmt"
22-
"os"
2322
"strings"
2423

2524
. "github.com/onsi/ginkgo/v2"
@@ -280,14 +279,11 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
280279

281280
By("adding image pull policy env variable IMAGE_PULL_POLICY in Subscription")
282281

283-
fixture.AddEnvVarToCSV(csv, "IMAGE_PULL_POLICY", "Always")
284-
//fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Always")
285-
Expect(k8sClient.Update(ctx, csv)).To(Succeed())
282+
fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Always")
286283
defer func() {
287284
By("removing IMAGE_PULL_POLICY environment variable to restore default behavior")
288285
fixture.RestoreSubcriptionToDefault()
289286
}()
290-
fixture.WaitForOperatorPodToHaveEnvVar("openshift-gitops-operator", "IMAGE_PULL_POLICY", "Always", k8sClient)
291287

292288
By("verifying Argo CD in openshift-gitops exists and is available")
293289
argoCD, err := argocdFixture.GetOpenShiftGitOpsNSArgoCD()
@@ -302,17 +298,33 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
302298
}
303299
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(gitopsService), gitopsService)).To(Succeed())
304300

301+
By("printing deployment ImagePullPolicy")
302+
deployment := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: "openshift-gitops"}}
303+
for _, container := range deployment.Spec.Template.Spec.Containers {
304+
fmt.Println("Container: " + container.Name + " is " + string(container.ImagePullPolicy))
305+
}
306+
305307
By("verifying backend deployment has ImagePullPolicy set based on env variable")
306308
clusterDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: argoCD.Namespace}}
307309
Eventually(clusterDepl).Should(k8sFixture.ExistByName())
310+
fmt.Println("Printing the list of deployment env variables")
311+
envList := clusterDepl.Spec.Template.Spec.Containers[0].Env
312+
for _, env := range envList {
313+
fmt.Println("Env: " + env.Name + " is " + env.Value)
314+
}
315+
316+
envValue, err := fixture.GetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY")
317+
Expect(err).ToNot(HaveOccurred())
318+
fmt.Println("EnvValue: " + string(*envValue))
319+
308320
Eventually(func() bool {
309321
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(clusterDepl), clusterDepl)
310322
if err != nil {
311323
return false
312324
}
313325
for _, container := range clusterDepl.Spec.Template.Spec.Containers {
314326
if container.ImagePullPolicy != corev1.PullAlways {
315-
fmt.Println("ImagePullPolicy is set to " + string(container.ImagePullPolicy) + " but expected " + os.Getenv("IMAGE_PULL_POLICY"))
327+
fmt.Println("ImagePullPolicy is set to " + string(container.ImagePullPolicy))
316328
return false
317329
}
318330
}
@@ -338,14 +350,11 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
338350

339351
By("updating image pull policy env variable to Never")
340352

341-
//fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Never")
342-
fixture.AddEnvVarToCSV(csv, "IMAGE_PULL_POLICY", "Never")
343-
Expect(k8sClient.Update(ctx, csv)).To(Succeed())
353+
fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Never")
344354
defer func() {
345355
By("removing IMAGE_PULL_POLICY environment variable to restore default behavior")
346356
fixture.RestoreSubcriptionToDefault()
347357
}()
348-
fixture.WaitForOperatorPodToHaveEnvVar("openshift-gitops-operator", "IMAGE_PULL_POLICY", "Never", k8sClient)
349358

350359
By("verifying backend deployment has ImagePullPolicy changed based on env variable")
351360
Eventually(func() bool {
@@ -376,14 +385,11 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
376385
return true
377386
}, "3m", "5s").Should(BeTrue())
378387

379-
//fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "IfNotPresent")
380-
fixture.AddEnvVarToCSV(csv, "IMAGE_PULL_POLICY", "IfNotPresent")
381-
Expect(k8sClient.Update(ctx, csv)).To(Succeed())
388+
fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "IfNotPresent")
382389
defer func() {
383390
By("removing IMAGE_PULL_POLICY environment variable to restore default behavior")
384391
fixture.RestoreSubcriptionToDefault()
385392
}()
386-
fixture.WaitForOperatorPodToHaveEnvVar("openshift-gitops-operator", "IMAGE_PULL_POLICY", "IfNotPresent", k8sClient)
387393

388394
By("verifying backend deployment has ImagePullPolicy changed based on env variable")
389395
Eventually(func() bool {

0 commit comments

Comments
 (0)