@@ -12,7 +12,9 @@ import (
1212 namespaceFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/namespace"
1313 "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils"
1414
15+ corev1 "k8s.io/api/core/v1"
1516 rbacv1 "k8s.io/api/rbac/v1"
17+ apierrors "k8s.io/apimachinery/pkg/api/errors"
1618 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1719 "sigs.k8s.io/controller-runtime/pkg/client"
1820)
@@ -22,8 +24,10 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
2224 Context ("1-036_validate_role_rolebinding_for_source_namespace" , func () {
2325
2426 var (
25- ctx context.Context
26- k8sClient client.Client
27+ ctx context.Context
28+ k8sClient client.Client
29+ argoNamespace * corev1.Namespace
30+ cleanupArgoNSFunc func ()
2731
2832 defaultNSArgoCD * v1beta1.ArgoCD
2933
@@ -39,30 +43,39 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
3943
4044 AfterEach (func () {
4145
42- fixture .OutputDebugOnFail ("default" )
46+ fixture .OutputDebugOnFail (argoNamespace )
47+
48+ // Clean up argo cd instance created in test namespace first (before deleting the namespace itself)
49+ Expect (defaultNSArgoCD ).ToNot (BeNil ())
50+ err := k8sClient .Delete (ctx , defaultNSArgoCD )
51+ if err != nil && ! apierrors .IsNotFound (err ) {
52+ Expect (err ).ToNot (HaveOccurred ())
53+ }
4354
4455 // Clean up namespaces created
4556 for _ , namespaceCleanupFunction := range cleanupFunctions {
4657 namespaceCleanupFunction ()
4758 }
4859
49- // Clean up argo cd instance created in 'default' NS
50- Expect (defaultNSArgoCD ).ToNot (BeNil ())
51- Expect (k8sClient .Delete (ctx , defaultNSArgoCD )).To (Succeed ())
52-
5360 })
5461
5562 It ("verifies that ArgoCD CR '.spec.sourceNamespaces' field wildcard-matching matches and manages only namespaces which match the wildcard" , func () {
5663
64+ fixture .SetEnvInOperatorSubscriptionOrDeployment ("ARGOCD_CLUSTER_CONFIG_NAMESPACES" , "openshift-gitops, argocd-e2e-cluster-config" )
65+
66+ By ("creating cluster-scoped namespace for Argo CD instance" )
67+ argoNamespace , cleanupArgoNSFunc = fixture .CreateNamespaceWithCleanupFunc ("argocd-e2e-cluster-config" )
68+ cleanupFunctions = append (cleanupFunctions , cleanupArgoNSFunc )
69+
5770 By ("creating test NS" )
5871 testNS , cleanupFunc := fixture .CreateNamespaceWithCleanupFunc ("test" )
5972 cleanupFunctions = append (cleanupFunctions , cleanupFunc )
6073
61- By ("creating Argo CD instance in default NS, with 'test' sourceNamespace only" )
74+ By ("creating Argo CD instance in argocd-e2e-cluster-config NS, with 'test' sourceNamespace only" )
6275 defaultNSArgoCD = & v1beta1.ArgoCD {
6376 ObjectMeta : metav1.ObjectMeta {
6477 Name : "example-argocd" ,
65- Namespace : "default" ,
78+ Namespace : argoNamespace . Name ,
6679 },
6780 Spec : v1beta1.ArgoCDSpec {
6881 SourceNamespaces : []string {
@@ -73,7 +86,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
7386 Expect (k8sClient .Create (ctx , defaultNSArgoCD )).To (Succeed ())
7487
7588 By ("verifying Argo CD instance starts managing the namespace via managed-by-cluster-argocd label" )
76- Eventually (testNS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , "default" ))
89+ Eventually (testNS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
7790
7891 expectRoleAndRoleBindingValues := func (name string , ns string ) {
7992
@@ -107,12 +120,12 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
107120 {
108121 Kind : "ServiceAccount" ,
109122 Name : "example-argocd-argocd-server" ,
110- Namespace : "default" ,
123+ Namespace : argoNamespace . Name ,
111124 },
112125 {
113126 Kind : "ServiceAccount" ,
114127 Name : "example-argocd-argocd-application-controller" ,
115- Namespace : "default" ,
128+ Namespace : argoNamespace . Name ,
116129 },
117130 }))
118131
@@ -133,7 +146,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
133146 })
134147
135148 By ("verifying test-1 NS becomes managed, and expected role/rolebindings exist in test* namespaces but not dev" )
136- Eventually (test1NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , "default" ))
149+ Eventually (test1NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
137150
138151 expectRoleAndRoleBindingValues ("example-argocd_test" , "test" )
139152
@@ -161,7 +174,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
161174 cleanupFunctions = append (cleanupFunctions , cleanupFunc )
162175
163176 By ("verifying the test-2 namespace becomes managed by the argo cd instance, and has the expected role/rolebinding" )
164- Eventually (test2NS , "2m" , "5s" ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , "default" ))
177+ Eventually (test2NS , "2m" , "5s" ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
165178
166179 expectRoleAndRoleBindingValues ("example-argocd_test-2" , "test-2" )
167180
@@ -173,17 +186,17 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
173186 })
174187
175188 By ("verifying test, test-1, test-2, and dev are all managed and have the expected roles" )
176- Eventually (testNS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , "default" ))
177- Consistently (testNS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , "default" ))
189+ Eventually (testNS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
190+ Consistently (testNS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
178191
179- Eventually (test1NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , "default" ))
180- Consistently (test1NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , "default" ))
192+ Eventually (test1NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
193+ Consistently (test1NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
181194
182- Eventually (test2NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , "default" ))
183- Consistently (test2NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , "default" ))
195+ Eventually (test2NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
196+ Consistently (test2NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
184197
185- Eventually (devNS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , "default" ))
186- Consistently (devNS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , "default" ))
198+ Eventually (devNS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
199+ Consistently (devNS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
187200
188201 expectRoleAndRoleBindingValues ("example-argocd_test" , "test" )
189202 expectRoleAndRoleBindingValues ("example-argocd_test-1" , "test-1" )
@@ -208,11 +221,11 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
208221 cleanupFunctions = append (cleanupFunctions , cleanupFunc )
209222
210223 By ("verifying test-ns-1 and dev-ns-1 are managed, but other-ns isn't" )
211- Eventually (test_ns_1NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , "default" ))
212- Consistently (test_ns_1NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , "default" ))
224+ Eventually (test_ns_1NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
225+ Consistently (test_ns_1NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
213226
214- Eventually (dev_ns_1NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , "default" ))
215- Consistently (dev_ns_1NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , "default" ))
227+ Eventually (dev_ns_1NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
228+ Consistently (dev_ns_1NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
216229
217230 expectRoleAndRoleBindingValues ("example-argocd_test-ns-1" , "test-ns-1" )
218231 expectRoleAndRoleBindingValues ("example-argocd_dev-ns-1" , "dev-ns-1" )
@@ -239,18 +252,18 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
239252 })
240253
241254 By ("verifying dev-ns-1 eventually becomes unmanaged" )
242- Eventually (dev_ns_1NS ).ShouldNot (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , "default" ))
243- Consistently (dev_ns_1NS ).ShouldNot (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , "default" ))
255+ Eventually (dev_ns_1NS ).ShouldNot (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
256+ Consistently (dev_ns_1NS ).ShouldNot (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
244257
245258 devns1Role := & rbacv1.Role {
246259 ObjectMeta : metav1.ObjectMeta {
247- Name : " example-argocd_dev-ns-1" ,
260+ Name : "example-argocd_dev-ns-1" ,
248261 Namespace : dev_ns_1NS .Name ,
249262 },
250263 }
251264 devns1RoleBinding := & rbacv1.RoleBinding {
252265 ObjectMeta : metav1.ObjectMeta {
253- Name : " example-argocd_dev-ns-1" ,
266+ Name : "example-argocd_dev-ns-1" ,
254267 Namespace : dev_ns_1NS .Name ,
255268 },
256269 }
0 commit comments