Skip to content

Commit 0a3f993

Browse files
committed
Update
1 parent 7eec754 commit 0a3f993

11 files changed

+587
-73
lines changed

controllers/argocd/openshift/openshift_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,10 @@ func TestAdminClusterRoleMapper(t *testing.T) {
306306

307307
// Sort both slices to ensure consistent comparison
308308
sort.Slice(result, func(i, j int) bool {
309-
return result[i].NamespacedName.Name < result[j].NamespacedName.Name
309+
return result[i].Name < result[j].Name
310310
})
311311
sort.Slice(expectedRequests, func(i, j int) bool {
312-
return expectedRequests[i].NamespacedName.Name < expectedRequests[j].NamespacedName.Name
312+
return expectedRequests[i].Name < expectedRequests[j].Name
313313
})
314314

315315
assert.Equal(t, expectedRequests, result)

test/openshift/e2e/ginkgo/fixture/fixture.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,17 @@ func OutputDebugOnFail(namespaceParams ...any) {
881881
GinkgoWriter.Println(kubectlOutput)
882882
GinkgoWriter.Println("----------------------------------------------------------------")
883883

884+
kubectlOutput, err = osFixture.ExecCommandWithOutputParam(false, "kubectl", "get", "events", "-n", namespace)
885+
if err != nil {
886+
GinkgoWriter.Println("unable to get events for namespace", err, kubectlOutput)
887+
} else {
888+
GinkgoWriter.Println("")
889+
GinkgoWriter.Println("----------------------------------------------------------------")
890+
GinkgoWriter.Println("'kubectl get events -n " + namespace + ":")
891+
GinkgoWriter.Println(kubectlOutput)
892+
GinkgoWriter.Println("----------------------------------------------------------------")
893+
}
894+
884895
}
885896

886897
kubectlOutput, err := osFixture.ExecCommandWithOutputParam(false, "kubectl", "get", "argocds", "-A", "-o", "yaml")
@@ -894,6 +905,8 @@ func OutputDebugOnFail(namespaceParams ...any) {
894905
GinkgoWriter.Println("----------------------------------------------------------------")
895906
}
896907

908+
GinkgoWriter.Println("You can skip this debug output by setting 'SKIP_DEBUG_OUTPUT=true'")
909+
897910
}
898911

899912
// EnsureRunningOnOpenShift should be called if a test requires OpenShift (for example, it uses Route CR).

test/openshift/e2e/ginkgo/fixture/k8s/fixture.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ func NotHaveLabelWithValue(key string, value string) matcher.GomegaMatcher {
9090
return true
9191
}
9292

93+
GinkgoWriter.Println("NotHaveLabelWithValue: not expected: ", key, "/", value, ". actual:", labels[key])
94+
9395
return labels[key] != value
9496

9597
}, BeTrue())

test/openshift/e2e/ginkgo/fixture/secret/fixture.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ func HaveDataKeyValue(key string, value []byte) matcher.GomegaMatcher {
9898

9999
}
100100

101+
// NotHaveDataKey returns true if Secret's .data 'key' does not exist, false otherwise
102+
func NotHaveDataKey(key string) matcher.GomegaMatcher {
103+
return fetchSecret(func(secret *corev1.Secret) bool {
104+
_, exists := secret.Data[key]
105+
GinkgoWriter.Println("NotHaveDataKey - key:", key, "Exists:", exists)
106+
return !exists
107+
})
108+
109+
}
110+
101111
// This is intentionally NOT exported, for now. Create another function in this file/package that calls this function, and export that.
102112
func fetchSecret(f func(*corev1.Secret) bool) matcher.GomegaMatcher {
103113

test/openshift/e2e/ginkgo/parallel/1-042_restricted_pss_compliant_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
5858
defer fixture.DeleteNamespace(ns)
5959

6060
fixture.OutputDebugOnFail(ns.Name)
61+
6162
})
6263

6364
It("verifies that all Argo CD components can run with pod-security enforce, warn, and audit of 'restricted'", func() {

test/openshift/e2e/ginkgo/parallel/1-055_validate_notification_controller_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,5 +171,76 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
171171

172172
})
173173

174+
It("ensure that sourceNamespace resources are not created for namespace-scoped instance", func() {
175+
176+
By("creating test namespaces")
177+
fooNs, fooNsCleanupFunc := fixture.CreateNamespaceWithCleanupFunc("foo-src-ns")
178+
defer fooNsCleanupFunc()
179+
180+
By("creating namespace-scoped Argo CD instance with sourceNamespaces")
181+
ns, cleanupFunc := fixture.CreateNamespaceWithCleanupFunc("1-055-src-ns-test")
182+
defer cleanupFunc()
183+
184+
argocd := &argov1beta1api.ArgoCD{
185+
ObjectMeta: metav1.ObjectMeta{
186+
Name: "example-argocd",
187+
Namespace: ns.Name,
188+
},
189+
Spec: argov1beta1api.ArgoCDSpec{
190+
Notifications: argov1beta1api.ArgoCDNotifications{
191+
Enabled: true,
192+
SourceNamespaces: []string{fooNs.Name},
193+
},
194+
SourceNamespaces: []string{fooNs.Name},
195+
},
196+
}
197+
Expect(k8sClient.Create(ctx, argocd)).To(Succeed())
198+
199+
By("verifying Argo CD and notification controller start as expected")
200+
Eventually(argocd, "4m", "5s").Should(argocdFixture.HaveNotificationControllerStatus("Running"))
201+
202+
By("verifying that sourceNamespace cmd args don't exist")
203+
depl := &appsv1.Deployment{
204+
ObjectMeta: metav1.ObjectMeta{
205+
Name: "example-argocd-notifications-controller",
206+
Namespace: ns.Name,
207+
},
208+
}
209+
Eventually(depl).Should(k8sFixture.ExistByName())
210+
// TODO: add check to test "--application-namespaces" cmd arg is not present in the notification deployment container args
211+
212+
By("verifying sourceNamespace rbac resources are not created")
213+
clusterRole := &rbacv1.ClusterRole{
214+
ObjectMeta: metav1.ObjectMeta{
215+
Name: "example-argocd-1-055-src-ns-test-argocd-notifications-controller",
216+
Namespace: ns.Name,
217+
},
218+
}
219+
clusterRoleBinding := &rbacv1.ClusterRoleBinding{
220+
ObjectMeta: metav1.ObjectMeta{
221+
Name: "example-argocd-1-055-src-ns-test-argocd-notifications-controller",
222+
Namespace: ns.Name,
223+
},
224+
}
225+
role := &rbacv1.Role{
226+
ObjectMeta: metav1.ObjectMeta{
227+
Name: "example-argocd-1-055-src-ns-test-notifications",
228+
Namespace: fooNs.Name,
229+
},
230+
}
231+
roleBinding := &rbacv1.RoleBinding{
232+
ObjectMeta: metav1.ObjectMeta{
233+
Name: "example-argocd-1-055-src-ns-test-notifications",
234+
Namespace: fooNs.Name,
235+
},
236+
}
237+
238+
Eventually(role).Should(k8sFixture.NotExistByName())
239+
Eventually(roleBinding).Should(k8sFixture.NotExistByName())
240+
Eventually(clusterRole).Should(k8sFixture.NotExistByName())
241+
Eventually(clusterRoleBinding).Should(k8sFixture.NotExistByName())
242+
243+
})
244+
174245
})
175246
})

test/openshift/e2e/ginkgo/parallel/1-121_validate_custom_labels_rollouts.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
7676
By("updating RolloutManager spec")
7777

7878
// Add a new label to trigger reconciliation
79-
if rolloutManager.ObjectMeta.Labels == nil {
80-
rolloutManager.ObjectMeta.Labels = make(map[string]string)
79+
if rolloutManager.Labels == nil {
80+
rolloutManager.Labels = make(map[string]string)
8181
}
82-
rolloutManager.ObjectMeta.Labels["test-update"] = "true"
82+
rolloutManager.Labels["test-update"] = "true"
8383
patch := client.MergeFrom(rolloutManager.DeepCopy())
8484
Expect(k8sClient.Patch(ctx, rolloutManager, patch)).To(Succeed())
8585

test/openshift/e2e/ginkgo/sequential/1-036_validate_role_rolebinding_for_source_namespace_test.go

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)