Skip to content

Commit e2c14b0

Browse files
committed
test(e2e): add e2e test for DefaultClusterScopedRoleDisabled
Signed-off-by: Christopher Coco <ccoco@redhat.com>
1 parent d626adb commit e2c14b0

2 files changed

Lines changed: 58 additions & 27 deletions

File tree

tests/ginkgo/sequential/1-051_validate_argocd_agent_principal_test.go

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import (
4444
)
4545

4646
var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
47-
4847
const (
4948
argoCDName = "example"
5049
argoCDAgentPrincipalName = "example-agent-principal" // argoCDName + "-agent-principal"
@@ -54,7 +53,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
5453
)
5554

5655
Context("1-051_validate_argocd_agent_principal", func() {
57-
5856
var (
5957
k8sClient client.Client
6058
ctx context.Context
@@ -339,7 +337,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
339337
})
340338

341339
It("should create argocd agent principal resources, and pod should start successfully with default image", func() {
342-
343340
// Add a custom environment variable to the principal server
344341
argoCD.Spec.ArgoCDAgent.Principal.Env = []corev1.EnvVar{{Name: "TEST_ENV", Value: "test_value"}}
345342

@@ -401,7 +398,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
401398
})
402399

403400
It("Should reflect configuration changes from ArgoCD CR to the principal deployment", func() {
404-
405401
By("Create ArgoCD instance")
406402

407403
argoCD.Spec.ArgoCDAgent.Principal.Image = common.ArgoCDAgentPrincipalDefaultImageName
@@ -429,7 +425,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
429425
Expect(k8sClient.Get(ctx, client.ObjectKey{Name: argoCDName, Namespace: ns.Name}, argoCD)).To(Succeed())
430426

431427
argocdFixture.Update(argoCD, func(ac *argov1beta1api.ArgoCD) {
432-
433428
ac.Spec.ArgoCDAgent.Principal.LogLevel = "trace"
434429
ac.Spec.ArgoCDAgent.Principal.LogFormat = "json"
435430
ac.Spec.ArgoCDAgent.Principal.Server.KeepAliveMinInterval = "60s"
@@ -452,7 +447,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
452447
SecretName: "argocd-agent-resource-proxy-tls-v2",
453448
CASecretName: "argocd-agent-ca-v2",
454449
}
455-
456450
})
457451

458452
By("Create required secrets and certificates for principal pod to start properly")
@@ -512,7 +506,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
512506
})
513507

514508
It("should handle route disabled configuration correctly", func() {
515-
516509
By("Create ArgoCD instance with route disabled")
517510

518511
argoCD.Spec.ArgoCDAgent.Principal.Server.Route = argov1beta1api.ArgoCDAgentPrincipalRouteSpec{
@@ -532,7 +525,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
532525
})
533526

534527
It("should handle route enabled configuration correctly", func() {
535-
536528
By("Create ArgoCD instance with route enabled")
537529

538530
argoCD.Spec.ArgoCDAgent.Principal.Server.Route = argov1beta1api.ArgoCDAgentPrincipalRouteSpec{
@@ -552,7 +544,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
552544
})
553545

554546
It("should handle route toggle from enabled to disabled correctly", func() {
555-
556547
By("Create ArgoCD instance with route enabled")
557548

558549
argoCD.Spec.ArgoCDAgent.Principal.Server.Route = argov1beta1api.ArgoCDAgentPrincipalRouteSpec{
@@ -618,7 +609,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
618609
})
619610

620611
It("should handle service type ClusterIP configuration correctly", func() {
621-
622612
By("Create ArgoCD instance with service type ClusterIP")
623613

624614
argoCD.Spec.ArgoCDAgent.Principal.Server.Service = argov1beta1api.ArgoCDAgentPrincipalServiceSpec{
@@ -643,7 +633,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
643633
})
644634

645635
It("should handle service type LoadBalancer configuration correctly", func() {
646-
647636
By("Create ArgoCD instance with service type LoadBalancer")
648637

649638
argoCD.Spec.ArgoCDAgent.Principal.Server.Service = argov1beta1api.ArgoCDAgentPrincipalServiceSpec{
@@ -668,7 +657,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
668657
})
669658

670659
It("should handle service type updates correctly", func() {
671-
672660
By("Create ArgoCD instance with service type ClusterIP")
673661

674662
argoCD.Spec.ArgoCDAgent.Principal.Server.Service = argov1beta1api.ArgoCDAgentPrincipalServiceSpec{
@@ -710,7 +698,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
710698
})
711699

712700
It("should deploy principal via namespace-scoped ArgoCD instance and verify cluster role and cluster role binding are not created", func() {
713-
714701
By("Create namespace-scoped ArgoCD instance")
715702

716703
// Create namespace for hosting namespace-scoped ArgoCD instance with principal
@@ -764,7 +751,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
764751
})
765752

766753
It("should delete existing cluster role and cluster role binding if ArgoCD instance is namespace-scoped", func() {
767-
768754
By("Create namespace-scoped ArgoCD instance namespace")
769755

770756
// Create namespace for hosting namespace-scoped ArgoCD instance with principal
@@ -908,7 +894,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
908894
})
909895

910896
It("should create and delete principal ServiceMonitor based on prometheus enabled flag", func() {
911-
912897
By("Create ArgoCD instance with principal enabled and prometheus enabled")
913898

914899
argoCD.Spec.Prometheus.Enabled = true
@@ -955,5 +940,33 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
955940

956941
Eventually(principalServiceMonitor, "2m", "2s").Should(k8sFixture.NotExistByName())
957942
})
943+
944+
It("shouldn't create ClusterRole and ClusterRoleBinding for principal if spec.DefaultClusterScopedRoleDisabled is set", func() {
945+
By("Create ArgoCD instance with principal enabled and DefaultClusterScopedRoleDisabled is true")
946+
argoCD.Spec.DefaultClusterScopedRoleDisabled = true
947+
Expect(k8sClient.Create(ctx, argoCD)).To(Succeed())
948+
949+
By("Verify ClusterRole and ClusterRoleBinding do not exist")
950+
Eventually(clusterRole, "60s", "2s").Should(k8sFixture.NotExistByName())
951+
Eventually(clusterRoleBinding, "60s", "2s").Should(k8sFixture.NotExistByName())
952+
953+
By("Namespaced RBAC objects should still exist")
954+
Eventually(role, "60s", "2s").Should(k8sFixture.ExistByName())
955+
Eventually(roleBinding, "60s", "2s").Should(k8sFixture.ExistByName())
956+
957+
By("Unset DefaultClusterScopedRoleDisabled and make sure cluster scoped RBAC objects are created")
958+
argocdFixture.Update(argoCD, func(ac *argov1beta1api.ArgoCD) {
959+
ac.Spec.DefaultClusterScopedRoleDisabled = false
960+
})
961+
Eventually(clusterRole, "60s", "2s").Should(k8sFixture.ExistByName())
962+
Eventually(clusterRoleBinding, "60s", "2s").Should(k8sFixture.ExistByName())
963+
964+
By("Setting DefaultClusterScopedRoleDisabled again deletes clusterRole and clusterRoleBinding")
965+
argocdFixture.Update(argoCD, func(ac *argov1beta1api.ArgoCD) {
966+
ac.Spec.DefaultClusterScopedRoleDisabled = true
967+
})
968+
Eventually(clusterRole, "60s", "2s").Should(k8sFixture.NotExistByName())
969+
Eventually(clusterRoleBinding, "60s", "2s").Should(k8sFixture.NotExistByName())
970+
})
958971
})
959972
})

tests/ginkgo/sequential/1-052_validate_argocd_agent_agent_test.go

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,12 @@ import (
4141
)
4242

4343
var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
44-
4544
const (
4645
argoCDName = "example"
4746
argoCDAgentAgentName = "example-agent-agent" // argoCDName + "-agent-agent"
4847
)
4948

5049
Context("1-052_validate_argocd_agent_agent", func() {
51-
5250
var (
5351
k8sClient client.Client
5452
ctx context.Context
@@ -201,12 +199,12 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
201199

202200
// verifyExpectedResourcesExist will verify that the resources that are created for agent and ArgoCD are created.
203201
verifyExpectedResourcesExist := func(ns *corev1.Namespace) {
204-
205202
By("verifying expected resources exist")
206203
Eventually(&corev1.Secret{
207204
ObjectMeta: metav1.ObjectMeta{
208205
Name: secretNames[2], Namespace: ns.Name,
209-
}}, "60s", "2s").Should(k8sFixture.ExistByName())
206+
},
207+
}, "60s", "2s").Should(k8sFixture.ExistByName())
210208
Eventually(serviceAccount).Should(k8sFixture.ExistByName())
211209
Eventually(role).Should(k8sFixture.ExistByName())
212210
Eventually(roleBinding).Should(k8sFixture.ExistByName())
@@ -258,7 +256,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
258256

259257
// verifyResourcesDeleted will verify that the various resources that are created for agent are deleted.
260258
verifyResourcesDeleted := func() {
261-
262259
By("verifying resources are deleted for agent pod")
263260

264261
Eventually(serviceAccount).Should(k8sFixture.NotExistByName())
@@ -321,7 +318,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
321318
})
322319

323320
It("should create argocd agent agent resources with default image, but pod will not start without principal", func() {
324-
325321
// Add a custom environment variable to the agent client
326322
argoCD.Spec.ArgoCDAgent.Agent.Env = []corev1.EnvVar{{Name: "TEST_ENV", Value: "test_value"}}
327323

@@ -367,7 +363,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
367363
})
368364

369365
It("Should reflect configuration changes from ArgoCD CR to the agent deployment", func() {
370-
371366
By("Create ArgoCD instance")
372367

373368
argoCD.Spec.ArgoCDAgent.Agent.Image = common.ArgoCDAgentAgentDefaultImageName
@@ -395,7 +390,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
395390
Expect(k8sClient.Get(ctx, client.ObjectKey{Name: argoCDName, Namespace: ns.Name}, argoCD)).To(Succeed())
396391

397392
argocdFixture.Update(argoCD, func(ac *argov1beta1api.ArgoCD) {
398-
399393
ac.Spec.ArgoCDAgent.Agent.LogLevel = "trace"
400394
ac.Spec.ArgoCDAgent.Agent.LogFormat = "json"
401395
ac.Spec.ArgoCDAgent.Agent.Image = "quay.io/argoprojlabs/argocd-agent:v0.5.1"
@@ -410,7 +404,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
410404
ac.Spec.ArgoCDAgent.Agent.TLS.Insecure = ptr.To(true)
411405
ac.Spec.ArgoCDAgent.Agent.TLS.SecretName = "argocd-agent-client-tls-v2"
412406
ac.Spec.ArgoCDAgent.Agent.TLS.RootCASecretName = "argocd-agent-ca-v2"
413-
414407
})
415408

416409
By("Verify agent has the updated image we specified in ArgoCD CR")
@@ -451,7 +444,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
451444
})
452445

453446
It("should deploy agent via namespace-scoped ArgoCD instance and verify cluster role and cluster role binding are not created", func() {
454-
455447
By("Create namespace-scoped ArgoCD instance")
456448

457449
// Create namespace for hosting namespace-scoped ArgoCD instance with agent
@@ -505,7 +497,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
505497
})
506498

507499
It("should delete existing cluster role and cluster role binding if ArgoCD instance is namespace-scoped", func() {
508-
509500
By("Create namespace-scoped ArgoCD instance namespace")
510501

511502
// Create namespace for hosting namespace-scoped ArgoCD instance with agent
@@ -585,7 +576,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
585576
})
586577

587578
It("should create and delete agent ServiceMonitor based on prometheus enabled flag", func() {
588-
589579
By("Create ArgoCD instance with agent enabled and prometheus enabled")
590580

591581
argoCD.Spec.Prometheus.Enabled = true
@@ -632,5 +622,33 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
632622

633623
Eventually(agentServiceMonitor, "2m", "2s").Should(k8sFixture.NotExistByName())
634624
})
625+
626+
It("shouldn't create ClusterRole and ClusterRoleBinding for agent if spec.DefaultClusterScopedRoleDisabled is set", func() {
627+
By("Create ArgoCD instance with principal enabled and DefaultClusterScopedRoleDisabled is true")
628+
argoCD.Spec.DefaultClusterScopedRoleDisabled = true
629+
Expect(k8sClient.Create(ctx, argoCD)).To(Succeed())
630+
631+
By("Verify ClusterRole and ClusterRoleBinding do not exist")
632+
Eventually(clusterRole, "60s", "2s").Should(k8sFixture.NotExistByName())
633+
Eventually(clusterRoleBinding, "60s", "2s").Should(k8sFixture.NotExistByName())
634+
635+
By("Namespaced RBAC objects should still exist")
636+
Eventually(role, "60s", "2s").Should(k8sFixture.ExistByName())
637+
Eventually(roleBinding, "60s", "2s").Should(k8sFixture.ExistByName())
638+
639+
By("Unset DefaultClusterScopedRoleDisabled and make sure cluster scoped RBAC objects are created")
640+
argocdFixture.Update(argoCD, func(ac *argov1beta1api.ArgoCD) {
641+
ac.Spec.DefaultClusterScopedRoleDisabled = false
642+
})
643+
Eventually(clusterRole, "60s", "2s").Should(k8sFixture.ExistByName())
644+
Eventually(clusterRoleBinding, "60s", "2s").Should(k8sFixture.ExistByName())
645+
646+
By("Setting DefaultClusterScopedRoleDisabled again deletes clusterRole and clusterRoleBinding")
647+
argocdFixture.Update(argoCD, func(ac *argov1beta1api.ArgoCD) {
648+
ac.Spec.DefaultClusterScopedRoleDisabled = true
649+
})
650+
Eventually(clusterRole, "60s", "2s").Should(k8sFixture.NotExistByName())
651+
Eventually(clusterRoleBinding, "60s", "2s").Should(k8sFixture.NotExistByName())
652+
})
635653
})
636654
})

0 commit comments

Comments
 (0)