Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 41 additions & 37 deletions test/openshift/e2e/ginkgo/fixture/deployment/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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

})

}
Expand Down
8 changes: 4 additions & 4 deletions test/openshift/e2e/ginkgo/fixture/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down