diff --git a/.github/actions/deploy-template-operator-with-modulereleasemeta/action.yml b/.github/actions/deploy-template-operator-with-modulereleasemeta/action.yml index 77ccaa2280..b91fc5e082 100644 --- a/.github/actions/deploy-template-operator-with-modulereleasemeta/action.yml +++ b/.github/actions/deploy-template-operator-with-modulereleasemeta/action.yml @@ -62,7 +62,8 @@ runs: matrix.e2e-test == 'misconfigured-kyma-secret' || matrix.e2e-test == 'unmanage-module' || matrix.e2e-test == 'modulereleasemeta-watch-trigger' || - matrix.e2e-test == 'modulereleasemeta-with-obsolete-moduletemplate' + matrix.e2e-test == 'modulereleasemeta-with-obsolete-moduletemplate' || + matrix.e2e-test == 'labelling' }} shell: bash run: | diff --git a/.github/actions/deploy-template-operator/action.yml b/.github/actions/deploy-template-operator/action.yml index 3f403d5d18..12b40db7a3 100644 --- a/.github/actions/deploy-template-operator/action.yml +++ b/.github/actions/deploy-template-operator/action.yml @@ -18,7 +18,8 @@ runs: matrix.e2e-test == 'module-consistency' || matrix.e2e-test == 'skip-manifest-reconciliation' || matrix.e2e-test == 'misconfigured-kyma-secret' || - matrix.e2e-test == 'unmanage-module' + matrix.e2e-test == 'unmanage-module' || + matrix.e2e-test == 'labelling' }} shell: bash run: | diff --git a/.github/workflows/test-e2e-with-modulereleasemeta.yml b/.github/workflows/test-e2e-with-modulereleasemeta.yml index 520abf6d3e..673d1d8bf3 100644 --- a/.github/workflows/test-e2e-with-modulereleasemeta.yml +++ b/.github/workflows/test-e2e-with-modulereleasemeta.yml @@ -66,6 +66,7 @@ jobs: - module-status-on-skr-connection-lost - modulereleasemeta-watch-trigger - modulereleasemeta-not-allowed-installation + - labelling runs-on: ubuntu-latest timeout-minutes: 20 diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index 7ccb95e697..7dbdf594a9 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -63,6 +63,7 @@ jobs: - misconfigured-kyma-secret - rbac-privileges - ocm-compatible-module-template + - labelling runs-on: ubuntu-latest timeout-minutes: 20 steps: diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 7b8cd36761..a34e46209c 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -105,6 +105,7 @@ "ocm-compatible-module-template", "modulereleasemeta-sync", "modulereleasemeta-not-allowed-installation", + "labelling" ] }, { diff --git a/tests/e2e/Makefile b/tests/e2e/Makefile index 1ff6225ea9..28cb5ba689 100644 --- a/tests/e2e/Makefile +++ b/tests/e2e/Makefile @@ -168,3 +168,6 @@ module-status-on-skr-connection-lost: modulereleasemeta-not-allowed-installation: go test -timeout 20m -ginkgo.v -ginkgo.focus "ModuleReleaseMeta Not Allowed Installation" + +labelling: + go test -timeout 20m -ginkgo.v -ginkgo.focus "Labelling SKR resources" diff --git a/tests/e2e/labelling_test.go b/tests/e2e/labelling_test.go new file mode 100644 index 0000000000..d77632f735 --- /dev/null +++ b/tests/e2e/labelling_test.go @@ -0,0 +1,102 @@ +package e2e_test + +import ( + admissionregistrationv1 "k8s.io/api/admissionregistration/v1" + apiappsv1 "k8s.io/api/apps/v1" + apicorev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/types" + + "github.com/kyma-project/lifecycle-manager/api/shared" + "github.com/kyma-project/lifecycle-manager/api/v1beta2" + + . "github.com/kyma-project/lifecycle-manager/pkg/testutils" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +var managedSkrResources = map[types.NamespacedName]schema.GroupVersionKind{ + {Name: "default", Namespace: RemoteNamespace}: v1beta2.GroupVersion.WithKind("Kyma"), + {Name: "skr-webhook", Namespace: RemoteNamespace}: apiappsv1.SchemeGroupVersion.WithKind("Deployment"), + {Name: "skr-webhook", Namespace: RemoteNamespace}: admissionregistrationv1.SchemeGroupVersion.WithKind("ValidatingWebhookConfiguration"), + {Name: "skr-webhook-tls", Namespace: RemoteNamespace}: apicorev1.SchemeGroupVersion.WithKind("Secret"), + {Name: "skr-webhook-sa", Namespace: RemoteNamespace}: apicorev1.SchemeGroupVersion.WithKind("ServiceAccount"), + {Name: RemoteNamespace, Namespace: ""}: apicorev1.SchemeGroupVersion.WithKind("Namespace"), +} + +var _ = Describe("Labelling SKR resources", Ordered, func() { + kyma := NewKymaWithSyncLabel("kyma-sample", ControlPlaneNamespace, v1beta2.DefaultChannel) + InitEmptyKymaBeforeAll(kyma) + CleanupKymaAfterAll(kyma) + + module := NewTemplateOperator(v1beta2.DefaultChannel) + + Context("Given SKR Cluster", func() { + It("When SKR cluster is setup", func() { + By("Then SKR Kyma CR is labelled with watched-by label") + Eventually(HasExpectedLabel). + WithContext(ctx). + WithArguments( + skrClient, + types.NamespacedName{Name: "default", Namespace: RemoteNamespace}, + v1beta2.GroupVersion.WithKind("Kyma"), + shared.WatchedByLabel, + shared.WatchedByLabelValue). + Should(Succeed()) + By("And managed SKR resources are labelled with managed-by label") + for name, gvk := range managedSkrResources { + Eventually(HasExpectedLabel). + WithContext(ctx). + WithArguments( + skrClient, + name, + gvk, + shared.ManagedBy, + shared.ManagedByLabelValue). + Should(Succeed()) + } + By("And remote namespace is labelled with istio and warden labels") + Eventually(EnsureNamespaceHasCorrectLabels). + WithContext(ctx). + WithArguments(skrClient, RemoteNamespace, map[string]string{ + "istio-injection": "enabled", + "namespaces.warden.kyma-project.io/validate": "enabled", + }).Should(Succeed()) + }) + + It("When Kyma Module is enabled in SKR Kyma CR", func() { + Eventually(EnableModule). + WithContext(ctx). + WithArguments(skrClient, defaultRemoteKymaName, RemoteNamespace, module). + Should(Succeed()) + Eventually(DeploymentIsReady). + WithContext(ctx). + WithArguments(skrClient, ModuleResourceName, TestModuleResourceNamespace). + Should(Succeed()) + + By("Then all manifest resources are labelled with managed-by label") + manifest, err := GetManifest(ctx, kcpClient, kyma.GetName(), kyma.GetNamespace(), + module.Name) + Expect(err).Should(Succeed()) + for _, resource := range manifest.Status.Synced { + name := types.NamespacedName{Name: resource.Name, Namespace: resource.Namespace} + gvk := schema.GroupVersionKind{ + Group: resource.Group, + Version: resource.Version, + Kind: resource.Kind, + } + Eventually(HasExpectedLabel). + WithContext(ctx). + WithArguments(skrClient, name, gvk, + shared.ManagedBy, shared.ManagedByLabelValue).Should(Succeed()) + } + + By("And default CR is labbelled with managed-by label") + Eventually(CheckSampleCRHasExpectedLabel). + WithContext(ctx). + WithArguments(TestModuleCRName, RemoteNamespace, skrClient, shared.ManagedBy, + shared.ManagedByLabelValue). + Should(Succeed()) + }) + }) +}) diff --git a/tests/e2e/manifest_reconciliation_test.go b/tests/e2e/manifest_reconciliation_test.go index 5b907eba9d..2154c6f5b4 100644 --- a/tests/e2e/manifest_reconciliation_test.go +++ b/tests/e2e/manifest_reconciliation_test.go @@ -36,13 +36,6 @@ var _ = Describe("Manifest Skip Reconciliation Label", Ordered, func() { WithContext(ctx). WithArguments(TestModuleCRName, RemoteNamespace, skrClient, shared.StateReady). Should(Succeed()) - By("And the SKR Module Default CR has the Managed-by Label") - Eventually(CheckSampleCRHasExpectedLabel). - WithContext(ctx). - WithArguments(TestModuleCRName, RemoteNamespace, skrClient, shared.ManagedBy, - shared.ManagedByLabelValue). - Should(Succeed()) - By("And the KCP Kyma CR is in a \"Ready\" State") Eventually(KymaIsInState). WithContext(ctx). diff --git a/tests/e2e/utils_test.go b/tests/e2e/utils_test.go index 281ce56c89..8e414a01bb 100644 --- a/tests/e2e/utils_test.go +++ b/tests/e2e/utils_test.go @@ -66,13 +66,6 @@ func InitEmptyKymaBeforeAll(kyma *v1beta2.Kyma) { WithContext(ctx). WithArguments(RemoteNamespace, []v1beta2.Module{}, skrClient, shared.StateReady). Should(Succeed()) - By("And Remote Namespace is labelled correctly") - Eventually(EnsureNamespaceHasCorrectLabels). - WithContext(ctx). - WithArguments(skrClient, RemoteNamespace, map[string]string{ - "istio-injection": "enabled", - "namespaces.warden.kyma-project.io/validate": "enabled", - }).Should(Succeed()) By("And Runtime Watcher deployment is up and running in SKR", func() { Eventually(CheckPodLogs). WithContext(ctx).