Skip to content

Commit 0c1f08e

Browse files
authored
fix: allow argocd spec.image to override default image for appset controller (argoproj-labs#1523)
* fix: allow argocd spec.image to override default image for appset controller Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com> * fix logic Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com> --------- Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>
1 parent e3bb558 commit 0c1f08e

File tree

2 files changed

+41
-15
lines changed

2 files changed

+41
-15
lines changed

controllers/argocd/applicationset.go

+14-15
Original file line numberDiff line numberDiff line change
@@ -761,25 +761,24 @@ func (r *ReconcileArgoCD) reconcileApplicationSetRoleBinding(cr *argoproj.ArgoCD
761761
}
762762

763763
func getApplicationSetContainerImage(cr *argoproj.ArgoCD) string {
764-
defaultImg, defaultTag := false, false
765-
766-
img := ""
767-
tag := ""
768-
769-
// First pull from spec, if it exists
770-
if cr.Spec.ApplicationSet != nil {
771-
img = cr.Spec.ApplicationSet.Image
772-
tag = cr.Spec.ApplicationSet.Version
773-
}
774764

775-
// If spec is empty, use the defaults
765+
defaultImg, defaultTag := false, false
766+
img := cr.Spec.ApplicationSet.Image
776767
if img == "" {
777-
img = common.ArgoCDDefaultArgoImage
778-
defaultImg = true
768+
img = cr.Spec.Image
769+
if img == "" {
770+
img = common.ArgoCDDefaultArgoImage
771+
defaultImg = true
772+
}
779773
}
774+
775+
tag := cr.Spec.ApplicationSet.Version
780776
if tag == "" {
781-
tag = common.ArgoCDDefaultArgoVersion
782-
defaultTag = true
777+
tag = cr.Spec.Version
778+
if tag == "" {
779+
tag = common.ArgoCDDefaultArgoVersion
780+
defaultTag = true
781+
}
783782
}
784783

785784
// If an env var is specified then use that, but don't override the spec values (if they are present)

controllers/argocd/applicationset_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,31 @@ func TestReconcileApplicationSet_Deployments_SpecOverride(t *testing.T) {
344344
tests := []struct {
345345
name string
346346
appSetField *argoproj.ArgoCDApplicationSet
347+
argocdField argoproj.ArgoCDSpec
347348
envVars map[string]string
348349
expectedContainerImage string
349350
}{
351+
{
352+
name: "fields are set in argocd spec and not on appsetspec",
353+
appSetField: &argoproj.ArgoCDApplicationSet{},
354+
argocdField: argoproj.ArgoCDSpec{
355+
Image: "test",
356+
Version: "sha256:b835999eb5cf75d01a2678cd971095926d9c2566c9ffe746d04b83a6a0a2849f",
357+
},
358+
expectedContainerImage: "test@sha256:b835999eb5cf75d01a2678cd971095926d9c2566c9ffe746d04b83a6a0a2849f",
359+
},
360+
{
361+
name: "fields are set in both argocdSpec and on appsetSpec",
362+
appSetField: &argoproj.ArgoCDApplicationSet{
363+
Image: "custom-image",
364+
Version: "sha256:b835999eb5cf75d01a2678cd971095926d9c2566c9ffe746d04b83a6a0a2849f",
365+
},
366+
argocdField: argoproj.ArgoCDSpec{
367+
Image: "test",
368+
Version: "sha256:b835999eb5cf75d01a2678cd9710952566c9ffe746d04b83a6a0a2849f926d9c",
369+
},
370+
expectedContainerImage: "custom-image@sha256:b835999eb5cf75d01a2678cd971095926d9c2566c9ffe746d04b83a6a0a2849f",
371+
},
350372
{
351373
name: "unspecified fields should use default",
352374
appSetField: &argoproj.ArgoCDApplicationSet{},
@@ -411,6 +433,11 @@ func TestReconcileApplicationSet_Deployments_SpecOverride(t *testing.T) {
411433
cm := newConfigMapWithName(getCAConfigMapName(a), a)
412434
r.Client.Create(context.Background(), cm, &client.CreateOptions{})
413435

436+
if test.argocdField.Image != "" {
437+
a.Spec.Image = test.argocdField.Image
438+
a.Spec.Version = test.argocdField.Version
439+
}
440+
414441
a.Spec.ApplicationSet = test.appSetField
415442

416443
sa := corev1.ServiceAccount{}

0 commit comments

Comments
 (0)