diff --git a/test/openshift/e2e/ginkgo/fixture/deployment/fixture.go b/test/openshift/e2e/ginkgo/fixture/deployment/fixture.go index d04afe677..146d29ebd 100644 --- a/test/openshift/e2e/ginkgo/fixture/deployment/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/deployment/fixture.go @@ -19,7 +19,7 @@ import ( "k8s.io/client-go/util/retry" ) -func GetEnv(d *appsv1.Deployment, key string) (*string, error) { +func GetEnv(d *appsv1.Deployment, container string, key string) (*string, error) { k8sClient, _, err := utils.GetE2ETestKubeClientWithError() if err != nil { @@ -32,76 +32,80 @@ func GetEnv(d *appsv1.Deployment, key string) (*string, error) { containers := d.Spec.Template.Spec.Containers - Expect(containers).Should(HaveLen(1)) + for idc := range containers { - for idx := range containers[0].Env { + if containers[idc].Name == container { + for idx := range containers[idc].Env { - currEnv := containers[0].Env[idx] + currEnv := containers[idc].Env[idx] - if currEnv.Name == key { - return &currEnv.Name, nil + if currEnv.Name == key { + return &currEnv.Name, nil + } + } } } - return nil, nil } -func SetEnv(depl *appsv1.Deployment, key string, value string) { +func SetEnv(depl *appsv1.Deployment, container string, key string, value string) { Update(depl, func(d *appsv1.Deployment) { containers := d.Spec.Template.Spec.Containers - Expect(containers).Should(HaveLen(1)) - newEnvVars := []corev1.EnvVar{} match := false - for idx := range containers[0].Env { + for idc := range containers { - currEnv := containers[0].Env[idx] + if containers[idc].Name == container { + for idx := range containers[idc].Env { - if currEnv.Name == key { - // replace with the value from the param - newEnvVars = append(newEnvVars, corev1.EnvVar{Name: key, Value: value}) - match = true - } else { - newEnvVars = append(newEnvVars, currEnv) - } - } + currEnv := containers[idc].Env[idx] - if !match { - newEnvVars = append(newEnvVars, corev1.EnvVar{Name: key, Value: value}) - } + if currEnv.Name == key { + // replace with the value from the param + newEnvVars = append(newEnvVars, corev1.EnvVar{Name: key, Value: value}) + match = true + } else { + newEnvVars = append(newEnvVars, currEnv) + } + } - containers[0].Env = newEnvVars + if !match { + newEnvVars = append(newEnvVars, corev1.EnvVar{Name: key, Value: value}) + } + containers[idc].Env = newEnvVars + } + } }) } -func RemoveEnv(depl *appsv1.Deployment, key string) { +func RemoveEnv(depl *appsv1.Deployment, container string, key string) { Update(depl, func(d *appsv1.Deployment) { containers := d.Spec.Template.Spec.Containers - Expect(containers).Should(HaveLen(1)) - - newEnvVars := []corev1.EnvVar{} + for idc := range containers { + if containers[idc].Name == container { + newEnvVars := []corev1.EnvVar{} + for idx := range containers[idc].Env { - for idx := range containers[0].Env { + currEnv := containers[idc].Env[idx] - currEnv := containers[0].Env[idx] + if currEnv.Name == key { + // don't add, thus causing it to be removed + } else { + newEnvVars = append(newEnvVars, currEnv) + } + } - if currEnv.Name == key { - // don't add, thus causing it to be removed - } else { - newEnvVars = append(newEnvVars, currEnv) + containers[idc].Env = newEnvVars } } - - containers[0].Env = newEnvVars - }) } diff --git a/test/openshift/e2e/ginkgo/fixture/fixture.go b/test/openshift/e2e/ginkgo/fixture/fixture.go index 9c3d0c103..adeafc6e5 100644 --- a/test/openshift/e2e/ginkgo/fixture/fixture.go +++ b/test/openshift/e2e/ginkgo/fixture/fixture.go @@ -377,7 +377,7 @@ func GetEnvInOperatorSubscriptionOrDeployment(key string) (*string, error) { if EnvNonOLM() { depl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator-controller-manager", Namespace: "openshift-gitops-operator"}} - return deploymentFixture.GetEnv(depl, key) + return deploymentFixture.GetEnv(depl, "manager", key) } else if EnvCI() { @@ -414,7 +414,7 @@ func SetEnvInOperatorSubscriptionOrDeployment(key string, value string) { if EnvNonOLM() { depl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator-controller-manager", Namespace: "openshift-gitops-operator"}} - deploymentFixture.SetEnv(depl, key, value) + deploymentFixture.SetEnv(depl, "manager", key, value) WaitForAllDeploymentsInTheNamespaceToBeReady("openshift-gitops-operator", k8sClient) @@ -451,7 +451,7 @@ func RemoveEnvFromOperatorSubscriptionOrDeployment(key string) error { if EnvNonOLM() { depl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator-controller-manager", Namespace: "openshift-gitops-operator"}} - deploymentFixture.RemoveEnv(depl, key) + deploymentFixture.RemoveEnv(depl, "manager", key) WaitForAllDeploymentsInTheNamespaceToBeReady("openshift-gitops-operator", k8sClient) @@ -518,7 +518,7 @@ func RestoreSubcriptionToDefault() { depl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator-controller-manager", Namespace: "openshift-gitops-operator"}} for _, envKey := range optionalEnvVarsToRemove { - deploymentFixture.RemoveEnv(depl, envKey) + deploymentFixture.RemoveEnv(depl, "manager", envKey) } err := waitForAllEnvVarsToBeRemovedFromDeployments(depl.Namespace, optionalEnvVarsToRemove, k8sClient)