|
| 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 | + rolloutmanagerv1alpha1 "github.com/argoproj-labs/argo-rollouts-manager/api/v1alpha1" |
| 23 | + . "github.com/onsi/ginkgo/v2" |
| 24 | + . "github.com/onsi/gomega" |
| 25 | + "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture" |
| 26 | + k8sFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/k8s" |
| 27 | + fixtureUtils "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils" |
| 28 | + appsv1 "k8s.io/api/apps/v1" |
| 29 | + corev1 "k8s.io/api/core/v1" |
| 30 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 31 | + "sigs.k8s.io/controller-runtime/pkg/client" |
| 32 | +) |
| 33 | + |
| 34 | +var _ = Describe("GitOps Operator Parallel E2E Tests", func() { |
| 35 | + |
| 36 | + Context("1-121_validate_custom_labels_rollouts", func() { |
| 37 | + |
| 38 | + var ( |
| 39 | + k8sClient client.Client |
| 40 | + ctx context.Context |
| 41 | + ) |
| 42 | + |
| 43 | + BeforeEach(func() { |
| 44 | + fixture.EnsureParallelCleanSlate() |
| 45 | + k8sClient, _ = fixtureUtils.GetE2ETestKubeClient() |
| 46 | + ctx = context.Background() |
| 47 | + }) |
| 48 | + |
| 49 | + It("ensures that custom labels set by the operator are added to Argo Rollouts resources", func() { |
| 50 | + |
| 51 | + By("creating namespace-scoped RolloutManager instance") |
| 52 | + rolloutManager := &rolloutmanagerv1alpha1.RolloutManager{ |
| 53 | + ObjectMeta: metav1.ObjectMeta{ |
| 54 | + Name: "test-rollout-manager", |
| 55 | + Namespace: "openshift-gitops", |
| 56 | + }, |
| 57 | + } |
| 58 | + Expect(k8sClient.Create(ctx, rolloutManager)).To(Succeed()) |
| 59 | + |
| 60 | + By("waiting for Argo Rollouts deployment to be created and become available") |
| 61 | + depl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "argo-rollouts", Namespace: "openshift-gitops"}} |
| 62 | + Eventually(depl, "2m", "2s").Should(k8sFixture.ExistByName()) |
| 63 | + |
| 64 | + By("verifying Argo Rollouts Secret has the custom labels") |
| 65 | + labelKey := "operator.argoproj.io/tracked-by" |
| 66 | + labelValue := "argocd" |
| 67 | + secret := &corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "argo-rollouts-notification-secret", Namespace: "openshift-gitops"}} |
| 68 | + Eventually(secret, "2m", "1s").Should(k8sFixture.ExistByName()) |
| 69 | + Expect(secret.Labels).Should(HaveKeyWithValue(labelKey, labelValue)) |
| 70 | + |
| 71 | + By("verifying Argo Rollouts ConfigMap has the custom labels") |
| 72 | + configMap := &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "argo-rollouts-config", Namespace: "openshift-gitops"}} |
| 73 | + Eventually(configMap, "2m", "1s").Should(k8sFixture.ExistByName()) |
| 74 | + Expect(configMap.Labels).Should(HaveKeyWithValue(labelKey, labelValue)) |
| 75 | + |
| 76 | + By("updating RolloutManager spec") |
| 77 | + |
| 78 | + // Add a new label to trigger reconciliation |
| 79 | + if rolloutManager.ObjectMeta.Labels == nil { |
| 80 | + rolloutManager.ObjectMeta.Labels = make(map[string]string) |
| 81 | + } |
| 82 | + rolloutManager.ObjectMeta.Labels["test-update"] = "true" |
| 83 | + patch := client.MergeFrom(rolloutManager.DeepCopy()) |
| 84 | + Expect(k8sClient.Patch(ctx, rolloutManager, patch)).To(Succeed()) |
| 85 | + |
| 86 | + By("ensures that custom labels persist in configmap after RolloutManager updates") |
| 87 | + configMap = &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "argo-rollouts-config", Namespace: "openshift-gitops"}} |
| 88 | + Eventually(configMap, "2m", "1s").Should(k8sFixture.ExistByName()) |
| 89 | + Expect(configMap.Labels).Should(HaveKeyWithValue(labelKey, labelValue)) |
| 90 | + |
| 91 | + By("ensures that custom labels persist in secret after RolloutManager updates") |
| 92 | + secret = &corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "argo-rollouts-notification-secret", Namespace: "openshift-gitops"}} |
| 93 | + Eventually(secret, "2m", "1s").Should(k8sFixture.ExistByName()) |
| 94 | + Expect(secret.Labels).Should(HaveKeyWithValue(labelKey, labelValue)) |
| 95 | + }) |
| 96 | + |
| 97 | + }) |
| 98 | +}) |
0 commit comments