Skip to content

Commit

Permalink
Add appendUnique args logic to all the cases
Browse files Browse the repository at this point in the history
Signed-off-by: Rizwana777 <[email protected]>
  • Loading branch information
Rizwana777 committed Dec 3, 2024
1 parent 0079ddb commit 33b914b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
7 changes: 1 addition & 6 deletions controllers/argocd/applicationset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
37 changes: 36 additions & 1 deletion controllers/argocd/applicationset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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{}
Expand All @@ -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) {
Expand Down
6 changes: 1 addition & 5 deletions controllers/argocd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 6 additions & 1 deletion controllers/argocd/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 33b914b

Please sign in to comment.