diff --git a/controllers/argocd/applicationset.go b/controllers/argocd/applicationset.go index 9dd5dafbf..64757d463 100644 --- a/controllers/argocd/applicationset.go +++ b/controllers/argocd/applicationset.go @@ -761,25 +761,24 @@ func (r *ReconcileArgoCD) reconcileApplicationSetRoleBinding(cr *argoproj.ArgoCD } func getApplicationSetContainerImage(cr *argoproj.ArgoCD) string { - defaultImg, defaultTag := false, false - - img := "" - tag := "" - - // First pull from spec, if it exists - if cr.Spec.ApplicationSet != nil { - img = cr.Spec.ApplicationSet.Image - tag = cr.Spec.ApplicationSet.Version - } - // If spec is empty, use the defaults + defaultImg, defaultTag := false, false + img := cr.Spec.ApplicationSet.Image if img == "" { - img = common.ArgoCDDefaultArgoImage - defaultImg = true + img = cr.Spec.Image + if img == "" { + img = common.ArgoCDDefaultArgoImage + defaultImg = true + } } + + tag := cr.Spec.ApplicationSet.Version if tag == "" { - tag = common.ArgoCDDefaultArgoVersion - defaultTag = true + tag = cr.Spec.Version + if tag == "" { + tag = common.ArgoCDDefaultArgoVersion + defaultTag = true + } } // If an env var is specified then use that, but don't override the spec values (if they are present) diff --git a/controllers/argocd/applicationset_test.go b/controllers/argocd/applicationset_test.go index dee07044e..e2ae546d5 100644 --- a/controllers/argocd/applicationset_test.go +++ b/controllers/argocd/applicationset_test.go @@ -344,9 +344,31 @@ func TestReconcileApplicationSet_Deployments_SpecOverride(t *testing.T) { tests := []struct { name string appSetField *argoproj.ArgoCDApplicationSet + argocdField argoproj.ArgoCDSpec envVars map[string]string expectedContainerImage string }{ + { + name: "fields are set in argocd spec and not on appsetspec", + appSetField: &argoproj.ArgoCDApplicationSet{}, + argocdField: argoproj.ArgoCDSpec{ + Image: "test", + Version: "sha256:b835999eb5cf75d01a2678cd971095926d9c2566c9ffe746d04b83a6a0a2849f", + }, + expectedContainerImage: "test@sha256:b835999eb5cf75d01a2678cd971095926d9c2566c9ffe746d04b83a6a0a2849f", + }, + { + name: "fields are set in both argocdSpec and on appsetSpec", + appSetField: &argoproj.ArgoCDApplicationSet{ + Image: "custom-image", + Version: "sha256:b835999eb5cf75d01a2678cd971095926d9c2566c9ffe746d04b83a6a0a2849f", + }, + argocdField: argoproj.ArgoCDSpec{ + Image: "test", + Version: "sha256:b835999eb5cf75d01a2678cd9710952566c9ffe746d04b83a6a0a2849f926d9c", + }, + expectedContainerImage: "custom-image@sha256:b835999eb5cf75d01a2678cd971095926d9c2566c9ffe746d04b83a6a0a2849f", + }, { name: "unspecified fields should use default", appSetField: &argoproj.ArgoCDApplicationSet{}, @@ -411,6 +433,11 @@ func TestReconcileApplicationSet_Deployments_SpecOverride(t *testing.T) { cm := newConfigMapWithName(getCAConfigMapName(a), a) r.Client.Create(context.Background(), cm, &client.CreateOptions{}) + if test.argocdField.Image != "" { + a.Spec.Image = test.argocdField.Image + a.Spec.Version = test.argocdField.Version + } + a.Spec.ApplicationSet = test.appSetField sa := corev1.ServiceAccount{}