@@ -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,37 @@ 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+ By ("creating cluster-scoped namespace for Argo CD instance" )
65+ argoNamespace , cleanupArgoNSFunc = fixture .CreateNamespaceWithCleanupFunc ("argocd-e2e-cluster-config" )
66+ cleanupFunctions = append (cleanupFunctions , cleanupArgoNSFunc )
67+
5768 By ("creating test NS" )
5869 testNS , cleanupFunc := fixture .CreateNamespaceWithCleanupFunc ("test" )
5970 cleanupFunctions = append (cleanupFunctions , cleanupFunc )
6071
61- By ("creating Argo CD instance in default NS, with 'test' sourceNamespace only" )
72+ By ("creating Argo CD instance in argocd-e2e-cluster-config NS, with 'test' sourceNamespace only" )
6273 defaultNSArgoCD = & v1beta1.ArgoCD {
6374 ObjectMeta : metav1.ObjectMeta {
6475 Name : "example-argocd" ,
65- Namespace : "default" ,
76+ Namespace : argoNamespace . Name ,
6677 },
6778 Spec : v1beta1.ArgoCDSpec {
6879 SourceNamespaces : []string {
@@ -73,7 +84,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
7384 Expect (k8sClient .Create (ctx , defaultNSArgoCD )).To (Succeed ())
7485
7586 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" ))
87+ Eventually (testNS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
7788
7889 expectRoleAndRoleBindingValues := func (name string , ns string ) {
7990
@@ -107,12 +118,12 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
107118 {
108119 Kind : "ServiceAccount" ,
109120 Name : "example-argocd-argocd-server" ,
110- Namespace : "default" ,
121+ Namespace : argoNamespace . Name ,
111122 },
112123 {
113124 Kind : "ServiceAccount" ,
114125 Name : "example-argocd-argocd-application-controller" ,
115- Namespace : "default" ,
126+ Namespace : argoNamespace . Name ,
116127 },
117128 }))
118129
@@ -133,7 +144,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
133144 })
134145
135146 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" ))
147+ Eventually (test1NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
137148
138149 expectRoleAndRoleBindingValues ("example-argocd_test" , "test" )
139150
@@ -161,7 +172,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
161172 cleanupFunctions = append (cleanupFunctions , cleanupFunc )
162173
163174 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" ))
175+ Eventually (test2NS , "2m" , "5s" ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
165176
166177 expectRoleAndRoleBindingValues ("example-argocd_test-2" , "test-2" )
167178
@@ -173,17 +184,17 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
173184 })
174185
175186 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" ))
187+ Eventually (testNS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
188+ Consistently (testNS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
178189
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" ))
190+ Eventually (test1NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
191+ Consistently (test1NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
181192
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" ))
193+ Eventually (test2NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
194+ Consistently (test2NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
184195
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" ))
196+ Eventually (devNS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
197+ Consistently (devNS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
187198
188199 expectRoleAndRoleBindingValues ("example-argocd_test" , "test" )
189200 expectRoleAndRoleBindingValues ("example-argocd_test-1" , "test-1" )
@@ -208,11 +219,11 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
208219 cleanupFunctions = append (cleanupFunctions , cleanupFunc )
209220
210221 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" ))
222+ Eventually (test_ns_1NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
223+ Consistently (test_ns_1NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
213224
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" ))
225+ Eventually (dev_ns_1NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
226+ Consistently (dev_ns_1NS ).Should (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
216227
217228 expectRoleAndRoleBindingValues ("example-argocd_test-ns-1" , "test-ns-1" )
218229 expectRoleAndRoleBindingValues ("example-argocd_dev-ns-1" , "dev-ns-1" )
@@ -239,18 +250,18 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
239250 })
240251
241252 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" ))
253+ Eventually (dev_ns_1NS ).ShouldNot (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
254+ Consistently (dev_ns_1NS ).ShouldNot (namespaceFixture .HaveLabel ("argocd.argoproj.io/managed-by-cluster-argocd" , argoNamespace . Name ))
244255
245256 devns1Role := & rbacv1.Role {
246257 ObjectMeta : metav1.ObjectMeta {
247- Name : " example-argocd_dev-ns-1" ,
258+ Name : "example-argocd_dev-ns-1" ,
248259 Namespace : dev_ns_1NS .Name ,
249260 },
250261 }
251262 devns1RoleBinding := & rbacv1.RoleBinding {
252263 ObjectMeta : metav1.ObjectMeta {
253- Name : " example-argocd_dev-ns-1" ,
264+ Name : "example-argocd_dev-ns-1" ,
254265 Namespace : dev_ns_1NS .Name ,
255266 },
256267 }
0 commit comments