Skip to content

Commit

Permalink
fix: allow argocd spec.image to override default image for appset con…
Browse files Browse the repository at this point in the history
…troller (argoproj-labs#1523)

* fix: allow argocd spec.image to override default image for appset controller

Signed-off-by: Anand Kumar Singh <[email protected]>

* fix logic

Signed-off-by: Anand Kumar Singh <[email protected]>

---------

Signed-off-by: Anand Kumar Singh <[email protected]>
  • Loading branch information
anandrkskd authored Aug 29, 2024
1 parent e3bb558 commit 0c1f08e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
29 changes: 14 additions & 15 deletions controllers/argocd/applicationset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions controllers/argocd/applicationset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down Expand Up @@ -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{}
Expand Down

0 comments on commit 0c1f08e

Please sign in to comment.