From c49ba2b56e9f3f912d5d11c7d3bcec49bf4d3694 Mon Sep 17 00:00:00 2001 From: "Badr, Nesma" Date: Mon, 14 Oct 2024 15:30:01 +0200 Subject: [PATCH] Fix E2E test --- .../action.yml | 1 + pkg/testutils/modulereleasemeta.go | 60 +++++++++++++++++++ tests/e2e/module_deletion_upgrade_test.go | 6 ++ tests/e2e/module_upgrade_new_version_test.go | 6 ++ 4 files changed, 73 insertions(+) create mode 100644 pkg/testutils/modulereleasemeta.go diff --git a/.github/actions/deploy-template-operator-with-modulereleasemeta/action.yml b/.github/actions/deploy-template-operator-with-modulereleasemeta/action.yml index 32ef5b74e7..75bedc3b52 100644 --- a/.github/actions/deploy-template-operator-with-modulereleasemeta/action.yml +++ b/.github/actions/deploy-template-operator-with-modulereleasemeta/action.yml @@ -38,6 +38,7 @@ runs: run: | sed -i 's/template-operator-fast/template-operator-2.4.2-e2e-test/g' tests/moduletemplates/moduletemplate_template_operator_v2_fast.yaml sed -i 's/template-operator-regular/template-operator-1.1.1-e2e-test/g' tests/moduletemplates/moduletemplate_template_operator_v1_regular.yaml + sed -i 's/template-operator-regular/template-operator-2.4.2-e2e-test/g' tests/moduletemplates/moduletemplate_template_operator_v2_regular_new_version.yaml kubectl apply -f tests/moduletemplates/moduletemplate_template_operator_v2_fast.yaml kubectl apply -f tests/moduletemplates/moduletemplate_template_operator_v1_regular.yaml diff --git a/pkg/testutils/modulereleasemeta.go b/pkg/testutils/modulereleasemeta.go new file mode 100644 index 0000000000..3fda7508c8 --- /dev/null +++ b/pkg/testutils/modulereleasemeta.go @@ -0,0 +1,60 @@ +package testutils + +import ( + "context" + "fmt" + + "sigs.k8s.io/controller-runtime/pkg/client" + + "github.com/kyma-project/lifecycle-manager/api/v1beta2" + "github.com/kyma-project/lifecycle-manager/pkg/util" +) + +func UpdateChannelVersionIfMRMExists(ctx context.Context, clnt client.Client, + moduleName, namespace, channel, version string, +) error { + mrm, err := GetModuleReleaseMeta(ctx, moduleName, namespace, clnt) + if err != nil { + if util.IsNotFound(err) { + return nil + } + return fmt.Errorf("get module release meta: %w", err) + } + + channelFound := false + for i, ch := range mrm.Spec.Channels { + if ch.Channel == channel { + mrm.Spec.Channels[i].Version = version + channelFound = true + break + } + } + + if !channelFound { + mrm.Spec.Channels = append(mrm.Spec.Channels, v1beta2.ChannelVersionAssignment{ + Channel: channel, + Version: version, + }) + } + + if err = clnt.Update(ctx, mrm); err != nil { + return fmt.Errorf("update module release meta: %w", err) + } + + return nil +} + +func GetModuleReleaseMeta(ctx context.Context, moduleName, namespace string, + clnt client.Client, +) (*v1beta2.ModuleReleaseMeta, error) { + mrm := &v1beta2.ModuleReleaseMeta{} + + err := clnt.Get(ctx, client.ObjectKey{ + Namespace: namespace, + Name: moduleName, + }, mrm) + if err != nil { + return nil, fmt.Errorf("get kyma: %w", err) + } + return mrm, nil +} diff --git a/tests/e2e/module_deletion_upgrade_test.go b/tests/e2e/module_deletion_upgrade_test.go index 8bbe4548d7..e4f5f2c31c 100644 --- a/tests/e2e/module_deletion_upgrade_test.go +++ b/tests/e2e/module_deletion_upgrade_test.go @@ -89,6 +89,12 @@ var _ = Describe("Kyma Module Upgrade Under Deletion", Ordered, func() { out, err := cmd.CombinedOutput() Expect(err).NotTo(HaveOccurred()) GinkgoWriter.Printf(string(out)) + + By("And ModuleReleaseMeta is updated if it exists") + Eventually(UpdateChannelVersionIfMRMExists). + WithContext(ctx). + WithArguments(kcpClient, module.Name, ControlPlaneNamespace, v1beta2.DefaultChannel, "2.4.2-e2e-test"). + Should(Succeed()) }) It("Then Kyma Module is updated on SKR Cluster", func() { diff --git a/tests/e2e/module_upgrade_new_version_test.go b/tests/e2e/module_upgrade_new_version_test.go index beecd1a272..af9f69fe4b 100644 --- a/tests/e2e/module_upgrade_new_version_test.go +++ b/tests/e2e/module_upgrade_new_version_test.go @@ -50,6 +50,12 @@ var _ = Describe("Module Upgrade By New Version", Ordered, func() { kcpClient, newTemplateFilePath)). Should(Succeed()) + + By("And ModuleReleaseMeta is updated if it exists") + Eventually(UpdateChannelVersionIfMRMExists). + WithContext(ctx). + WithArguments(kcpClient, module.Name, ControlPlaneNamespace, v1beta2.DefaultChannel, "2.4.2-e2e-test"). + Should(Succeed()) }) It("Then Module CR exists", func() {