Skip to content

Commit 75b2eee

Browse files
committed
Add e2e ginkgo tests for extraCommandargs and Application Health Status
Signed-off-by: Rizwana777 <[email protected]>
1 parent 5105bbe commit 75b2eee

File tree

2 files changed

+335
-27
lines changed

2 files changed

+335
-27
lines changed

test/openshift/e2e/ginkgo/parallel/1-115_validate_controller_extra_command_args_test.go

Lines changed: 121 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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("ensures 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,156 @@ 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+
// Verify default values of --status-processors and --kubectl-parallelism-limit
76+
Eventually(appControllerSS).Should(statefulsetFixture.HaveContainerCommandSubstring("--status-processors", 0))
77+
Eventually(appControllerSS).Should(statefulsetFixture.HaveContainerCommandSubstring("20", 0))
78+
Eventually(appControllerSS).Should(statefulsetFixture.HaveContainerCommandSubstring("--kubectl-parallelism-limit", 0))
79+
Eventually(appControllerSS).Should(statefulsetFixture.HaveContainerCommandSubstring("10", 0))
80+
81+
// 1: Add new flag
82+
By("adding a new flag via extraCommandArgs")
8083
argocdFixture.Update(argoCD, func(ac *argov1beta1api.ArgoCD) {
81-
ac.Spec.Controller.ExtraCommandArgs = []string{"--app-hard-resync"}
84+
ac.Spec.Controller.ExtraCommandArgs = []string{"--app-hard-resync", "2"}
8285
})
83-
84-
By("verifying new parameter is added, and the existing paramaters are still present")
8586
Eventually(appControllerSS).Should(statefulsetFixture.HaveContainerCommandSubstring("--app-hard-resync", 0))
8687

87-
Expect(len(appControllerSS.Spec.Template.Spec.Containers[0].Command)).To(BeNumerically(">=", 10))
88-
89-
By("removing the extra command arg")
88+
// 2: Replace existing non-repeatable flags --status-processors and --kubectl-parallelism-limit
89+
By("replacing existing default flag with extraCommandArgs")
9090
argocdFixture.Update(argoCD, func(ac *argov1beta1api.ArgoCD) {
91-
ac.Spec.Controller.ExtraCommandArgs = nil
91+
ac.Spec.Controller.ExtraCommandArgs = []string{
92+
"--status-processors", "15",
93+
"--kubectl-parallelism-limit", "20",
94+
}
9295
})
9396

94-
By("verifying the parameter has been removed")
97+
By("new values should appear for --status-processors and --kubectl-parallelism-limit")
98+
Eventually(appControllerSS).Should(statefulsetFixture.HaveContainerCommandSubstring("--status-processors", 0))
99+
Eventually(appControllerSS).Should(statefulsetFixture.HaveContainerCommandSubstring("15", 0))
100+
Eventually(appControllerSS).Should(statefulsetFixture.HaveContainerCommandSubstring("--kubectl-parallelism-limit", 0))
101+
Eventually(appControllerSS).Should(statefulsetFixture.HaveContainerCommandSubstring("20", 0))
95102
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))
98103

99-
By("adding a new extra command arg that has the same name as existing parameters")
104+
By("default values should be replaced (old default for --status-processors 20 and --kubectl-parallelism-limit 10 should not appear")
105+
Consistently(func() bool {
106+
Expect(k8sClient.Get(ctx, client.ObjectKey{
107+
Name: appControllerSS.Name,
108+
Namespace: appControllerSS.Namespace,
109+
}, appControllerSS)).To(Succeed())
110+
111+
cmd := appControllerSS.Spec.Template.Spec.Containers[0].Command
112+
for i := range cmd {
113+
if cmd[i] == "--status-processors" && i+1 < len(cmd) && cmd[i+1] == "20" {
114+
return true
115+
}
116+
if cmd[i] == "--kubectl-parallelism-limit" && i+1 < len(cmd) && cmd[i+1] == "10" {
117+
return true
118+
}
119+
}
120+
return false
121+
}).Should(BeFalse())
122+
123+
// 3: Add duplicate flag+value pairs, which should be ignored
124+
By("adding duplicate flags with same values")
100125
argocdFixture.Update(argoCD, func(ac *argov1beta1api.ArgoCD) {
101126
ac.Spec.Controller.ExtraCommandArgs = []string{
102-
"--status-processors",
103-
"15",
104-
"--kubectl-parallelism-limit",
105-
"20",
127+
"--status-processors", "15",
128+
"--kubectl-parallelism-limit", "20",
129+
"--status-processors", "15", // duplicate
130+
"--kubectl-parallelism-limit", "20", // duplicate
131+
"--hydrator-enabled",
106132
}
107133
})
134+
// Verify --hydrator-enabled gets added
135+
Eventually(appControllerSS).Should(statefulsetFixture.HaveContainerCommandSubstring("--hydrator-enabled", 0))
136+
137+
// But no duplicate --status-processors or --kubectl-parallelism-limit
138+
Consistently(func() bool {
139+
Expect(k8sClient.Get(ctx, client.ObjectKey{
140+
Name: appControllerSS.Name,
141+
Namespace: appControllerSS.Namespace,
142+
}, appControllerSS)).To(Succeed())
143+
144+
cmd := appControllerSS.Spec.Template.Spec.Containers[0].Command
145+
146+
statusProcessorsCount := 0
147+
kubectlLimitCount := 0
148+
149+
for i := 0; i < len(cmd); i++ {
150+
if cmd[i] == "--status-processors" {
151+
statusProcessorsCount++
152+
}
153+
if cmd[i] == "--kubectl-parallelism-limit" {
154+
kubectlLimitCount++
155+
}
156+
}
108157

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)
158+
// Fail if either flag appears more than once
159+
return statusProcessorsCount > 1 || kubectlLimitCount > 1
160+
}).Should(BeFalse())
110161

111-
// Eventually(appControllerSS).ShouldNot(statefulsetFixture.HaveContainerCommandSubstring("--status-processors 15", 0))
162+
// 4: Add a repeatable flag multiple times with different values
163+
By("adding a repeatable flag with multiple values")
164+
argocdFixture.Update(argoCD, func(ac *argov1beta1api.ArgoCD) {
165+
ac.Spec.Controller.ExtraCommandArgs = []string{
166+
"--metrics-application-labels", "application.argoproj.io/template-version",
167+
"--metrics-application-labels", "application.argoproj.io/chart-version",
168+
}
169+
})
112170

113-
// Consistently(appControllerSS).ShouldNot(statefulsetFixture.HaveContainerCommandSubstring("--status-processors 15", 0))
171+
Eventually(appControllerSS).Should(statefulsetFixture.HaveContainerCommandSubstring("--metrics-application-labels", 0))
114172

115-
// Eventually(appControllerSS).ShouldNot(statefulsetFixture.HaveContainerCommandSubstring("--kubectl-parallelism-limit 20", 0))
173+
By("Check that both --metrics-application-labels flags are present")
174+
Eventually(func() bool {
175+
Expect(k8sClient.Get(ctx, client.ObjectKey{
176+
Name: appControllerSS.Name,
177+
Namespace: appControllerSS.Namespace,
178+
}, appControllerSS)).To(Succeed())
116179

117-
// Consistently(appControllerSS).ShouldNot(statefulsetFixture.HaveContainerCommandSubstring("--kubectl-parallelism-limit 20", 0))
180+
cmd := appControllerSS.Spec.Template.Spec.Containers[0].Command
118181

119-
})
182+
metricVals := []string{}
183+
for i := 0; i < len(cmd); i++ {
184+
if cmd[i] == "--metrics-application-labels" && i+1 < len(cmd) {
185+
metricVals = append(metricVals, cmd[i+1])
186+
}
187+
}
188+
189+
// Ensure both values are present
190+
hasMetricLabelTemplate := false
191+
hasMetricLabelChart := false
192+
for _, v := range metricVals {
193+
if v == "application.argoproj.io/template-version" {
194+
hasMetricLabelTemplate = true
195+
}
196+
if v == "application.argoproj.io/chart-version" {
197+
hasMetricLabelChart = true
198+
}
199+
}
200+
return hasMetricLabelTemplate && hasMetricLabelChart
201+
}).Should(BeTrue())
202+
203+
// 5: Remove all extra args
204+
By("removing all extra args")
205+
argocdFixture.Update(argoCD, func(ac *argov1beta1api.ArgoCD) {
206+
ac.Spec.Controller.ExtraCommandArgs = nil
207+
})
120208

209+
// Expect all custom flags to disappear
210+
Eventually(appControllerSS).ShouldNot(statefulsetFixture.HaveContainerCommandSubstring("--metrics-application-labels", 0))
211+
Eventually(appControllerSS).ShouldNot(statefulsetFixture.HaveContainerCommandSubstring("--status-processors 15", 0))
212+
Eventually(appControllerSS).ShouldNot(statefulsetFixture.HaveContainerCommandSubstring("--kubectl-parallelism-limit 20", 0))
213+
Eventually(appControllerSS).ShouldNot(statefulsetFixture.HaveContainerCommandSubstring("--hydrator-enabled", 0))
214+
})
121215
})
122216
})

0 commit comments

Comments
 (0)