@@ -36,10 +36,15 @@ import (
3636)
3737
3838const testReconciliationTriggerAnnotation = "test-reconciliation-trigger"
39+ const gitopsPluginDeploymentName = "gitops-plugin"
3940
4041var _ = Describe ("GitOps Operator Sequential E2E Tests" , func () {
4142
4243 Context ("1-123_validate_list_order_comparison" , func () {
44+ // Reviewer note: This test has been verified passing locally with `make run` (operator
45+ // running on host) and also after installing the operator via OLM on an OpenShift cluster.
46+ // If it fails in CI (e.g. OpenShift Prow / GitHub workflow) without an obvious cause,
47+ // consider environment differences (e.g. container order, timing, or cluster state).
4348
4449 var (
4550 k8sClient client.Client
@@ -58,7 +63,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
5863
5964 pluginDeployment := & appsv1.Deployment {
6065 ObjectMeta : metav1.ObjectMeta {
61- Name : "gitops-plugin" ,
66+ Name : gitopsPluginDeploymentName ,
6267 Namespace : "openshift-gitops" ,
6368 },
6469 }
@@ -149,7 +154,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
149154
150155 pluginDeployment := & appsv1.Deployment {
151156 ObjectMeta : metav1.ObjectMeta {
152- Name : "gitops-plugin" ,
157+ Name : gitopsPluginDeploymentName ,
153158 Namespace : "openshift-gitops" ,
154159 },
155160 }
@@ -160,12 +165,18 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
160165 By ("capturing initial state before making actual change" )
161166 Expect (k8sClient .Get (ctx , client .ObjectKeyFromObject (pluginDeployment ), pluginDeployment )).To (Succeed ())
162167 initialGen := pluginDeployment .Generation
163- expectedImage := pluginDeployment .Spec .Template .Spec .Containers [0 ].Image
168+ // Target the operator-managed container by name so we don't depend on container order (e.g. oauth-proxy may be first on OpenShift)
169+ pluginContainer := deploymentFixture .GetTemplateSpecContainerByName (gitopsPluginDeploymentName , * pluginDeployment )
170+ Expect (pluginContainer ).ToNot (BeNil (), "deployment should have container %q" , gitopsPluginDeploymentName )
171+ expectedImage := pluginContainer .Image
164172
165173 By ("making an actual change to the deployment" )
166174 deploymentFixture .Update (pluginDeployment , func (d * appsv1.Deployment ) {
167- if len (d .Spec .Template .Spec .Containers ) > 0 {
168- d .Spec .Template .Spec .Containers [0 ].Image = "wrong-image:wrong-tag"
175+ for i := range d .Spec .Template .Spec .Containers {
176+ if d .Spec .Template .Spec .Containers [i ].Name == gitopsPluginDeploymentName {
177+ d .Spec .Template .Spec .Containers [i ].Image = "wrong-image:wrong-tag"
178+ break
179+ }
169180 }
170181 })
171182
@@ -195,11 +206,13 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
195206 if err := k8sClient .Get (ctx , client .ObjectKeyFromObject (pluginDeployment ), pluginDeployment ); err != nil {
196207 return false
197208 }
198- if len (pluginDeployment .Spec .Template .Spec .Containers ) == 0 {
209+ c := deploymentFixture .GetTemplateSpecContainerByName (gitopsPluginDeploymentName , * pluginDeployment )
210+ if c == nil {
199211 return false
200212 }
201- return pluginDeployment .Spec .Template .Spec .Containers [0 ].Image == expectedImage
202- }, "5m" , "5s" ).Should (BeTrue (), "Operator should restore the image to %q within 5m" , expectedImage )
213+ GinkgoWriter .Println (fmt .Sprintf ("container %q: current image=%q, expected (original) image=%q, match=%v" , c .Name , c .Image , expectedImage , c .Image == expectedImage ))
214+ return c .Image == expectedImage
215+ }, "5m" , "5s" ).Should (BeTrue (), "Operator should restore the image of container %q to %q within 5m" , gitopsPluginDeploymentName , expectedImage )
203216 })
204217 })
205218})
0 commit comments