From 33b914bff3290a391a15b4cc6778a1c728bd7e39 Mon Sep 17 00:00:00 2001 From: Rizwana777 Date: Tue, 3 Dec 2024 22:04:49 +0530 Subject: [PATCH] Add appendUnique args logic to all the cases Signed-off-by: Rizwana777 --- controllers/argocd/applicationset.go | 7 +---- controllers/argocd/applicationset_test.go | 37 ++++++++++++++++++++++- controllers/argocd/util.go | 6 +--- controllers/argocd/util_test.go | 7 ++++- 4 files changed, 44 insertions(+), 13 deletions(-) diff --git a/controllers/argocd/applicationset.go b/controllers/argocd/applicationset.go index 0187b1d82..e78ae256b 100644 --- a/controllers/argocd/applicationset.go +++ b/controllers/argocd/applicationset.go @@ -93,12 +93,7 @@ func (r *ReconcileArgoCD) getArgoApplicationSetCommand(cr *argoproj.ArgoCD) []st // ApplicationSet command arguments provided by the user extraArgs := cr.Spec.ApplicationSet.ExtraCommandArgs - err = isMergable(extraArgs, cmd) - if err != nil { - return cmd - } - - cmd = append(cmd, extraArgs...) + cmd = appendUniqueArgs(cmd, extraArgs) return cmd } diff --git a/controllers/argocd/applicationset_test.go b/controllers/argocd/applicationset_test.go index e2ae546d5..7a991f583 100644 --- a/controllers/argocd/applicationset_test.go +++ b/controllers/argocd/applicationset_test.go @@ -941,6 +941,15 @@ func TestArgoCDApplicationSetCommand(t *testing.T) { "bar", } + wantCmd := []string{ + "entrypoint.sh", + "argocd-applicationset-controller", + "--argocd-repo-server", + "foo.scv.cluster.local:6379", + "--loglevel", + "info", + } + deployment := &appsv1.Deployment{} assert.NoError(t, r.reconcileApplicationSetController(a)) @@ -991,7 +1000,7 @@ func TestArgoCDApplicationSetCommand(t *testing.T) { }, deployment)) - assert.Equal(t, baseCommand, deployment.Spec.Template.Spec.Containers[0].Command) + assert.Equal(t, wantCmd, deployment.Spec.Template.Spec.Containers[0].Command) // Remove all the command arguments that were added. a.Spec.ApplicationSet.ExtraCommandArgs = []string{} @@ -1006,6 +1015,32 @@ func TestArgoCDApplicationSetCommand(t *testing.T) { deployment)) assert.Equal(t, baseCommand, deployment.Spec.Template.Spec.Containers[0].Command) + + // When ExtraCommandArgs contains a non-duplicate argument along with a duplicate + a.Spec.ApplicationSet.ExtraCommandArgs = []string{ + "--foo", + "bar", + "--ping", + "pong", + "test", + "--newarg", // Non-duplicate argument + "newvalue", + "--newarg", // Duplicate argument passing at once + "newvalue", + } + + assert.NoError(t, r.reconcileApplicationSetController(a)) + assert.NoError(t, r.Client.Get( + context.TODO(), + types.NamespacedName{ + Name: "argocd-applicationset-controller", + Namespace: a.Namespace, + }, + deployment)) + + // Non-duplicate argument "--newarg" should be added, duplicate "--newarg" which is added twice is ignored + cmd = append(cmd, "--newarg", "newvalue") + assert.Equal(t, cmd, deployment.Spec.Template.Spec.Containers[0].Command) } func TestArgoCDApplicationSetEnv(t *testing.T) { diff --git a/controllers/argocd/util.go b/controllers/argocd/util.go index 323b00ebc..0f8ad2cd3 100644 --- a/controllers/argocd/util.go +++ b/controllers/argocd/util.go @@ -176,11 +176,7 @@ func getArgoApplicationControllerCommand(cr *argoproj.ArgoCD, useTLSForRedis boo // check if extra args are present extraArgs := cr.Spec.Controller.ExtraCommandArgs - err := isMergable(extraArgs, cmd) - if err != nil { - return cmd - } - cmd = append(cmd, extraArgs...) + cmd = appendUniqueArgs(cmd, extraArgs) return cmd } diff --git a/controllers/argocd/util_test.go b/controllers/argocd/util_test.go index 020526183..7ae780c98 100644 --- a/controllers/argocd/util_test.go +++ b/controllers/argocd/util_test.go @@ -582,13 +582,18 @@ func TestGetArgoApplicationControllerCommand(t *testing.T) { { "overriding default argument using extraCommandArgs", []argoCDOpt{extraCommandArgs([]string{"--operation-processors", "15"})}, - defaultResult, + operationProcesorsChangedResult("15"), }, { "configured empty extraCommandArgs", []argoCDOpt{extraCommandArgs([]string{})}, defaultResult, }, + { + "configured extraCommandArgs with duplicate values", + []argoCDOpt{extraCommandArgs([]string{"--status-processors", "20"})}, + defaultResult, + }, } for _, tt := range cmdTests {