Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for image override for argocd-extension #1590

Merged
Merged
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
4 changes: 4 additions & 0 deletions common/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ const (
// to used for the argocd container.
ArgoCDImageEnvName = "ARGOCD_IMAGE"

// ArgoCDExtensionImageEnvName is the environment variable used to get the image
// to be used for the Argo-CD extension image
ArgoCDExtensionImageEnvName = "ARGOCD_EXTENSION_IMAGE"

// ArgoCDKeycloakImageEnvName is the environment variable used to get the image
// to used for the Keycloak container.
ArgoCDKeycloakImageEnvName = "ARGOCD_KEYCLOAK_IMAGE"
Expand Down
23 changes: 14 additions & 9 deletions controllers/argocd/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -1564,16 +1564,9 @@ func updateNodePlacement(existing *appsv1.Deployment, deploy *appsv1.Deployment,
}

func getRolloutInitContainer() []corev1.Container {
return []corev1.Container{
containers := []corev1.Container{
{
Name: "rollout-extension",
Image: common.ArgoCDExtensionInstallerImage,
Env: []corev1.EnvVar{
{
Name: "EXTENSION_URL",
Value: common.ArgoRolloutsExtensionURL,
},
},
Name: "rollout-extension",
VolumeMounts: []corev1.VolumeMount{
{
Name: "extensions",
Expand All @@ -1593,6 +1586,18 @@ func getRolloutInitContainer() []corev1.Container {
},
},
}

if value, exists := os.LookupEnv(common.ArgoCDExtensionImageEnvName); exists {
containers[0].Image = value
} else {
containers[0].Image = common.ArgoCDExtensionInstallerImage
containers[0].Env = []corev1.EnvVar{
{
Name: "EXTENSION_URL",
Value: common.ArgoRolloutsExtensionURL,
}}
}
return containers
}

func removeInitContainer(initContainers []corev1.Container, name string) []corev1.Container {
Expand Down
42 changes: 42 additions & 0 deletions controllers/argocd/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package argocd
import (
"context"
"fmt"
"os"
"reflect"
"strings"
"testing"
Expand Down Expand Up @@ -2409,3 +2410,44 @@ func TestReconcileArgoCD_reconcileRepoServerWithRemote(t *testing.T) {
assert.NoError(t, r.reconcileRepoDeployment(cr, false))
assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: cr.Name + "-repo-server", Namespace: cr.Namespace}, d))
}

func Test_getRolloutInitContainer(t *testing.T) {
tests := []struct {
name string
envSet bool
wantImage string
wantEnv []corev1.EnvVar
}{
{
name: "when running in argocd-operator",
envSet: false,
wantImage: "quay.io/argoprojlabs/argocd-extension-installer:v0.0.8",
wantEnv: []corev1.EnvVar{
{
Name: "EXTENSION_URL",
Value: common.ArgoRolloutsExtensionURL,
},
},
},
{
name: "when running in gitops-operator",
envSet: true,
wantImage: "updated_container",
wantEnv: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.envSet {
err := os.Setenv(common.ArgoCDExtensionImageEnvName, "updated_container")
assert.NoError(t, err)
}

containers := getRolloutInitContainer()

assert.Equalf(t, tt.wantImage, containers[0].Image, "Image check")
assert.Equalf(t, tt.wantEnv, containers[0].Env, "Env check")

})
}
}
Loading