Skip to content

Commit 337c5e3

Browse files
committed
Add appendUnique args logic to all the cases
1 parent 0079ddb commit 337c5e3

File tree

4 files changed

+44
-13
lines changed

4 files changed

+44
-13
lines changed

controllers/argocd/applicationset.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,7 @@ func (r *ReconcileArgoCD) getArgoApplicationSetCommand(cr *argoproj.ArgoCD) []st
9393

9494
// ApplicationSet command arguments provided by the user
9595
extraArgs := cr.Spec.ApplicationSet.ExtraCommandArgs
96-
err = isMergable(extraArgs, cmd)
97-
if err != nil {
98-
return cmd
99-
}
100-
101-
cmd = append(cmd, extraArgs...)
96+
cmd = appendUniqueArgs(cmd, extraArgs)
10297

10398
return cmd
10499
}

controllers/argocd/applicationset_test.go

+36-1
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,15 @@ func TestArgoCDApplicationSetCommand(t *testing.T) {
941941
"bar",
942942
}
943943

944+
wantCmd := []string{
945+
"entrypoint.sh",
946+
"argocd-applicationset-controller",
947+
"--argocd-repo-server",
948+
"foo.scv.cluster.local:6379",
949+
"--loglevel",
950+
"info",
951+
}
952+
944953
deployment := &appsv1.Deployment{}
945954
assert.NoError(t, r.reconcileApplicationSetController(a))
946955

@@ -991,7 +1000,7 @@ func TestArgoCDApplicationSetCommand(t *testing.T) {
9911000
},
9921001
deployment))
9931002

994-
assert.Equal(t, baseCommand, deployment.Spec.Template.Spec.Containers[0].Command)
1003+
assert.Equal(t, wantCmd, deployment.Spec.Template.Spec.Containers[0].Command)
9951004

9961005
// Remove all the command arguments that were added.
9971006
a.Spec.ApplicationSet.ExtraCommandArgs = []string{}
@@ -1006,6 +1015,32 @@ func TestArgoCDApplicationSetCommand(t *testing.T) {
10061015
deployment))
10071016

10081017
assert.Equal(t, baseCommand, deployment.Spec.Template.Spec.Containers[0].Command)
1018+
1019+
// When ExtraCommandArgs contains a non-duplicate argument along with a duplicate
1020+
a.Spec.ApplicationSet.ExtraCommandArgs = []string{
1021+
"--foo",
1022+
"bar",
1023+
"--ping",
1024+
"pong",
1025+
"test",
1026+
"--newarg", // Non-duplicate argument
1027+
"newvalue",
1028+
"--newarg", // Duplicate argument passing at once
1029+
"newvalue",
1030+
}
1031+
1032+
assert.NoError(t, r.reconcileApplicationSetController(a))
1033+
assert.NoError(t, r.Client.Get(
1034+
context.TODO(),
1035+
types.NamespacedName{
1036+
Name: "argocd-applicationset-controller",
1037+
Namespace: a.Namespace,
1038+
},
1039+
deployment))
1040+
1041+
// Non-duplicate argument "--newarg" should be added, duplicate "--newarg" which is added twice is ignored
1042+
cmd = append(cmd, "--newarg", "newvalue")
1043+
assert.Equal(t, cmd, deployment.Spec.Template.Spec.Containers[0].Command)
10091044
}
10101045

10111046
func TestArgoCDApplicationSetEnv(t *testing.T) {

controllers/argocd/util.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,7 @@ func getArgoApplicationControllerCommand(cr *argoproj.ArgoCD, useTLSForRedis boo
176176

177177
// check if extra args are present
178178
extraArgs := cr.Spec.Controller.ExtraCommandArgs
179-
err := isMergable(extraArgs, cmd)
180-
if err != nil {
181-
return cmd
182-
}
183-
cmd = append(cmd, extraArgs...)
179+
cmd = appendUniqueArgs(cmd, extraArgs)
184180

185181
return cmd
186182
}

controllers/argocd/util_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -582,13 +582,18 @@ func TestGetArgoApplicationControllerCommand(t *testing.T) {
582582
{
583583
"overriding default argument using extraCommandArgs",
584584
[]argoCDOpt{extraCommandArgs([]string{"--operation-processors", "15"})},
585-
defaultResult,
585+
operationProcesorsChangedResult("15"),
586586
},
587587
{
588588
"configured empty extraCommandArgs",
589589
[]argoCDOpt{extraCommandArgs([]string{})},
590590
defaultResult,
591591
},
592+
{
593+
"configured extraCommandArgs with duplicate values",
594+
[]argoCDOpt{extraCommandArgs([]string{"--status-processors", "20"})},
595+
defaultResult,
596+
},
592597
}
593598

594599
for _, tt := range cmdTests {

0 commit comments

Comments
 (0)