@@ -49,8 +49,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
4949
5050 })
5151
52- It ("ensuring that extra arguments can be added to application controller" , func () {
53-
52+ It ("ensuring extra arguments are deduplicated, replaced, or preserved as expected in application-controller" , func () {
5453 By ("creating a simple ArgoCD CR and waiting for it to become available" )
5554 ns , cleanupFunc := fixture .CreateRandomE2ETestNamespaceWithCleanupFunc ()
5655 defer cleanupFunc ()
@@ -62,61 +61,130 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
6261 },
6362 }
6463 Expect (k8sClient .Create (ctx , argoCD )).To (Succeed ())
65-
6664 Eventually (argoCD , "5m" , "5s" ).Should (argocdFixture .BeAvailable ())
6765
68- By ("verifying app controller becomes availables" )
6966 appControllerSS := & appsv1.StatefulSet {
7067 ObjectMeta : metav1.ObjectMeta {
7168 Name : "example-argocd-application-controller" ,
7269 Namespace : ns .Name ,
7370 },
7471 }
75-
7672 Eventually (appControllerSS ).Should (k8sFixture .ExistByName ())
7773 Eventually (appControllerSS ).Should (statefulsetFixture .HaveReadyReplicas (1 ))
7874
79- By ("adding a new parameter via .spec.controller.extraCommandArgs" )
75+ // 1: Add new flag
76+ By ("adding a new flag via extraCommandArgs" )
8077 argocdFixture .Update (argoCD , func (ac * argov1beta1api.ArgoCD ) {
81- ac .Spec .Controller .ExtraCommandArgs = []string {"--app-hard-resync" }
78+ ac .Spec .Controller .ExtraCommandArgs = []string {"--app-hard-resync" , "2" }
8279 })
83-
84- By ("verifying new parameter is added, and the existing paramaters are still present" )
8580 Eventually (appControllerSS ).Should (statefulsetFixture .HaveContainerCommandSubstring ("--app-hard-resync" , 0 ))
8681
87- Expect (len (appControllerSS .Spec .Template .Spec .Containers [0 ].Command )).To (BeNumerically (">=" , 10 ))
82+ // 2: Replace existing non-repeatable flag
83+ By ("replacing existing default flag with extraCommandArgs" )
84+ argocdFixture .Update (argoCD , func (ac * argov1beta1api.ArgoCD ) {
85+ ac .Spec .Controller .ExtraCommandArgs = []string {
86+ "--status-processors" , "15" ,
87+ "--kubectl-parallelism-limit" , "20" ,
88+ }
89+ })
8890
89- By ("removing the extra command arg" )
91+ // Expect new values to appear
92+ Eventually (appControllerSS ).Should (statefulsetFixture .HaveContainerCommandSubstring ("--status-processors" , 0 ))
93+ Eventually (appControllerSS ).Should (statefulsetFixture .HaveContainerCommandSubstring ("15" , 0 ))
94+ Eventually (appControllerSS ).Should (statefulsetFixture .HaveContainerCommandSubstring ("--kubectl-parallelism-limit" , 0 ))
95+ Eventually (appControllerSS ).Should (statefulsetFixture .HaveContainerCommandSubstring ("20" , 0 ))
96+
97+ // Expect default values to be replaced (old default 10 should not appear)
98+ Consistently (func () bool {
99+ cmd := appControllerSS .Spec .Template .Spec .Containers [0 ].Command
100+ for i := range cmd {
101+ if cmd [i ] == "--status-processors" && i + 1 < len (cmd ) && cmd [i + 1 ] == "10" {
102+ return true
103+ }
104+ }
105+ return false
106+ }).Should (BeFalse ())
107+
108+ // 3: Add duplicate flag+value pairs, which should be ignored
109+ By ("adding duplicate flags with same values" )
90110 argocdFixture .Update (argoCD , func (ac * argov1beta1api.ArgoCD ) {
91- ac .Spec .Controller .ExtraCommandArgs = nil
111+ ac .Spec .Controller .ExtraCommandArgs = []string {
112+ "--status-processors" , "15" , // duplicate
113+ "--kubectl-parallelism-limit" , "20" , // duplicate
114+ "--hydrator-enabled" ,
115+ }
92116 })
117+ // Verify --hydrator-enabled gets added
118+ Eventually (appControllerSS ).Should (statefulsetFixture .HaveContainerCommandSubstring ("--hydrator-enabled" , 0 ))
119+
120+ // But no duplicate --status-processors or --kubectl-parallelism-limit
121+ Consistently (func () bool {
122+ cmd := appControllerSS .Spec .Template .Spec .Containers [0 ].Command
123+
124+ statusProcessorsCount := 0
125+ kubectlLimitCount := 0
126+
127+ for i := 0 ; i < len (cmd ); i ++ {
128+ if cmd [i ] == "--status-processors" {
129+ statusProcessorsCount ++
130+ }
131+ if cmd [i ] == "--kubectl-parallelism-limit" {
132+ kubectlLimitCount ++
133+ }
134+ }
93135
94- By ("verifying the parameter has been removed" )
95- Eventually (appControllerSS ).ShouldNot (statefulsetFixture .HaveContainerCommandSubstring ("--app-hard-resync" , 0 ))
96- Consistently (appControllerSS ).ShouldNot (statefulsetFixture .HaveContainerCommandSubstring ("--app-hard-resync" , 0 ))
97- Expect (len (appControllerSS .Spec .Template .Spec .Containers [0 ].Command )).To (BeNumerically (">=" , 10 ))
136+ // Fail if either flag appears more than once
137+ return statusProcessorsCount > 1 || kubectlLimitCount > 1
138+ }).Should (BeFalse ())
98139
99- By ("adding a new extra command arg that has the same name as existing parameters" )
140+ // 4: Add a repeatable flag multiple times with different values
141+ By ("adding a repeatable flag with multiple values" )
100142 argocdFixture .Update (argoCD , func (ac * argov1beta1api.ArgoCD ) {
101143 ac .Spec .Controller .ExtraCommandArgs = []string {
102- "--status-processors" ,
103- "15" ,
104- "--kubectl-parallelism-limit" ,
105- "20" ,
144+ "--metrics-application-labels" , "application.argoproj.io/template-version" ,
145+ "--metrics-application-labels" , "application.argoproj.io/chart-version" ,
106146 }
107147 })
108148
109- // TODO: These lines are currently failing: they are ported correctly from the original kuttl test, but the original kuttl test did not check them correctly (and thus either the behaviour in the operator changed, or the tests never worked )
149+ Eventually ( appControllerSS ). Should ( statefulsetFixture . HaveContainerCommandSubstring ( "--metrics-application-labels" , 0 ) )
110150
111- // Eventually(appControllerSS).ShouldNot(statefulsetFixture.HaveContainerCommandSubstring("--status-processors 15", 0))
151+ // Check that both --metrics-application-labels flags are present
152+ Eventually (func () bool {
153+ cmd := appControllerSS .Spec .Template .Spec .Containers [0 ].Command
112154
113- // Consistently(appControllerSS).ShouldNot(statefulsetFixture.HaveContainerCommandSubstring("--status-processors 15", 0))
155+ metricVals := []string {}
156+ for i := 0 ; i < len (cmd ); i ++ {
157+ if cmd [i ] == "--metrics-application-labels" && i + 1 < len (cmd ) {
158+ metricVals = append (metricVals , cmd [i + 1 ])
159+ }
160+ }
114161
115- // Eventually(appControllerSS).ShouldNot(statefulsetFixture.HaveContainerCommandSubstring("--kubectl-parallelism-limit 20", 0))
162+ // Ensure both values are present
163+ hasMetricLabelTemplate := false
164+ hasMetricLabelChart := false
165+ for _ , v := range metricVals {
166+ if v == "application.argoproj.io/template-version" {
167+ hasMetricLabelTemplate = true
168+ }
169+ if v == "application.argoproj.io/chart-version" {
170+ hasMetricLabelChart = true
171+ }
172+ }
173+ return hasMetricLabelTemplate && hasMetricLabelChart
174+ }).Should (BeTrue ())
116175
117- // Consistently(appControllerSS).ShouldNot(statefulsetFixture.HaveContainerCommandSubstring("--kubectl-parallelism-limit 20", 0))
176+ // 5: Remove all extra args
177+ By ("removing all extra args" )
178+ argocdFixture .Update (argoCD , func (ac * argov1beta1api.ArgoCD ) {
179+ ac .Spec .Controller .ExtraCommandArgs = nil
180+ })
118181
182+ // Expect all custom flags to disappear
183+ Eventually (appControllerSS ).ShouldNot (statefulsetFixture .HaveContainerCommandSubstring ("--metrics-application-labels" , 0 ))
184+ Eventually (appControllerSS ).ShouldNot (statefulsetFixture .HaveContainerCommandSubstring ("--status-processors 15" , 0 ))
185+ Eventually (appControllerSS ).ShouldNot (statefulsetFixture .HaveContainerCommandSubstring ("--kubectl-parallelism-limit 20" , 0 ))
186+ Eventually (appControllerSS ).ShouldNot (statefulsetFixture .HaveContainerCommandSubstring ("--hydrator-enabled" , 0 ))
119187 })
120-
121188 })
189+
122190})
0 commit comments