|
| 1 | +/* |
| 2 | +Copyright 2025. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package parallel |
| 18 | + |
| 19 | +import ( |
| 20 | + "context" |
| 21 | + |
| 22 | + . "github.com/onsi/ginkgo/v2" |
| 23 | + . "github.com/onsi/gomega" |
| 24 | + argov1beta1api "github.com/redhat-developer/gitops-operator/argocd-operator/api/v1beta1" |
| 25 | + "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture" |
| 26 | + argocdFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/argocd" |
| 27 | + k8sFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/k8s" |
| 28 | + fixtureUtils "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" |
| 29 | + appsv1 "k8s.io/api/apps/v1" |
| 30 | + corev1 "k8s.io/api/core/v1" |
| 31 | + "k8s.io/apimachinery/pkg/api/resource" |
| 32 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 33 | + "sigs.k8s.io/controller-runtime/pkg/client" |
| 34 | +) |
| 35 | + |
| 36 | +var _ = Describe("GitOps Operator Parallel E2E Tests", func() { |
| 37 | + |
| 38 | + Context("1-064_validate_deployment_attributes", func() { |
| 39 | + |
| 40 | + var ( |
| 41 | + k8sClient client.Client |
| 42 | + ctx context.Context |
| 43 | + ) |
| 44 | + |
| 45 | + expectedSecurityContext := corev1.SecurityContext{ |
| 46 | + Capabilities: &corev1.Capabilities{Drop: []corev1.Capability{"ALL"}}, |
| 47 | + AllowPrivilegeEscalation: new(false), |
| 48 | + RunAsNonRoot: new(true), |
| 49 | + ReadOnlyRootFilesystem: new(true), |
| 50 | + SeccompProfile: &corev1.SeccompProfile{ |
| 51 | + Type: corev1.SeccompProfileTypeRuntimeDefault, |
| 52 | + LocalhostProfile: nil, |
| 53 | + }, |
| 54 | + } |
| 55 | + |
| 56 | + verifiedDeployments := func() []string { |
| 57 | + deployments := []string{ |
| 58 | + "argocd-applicationset-controller", "argocd-notifications-controller", "argocd-redis", "argocd-repo-server", "argocd-server", |
| 59 | + "argocd-commit-server", "argocd-argocd-image-updater-controller", |
| 60 | + } |
| 61 | + if fixture.RunningOnOpenShift() { |
| 62 | + deployments = append(deployments, "argocd-dex-server") |
| 63 | + } |
| 64 | + return deployments |
| 65 | + } |
| 66 | + |
| 67 | + initialResources := &corev1.ResourceRequirements{ |
| 68 | + Limits: corev1.ResourceList{ |
| 69 | + corev1.ResourceCPU: resource.MustParse("500m"), |
| 70 | + corev1.ResourceMemory: resource.MustParse("512Mi"), |
| 71 | + }, |
| 72 | + Requests: corev1.ResourceList{ |
| 73 | + corev1.ResourceCPU: resource.MustParse("250m"), |
| 74 | + corev1.ResourceMemory: resource.MustParse("256Mi"), |
| 75 | + }, |
| 76 | + } |
| 77 | + |
| 78 | + BeforeEach(func() { |
| 79 | + fixture.EnsureParallelCleanSlate() |
| 80 | + |
| 81 | + k8sClient, _ = fixtureUtils.GetE2ETestKubeClient() |
| 82 | + ctx = context.Background() |
| 83 | + }) |
| 84 | + |
| 85 | + It("verifies that Argo CD deployments have expected config", func() { |
| 86 | + |
| 87 | + By("creating simple namespace-scoped Argo CD instance") |
| 88 | + ns, cleanupFunc := fixture.CreateRandomE2ETestNamespaceWithCleanupFunc() |
| 89 | + defer cleanupFunc() |
| 90 | + |
| 91 | + argoCD := &argov1beta1api.ArgoCD{ |
| 92 | + ObjectMeta: metav1.ObjectMeta{Name: "argocd", Namespace: ns.Name}, |
| 93 | + Spec: argov1beta1api.ArgoCDSpec{ |
| 94 | + ApplicationSet: &argov1beta1api.ArgoCDApplicationSet{ |
| 95 | + Resources: initialResources, |
| 96 | + }, |
| 97 | + Notifications: argov1beta1api.ArgoCDNotifications{ |
| 98 | + Enabled: true, |
| 99 | + Resources: initialResources, |
| 100 | + }, |
| 101 | + Redis: argov1beta1api.ArgoCDRedisSpec{ |
| 102 | + Resources: initialResources, |
| 103 | + }, |
| 104 | + Repo: argov1beta1api.ArgoCDRepoSpec{ |
| 105 | + Resources: initialResources, |
| 106 | + // Creates new init container |
| 107 | + SystemCATrust: &argov1beta1api.ArgoCDSystemCATrustSpec{ |
| 108 | + DropImageCertificates: true, |
| 109 | + }, |
| 110 | + // TODO: override the Ubuntu specified image with a RHEL one. Drop once all images are on UBI |
| 111 | + Image: "quay.io/redhat-user-workloads/rh-openshift-gitops-tenant/argocd-rhel9", |
| 112 | + Version: "main", |
| 113 | + }, |
| 114 | + Server: argov1beta1api.ArgoCDServerSpec{ |
| 115 | + Resources: initialResources, |
| 116 | + }, |
| 117 | + CommitServer: argov1beta1api.ArgoCDCommitServerSpec{ |
| 118 | + Resources: initialResources, |
| 119 | + }, |
| 120 | + SourceHydrator: argov1beta1api.ArgoCDSourceHydratorSpec{ |
| 121 | + // Needed for commit server |
| 122 | + Enabled: new(true), |
| 123 | + }, |
| 124 | + ImageUpdater: argov1beta1api.ArgoCDImageUpdaterSpec{ |
| 125 | + Enabled: true, |
| 126 | + Resources: initialResources, |
| 127 | + }, |
| 128 | + }, |
| 129 | + } |
| 130 | + |
| 131 | + if fixture.RunningOnOpenShift() { |
| 132 | + argoCD.Spec.SSO = &argov1beta1api.ArgoCDSSOSpec{ |
| 133 | + Provider: argov1beta1api.SSOProviderTypeDex, |
| 134 | + Dex: &argov1beta1api.ArgoCDDexSpec{ |
| 135 | + OpenShiftOAuth: true, |
| 136 | + Resources: initialResources, |
| 137 | + }, |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + Expect(k8sClient.Create(ctx, argoCD)).To(Succeed()) |
| 142 | + |
| 143 | + By("waiting for ArgoCD to be ready") |
| 144 | + Eventually(argoCD, "5m", "5s").Should(argocdFixture.BeAvailable()) |
| 145 | + |
| 146 | + By("verifying that each Argo CD deployment has expected security context") |
| 147 | + for _, deployment := range verifiedDeployments() { |
| 148 | + By("verifying " + deployment) |
| 149 | + |
| 150 | + depl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: deployment, Namespace: ns.Name}} |
| 151 | + Eventually(depl).Should(k8sFixture.ExistByName()) |
| 152 | + |
| 153 | + if fixture.RunningOnOpenShift() { |
| 154 | + By("verifying security context") |
| 155 | + seccompProfile := depl.Spec.Template.Spec.SecurityContext.SeccompProfile.Type |
| 156 | + Expect(seccompProfile).To(Equal(corev1.SeccompProfileTypeRuntimeDefault), "deployment %s has unexpected seccomp profile", depl.Name) |
| 157 | + } |
| 158 | + |
| 159 | + containers := depl.Spec.Template.Spec.Containers |
| 160 | + Expect(containers).To(HaveLen(1)) |
| 161 | + for _, container := range containers { |
| 162 | + secContext := container.SecurityContext |
| 163 | + Expect(secContext).ToNot(BeNil(), "container %s has no security context", container.Name) |
| 164 | + Expect(*secContext).To(Equal(expectedSecurityContext), "container %s has unexpected security context", container.Name) |
| 165 | + |
| 166 | + Expect(container.Resources.Limits).To(Not(BeNil()), "container %s has no limits", container.Name) |
| 167 | + Expect(container.Resources.Requests).To(Not(BeNil()), "container %s has no requests", container.Name) |
| 168 | + } |
| 169 | + initContainers := depl.Spec.Template.Spec.InitContainers |
| 170 | + for _, container := range initContainers { |
| 171 | + secContext := container.SecurityContext |
| 172 | + Expect(secContext).ToNot(BeNil(), "init container %s has no security context", container.Name) |
| 173 | + Expect(*secContext).To(Equal(expectedSecurityContext), "init container %s has unexpected security context", container.Name) |
| 174 | + |
| 175 | + Expect(container.Resources.Limits).To(Not(BeNil()), "init container %s has no limits", container.Name) |
| 176 | + Expect(container.Resources.Requests).To(Not(BeNil()), "init container %s has no requests", container.Name) |
| 177 | + } |
| 178 | + } |
| 179 | + }) |
| 180 | + }) |
| 181 | +}) |
0 commit comments