Skip to content

Commit b17a23b

Browse files
committed
changed logic to set env variable in csv
Signed-off-by: Alka Kumari <alkumari@redhat.com>
1 parent 9ceb438 commit b17a23b

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,23 @@ 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+
639656
// WaitForOperatorPodToHaveEnvVar waits for the operator pod to have the specified environment variable with the expected value.
640657
// This ensures that after updating the subscription, the operator pod has actually restarted with the new env var.
641658
func WaitForOperatorPodToHaveEnvVar(ns string, envKey string, expectedValue string, k8sClient client.Client) {

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
280280

281281
By("adding image pull policy env variable IMAGE_PULL_POLICY in Subscription")
282282

283-
fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Always")
283+
fixture.AddEnvVarToCSV(csv, "IMAGE_PULL_POLICY", "Always")
284+
//fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Always")
285+
Expect(k8sClient.Update(ctx, csv)).To(Succeed())
284286
defer func() {
285287
By("removing IMAGE_PULL_POLICY environment variable to restore default behavior")
286288
fixture.RestoreSubcriptionToDefault()
@@ -336,7 +338,9 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
336338

337339
By("updating image pull policy env variable to Never")
338340

339-
fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Never")
341+
//fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "Never")
342+
fixture.AddEnvVarToCSV(csv, "IMAGE_PULL_POLICY", "Never")
343+
Expect(k8sClient.Update(ctx, csv)).To(Succeed())
340344
defer func() {
341345
By("removing IMAGE_PULL_POLICY environment variable to restore default behavior")
342346
fixture.RestoreSubcriptionToDefault()
@@ -372,7 +376,9 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
372376
return true
373377
}, "3m", "5s").Should(BeTrue())
374378

375-
fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "IfNotPresent")
379+
//fixture.SetEnvInOperatorSubscriptionOrDeployment("IMAGE_PULL_POLICY", "IfNotPresent")
380+
fixture.AddEnvVarToCSV(csv, "IMAGE_PULL_POLICY", "IfNotPresent")
381+
Expect(k8sClient.Update(ctx, csv)).To(Succeed())
376382
defer func() {
377383
By("removing IMAGE_PULL_POLICY environment variable to restore default behavior")
378384
fixture.RestoreSubcriptionToDefault()

0 commit comments

Comments
 (0)