-
Notifications
You must be signed in to change notification settings - Fork 359
Added E2E tests for role ownership validation #1208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alkakumari016
wants to merge
14
commits into
redhat-developer:master
Choose a base branch
from
alkakumari016:role_val_e2e
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
aa1ad52
added E2E tests for role ownership validation and rupdate argocd-oper…
alkakumari016 1c80dc1
resolve gosec error
alkakumari016 da07e0b
added coderabbit suggestions
alkakumari016 fc5bbf6
utilised const in test file
alkakumari016 ab625bd
added proper bug description and changed variable names
alkakumari016 f07a042
removed unwanted checks from ginkgo test of image updater
alkakumari016 7ce7abe
increased timout of sequential test to 270m
alkakumari016 3131728
Merge branch 'master' of github.com:redhat-developer/gitops-operator …
alkakumari016 500c95f
creating argocd instamce instead of using default instance to rectify…
alkakumari016 5df4eb5
changed ginkgo test names
alkakumari016 520dea9
Merge branch 'master' of github.com:redhat-developer/gitops-operator …
alkakumari016 7506074
changed argocd-operator import path to gitops-operator
alkakumari016 b9fd628
moved argocd creation from Before block to It block
alkakumari016 bcc8be2
enabled applicationset in validate_role_ownership e2e test
alkakumari016 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
201 changes: 201 additions & 0 deletions
201
test/openshift/e2e/ginkgo/sequential/1-125_validate_role_ownership.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,201 @@ | ||
| /* | ||
| Copyright 2025. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
| package sequential | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| argov1beta1api "github.com/argoproj-labs/gitops-operator/argocd-operator/api/v1beta1" | ||
| argocdFixture "github.com/argoproj-labs/gitops-operator/argocd-operator/tests/ginkgo/fixture/argocd" | ||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture" | ||
| k8sFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/k8s" | ||
| fixtureUtils "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" | ||
| rbacv1 "k8s.io/api/rbac/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| ) | ||
|
|
||
| var _ = Describe("GitOps Operator Parallel E2E Tests", func() { | ||
|
|
||
| Context("1-125_validate_role_ownership", func() { | ||
|
|
||
| var ( | ||
| ctx context.Context | ||
| k8sClient client.Client | ||
| argoCD *argov1beta1api.ArgoCD | ||
| ) | ||
| const ( | ||
| applicationControllerClusterRoleName = "openshift-gitops-openshift-gitops-argocd-application-controller" | ||
| applicationSetControllerClusterRoleName = "openshift-gitops-openshift-gitops-argocd-applicationset-controller" | ||
| serverClusterRoleName = "openshift-gitops-openshift-gitops-argocd-server" | ||
| applicationControllerClusterRoleBindingName = "openshift-gitops-openshift-gitops-argocd-application-controller" | ||
| applicationSetControllerClusterRoleBindingName = "openshift-gitops-openshift-gitops-argocd-applicationset-controller" | ||
| serverClusterRoleBindingName = "openshift-gitops-openshift-gitops-argocd-server" | ||
| ) | ||
|
|
||
| BeforeEach(func() { | ||
| fixture.EnsureSequentialCleanSlate() | ||
| fixture.SetEnvInOperatorSubscriptionOrDeployment("ARGOCD_CLUSTER_CONFIG_NAMESPACES", "openshift-gitops") | ||
|
|
||
| k8sClient, _ = fixtureUtils.GetE2ETestKubeClient() | ||
| ctx = context.Background() | ||
| }) | ||
|
|
||
| It("validates that namespace-scoped resources do not delete a ClusterRole or ClusterRoleBinding with a matching generated name", func() { | ||
|
|
||
| ns, cleanupFunc := fixture.CreateNamespaceWithCleanupFunc("openshift-gitops") | ||
| defer cleanupFunc() | ||
|
|
||
| By("creating cluster scoped ArgoCD instance") | ||
| argoCD = &argov1beta1api.ArgoCD{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "openshift-gitops", | ||
| Namespace: ns.Name, | ||
| }, | ||
| Spec: argov1beta1api.ArgoCDSpec{ | ||
| ApplicationSet: &argov1beta1api.ArgoCDApplicationSet{}, | ||
| }, | ||
| } | ||
| Expect(k8sClient.Create(ctx, argoCD)).To(Succeed()) | ||
| Eventually(argoCD, "5m", "5s").Should(argocdFixture.BeAvailable()) | ||
|
|
||
| By("checking that the default ClusterRole and clusterroleBinding for the ArgoCD Application Controller and Server exists") | ||
| defaultControllerClusterRole := &rbacv1.ClusterRole{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: applicationControllerClusterRoleName, | ||
| }, | ||
| } | ||
| defaultApplicationSetControllerClusterRole := &rbacv1.ClusterRole{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: applicationSetControllerClusterRoleName, | ||
| }, | ||
| } | ||
| defaultServerClusterRole := &rbacv1.ClusterRole{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: serverClusterRoleName, | ||
| }, | ||
| } | ||
| defaultControllerClusterRoleBinding := &rbacv1.ClusterRoleBinding{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: applicationControllerClusterRoleBindingName, | ||
| }, | ||
| } | ||
| defaultApplicationSetControllerClusterRoleBinding := &rbacv1.ClusterRoleBinding{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: applicationSetControllerClusterRoleBindingName, | ||
| }, | ||
| } | ||
| defaultServerClusterRoleBinding := &rbacv1.ClusterRoleBinding{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: serverClusterRoleBindingName, | ||
| }, | ||
| } | ||
| Eventually(defaultControllerClusterRole).Should(k8sFixture.ExistByName()) | ||
| Eventually(defaultApplicationSetControllerClusterRole).Should(k8sFixture.ExistByName()) | ||
| Eventually(defaultServerClusterRole).Should(k8sFixture.ExistByName()) | ||
| Eventually(defaultControllerClusterRoleBinding).Should(k8sFixture.ExistByName()) | ||
| Eventually(defaultApplicationSetControllerClusterRoleBinding).Should(k8sFixture.ExistByName()) | ||
| Eventually(defaultServerClusterRoleBinding).Should(k8sFixture.ExistByName()) | ||
|
|
||
| By("fetching initial UID of the clusterrole") | ||
| initialControllerUid := defaultControllerClusterRole.GetUID() | ||
| initialApplicationSetControllerUid := defaultApplicationSetControllerClusterRole.GetUID() | ||
| initialServerUid := defaultServerClusterRole.GetUID() | ||
| initialControllerRoleBindingUid := defaultControllerClusterRoleBinding.GetUID() | ||
| initialApplicationSetControllerRoleBindingUid := defaultApplicationSetControllerClusterRoleBinding.GetUID() | ||
| initialServerRoleBindingUid := defaultServerClusterRoleBinding.GetUID() | ||
|
|
||
| By("creating new namespace scoped ArgoCD instance to create the condition where clusterrole and clusterrolebinding are deleted by namespaced scoped resources") | ||
| ns, nsCleanup := fixture.CreateNamespaceWithCleanupFunc("gitops") | ||
| defer nsCleanup() | ||
|
|
||
| argoCD := &argov1beta1api.ArgoCD{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "openshift-gitops-openshift", | ||
| Namespace: ns.Name, | ||
| }, | ||
| Spec: argov1beta1api.ArgoCDSpec{ | ||
| ApplicationSet: &argov1beta1api.ArgoCDApplicationSet{}, | ||
| }, | ||
| } | ||
| Expect(k8sClient.Create(ctx, argoCD)).To(Succeed()) | ||
|
|
||
| Eventually(argoCD, "5m", "5s").Should(argocdFixture.BeAvailable()) | ||
|
|
||
| By("checking that the default ClusterRole for the ArgoCD Application Controller still exists") | ||
| afterReconcileControllerClusterRole := &rbacv1.ClusterRole{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: applicationControllerClusterRoleName, | ||
| }, | ||
| } | ||
| afterReconcileApplicationSetControllerCR := &rbacv1.ClusterRole{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: applicationSetControllerClusterRoleName, | ||
| }, | ||
| } | ||
| afterReconcileServerCR := &rbacv1.ClusterRole{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: serverClusterRoleName, | ||
| }, | ||
| } | ||
| afterReconcileControllerCRB := &rbacv1.ClusterRoleBinding{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: applicationControllerClusterRoleBindingName, | ||
| }, | ||
| } | ||
| afterReconcileApplicationSetControllerCRB := &rbacv1.ClusterRoleBinding{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: applicationSetControllerClusterRoleBindingName, | ||
| }, | ||
| } | ||
| afterReconcileServerCRB := &rbacv1.ClusterRoleBinding{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: serverClusterRoleBindingName, | ||
| }, | ||
| } | ||
|
|
||
| Eventually(afterReconcileControllerClusterRole).Should(k8sFixture.ExistByName()) | ||
| Eventually(afterReconcileApplicationSetControllerCR).Should(k8sFixture.ExistByName()) | ||
| Eventually(afterReconcileServerCR).Should(k8sFixture.ExistByName()) | ||
|
|
||
| Eventually(afterReconcileControllerCRB).Should(k8sFixture.ExistByName()) | ||
| Eventually(afterReconcileApplicationSetControllerCRB).Should(k8sFixture.ExistByName()) | ||
| Eventually(afterReconcileServerCRB).Should(k8sFixture.ExistByName()) | ||
|
|
||
| By("fetching UID of the clusterrole after reconciliation") | ||
| afterReconcileControllerUid := afterReconcileControllerClusterRole.GetUID() | ||
| afterReconcileApplicationSetControllerUid := afterReconcileApplicationSetControllerCR.GetUID() | ||
| afterReconcileServerUid := afterReconcileServerCR.GetUID() | ||
|
|
||
| afterReconcileControllerRBUid := afterReconcileControllerCRB.GetUID() | ||
| afterReconcileApplicationSetControllerRBUid := afterReconcileApplicationSetControllerCRB.GetUID() | ||
| afterReconcileServerRBUid := afterReconcileServerCRB.GetUID() | ||
|
|
||
| By("comparing the UID to ensure that the ClusterRole and ClusterRoleBinding are not recreated") | ||
| Expect(initialControllerUid).To(Equal(afterReconcileControllerUid), "the ClusterRole was recreated") | ||
| Expect(initialApplicationSetControllerUid).To(Equal(afterReconcileApplicationSetControllerUid), "the ClusterRole was recreated") | ||
| Expect(initialServerUid).To(Equal(afterReconcileServerUid), "the ClusterRole was recreated") | ||
|
|
||
| Expect(initialControllerRoleBindingUid).To(Equal(afterReconcileControllerRBUid)) | ||
| Expect(initialApplicationSetControllerRoleBindingUid).To(Equal(afterReconcileApplicationSetControllerRBUid)) | ||
| Expect(initialServerRoleBindingUid).To(Equal(afterReconcileServerRBUid)) | ||
|
|
||
| }) | ||
|
|
||
| }) | ||
| }) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests are failing because applicationset is not enabled in this argocd instance. You can enable it by using