Skip to content

Commit

Permalink
Fix E2E test
Browse files Browse the repository at this point in the history
  • Loading branch information
nesmabadr committed Oct 14, 2024
1 parent 3abcec3 commit c49ba2b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 60 additions & 0 deletions pkg/testutils/modulereleasemeta.go
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 6 additions & 0 deletions tests/e2e/module_deletion_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 6 additions & 0 deletions tests/e2e/module_upgrade_new_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit c49ba2b

Please sign in to comment.