Skip to content

Commit

Permalink
test: Add ModuleReleaseMeta Sync test (kyma-project#1980)
Browse files Browse the repository at this point in the history
* Add ModuleReleaseMeta Sync test - CRUD for ModuleTemplate

* Add ModuleReleaseMeta Sync test - CRUD for ModuleReleaseMeta

---------

Co-authored-by: Tomasz Smelcerz <[email protected]>
  • Loading branch information
nesmabadr and Tomasz-Smelcerz-SAP authored Oct 28, 2024
1 parent 0cb4df0 commit de3a208
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ runs:
working-directory: lifecycle-manager
if: ${{ matrix.e2e-test == 'module-upgrade-channel-switch' ||
matrix.e2e-test == 'module-upgrade-new-version' ||
matrix.e2e-test == 'upgrade-under-deletion'
matrix.e2e-test == 'upgrade-under-deletion' ||
matrix.e2e-test == 'modulereleasemeta-sync'
}}
shell: bash
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-e2e-with-modulereleasemeta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
- rbac-privileges
- ocm-compatible-module-template
- modulereleasemeta-with-obsolete-moduletemplate
- modulereleasemeta-sync
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
Expand Down
45 changes: 45 additions & 0 deletions pkg/testutils/modulereleasemeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package testutils

import (
"context"
"errors"
"fmt"

"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -10,6 +11,8 @@ import (
"github.com/kyma-project/lifecycle-manager/pkg/util"
)

var ErrNotExpectedChannelVersion = errors.New("channel-version pair not found")

func UpdateChannelVersionIfModuleReleaseMetaExists(ctx context.Context, clnt client.Client,
moduleName, namespace, channel, version string,
) error {
Expand Down Expand Up @@ -58,3 +61,45 @@ func GetModuleReleaseMeta(ctx context.Context, moduleName, namespace string,
}
return mrm, nil
}

func ModuleReleaseMetaExists(ctx context.Context, moduleName, namespace string, clnt client.Client) error {
if _, err := GetModuleReleaseMeta(ctx, moduleName, namespace, clnt); err != nil {
if util.IsNotFound(err) {
return ErrNotFound
}
}

return nil
}

func ModuleReleaseMetaContainsCorrectChannelVersion(ctx context.Context,
moduleName, namespace, channel, version string, clnt client.Client,
) error {
mrm, err := GetModuleReleaseMeta(ctx, moduleName, namespace, clnt)
if err != nil {
return fmt.Errorf("failed to fetch modulereleasemeta, %w", err)
}

for _, ch := range mrm.Spec.Channels {
if ch.Channel == channel {
if ch.Version == version {
return nil
}
}
}

return ErrNotExpectedChannelVersion
}

func DeleteModuleReleaseMeta(ctx context.Context, moduleName, namespace string, clnt client.Client) error {
mrm, err := GetModuleReleaseMeta(ctx, moduleName, namespace, clnt)
if util.IsNotFound(err) {
return nil
}

err = client.IgnoreNotFound(clnt.Delete(ctx, mrm))
if err != nil {
return fmt.Errorf("modulereleasemeta not deleted: %w", err)
}
return nil
}
5 changes: 4 additions & 1 deletion tests/e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,7 @@ ocm-compatible-module-template:
go test -timeout 20m -ginkgo.v -ginkgo.focus "OCM Format Module Template"

modulereleasemeta-with-obsolete-moduletemplate:
go test -timeout 20m -ginkgo.v -ginkgo.focus "ModuleReleaseMeta With Obsolete ModuleTemplate"
go test -timeout 20m -ginkgo.v -ginkgo.focus "ModuleReleaseMeta With Obsolete ModuleTemplate"

modulereleasemeta-sync:
go test -timeout 20m -ginkgo.v -ginkgo.focus "ModuleReleaseMeta Sync"
136 changes: 136 additions & 0 deletions tests/e2e/modulereleasemeta_sync_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package e2e_test

import (
"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 _ = Describe("ModuleReleaseMeta Sync", Ordered, func() {
kyma := NewKymaWithSyncLabel("kyma-sample", ControlPlaneNamespace, v1beta2.DefaultChannel)
module := NewTemplateOperator(v1beta2.DefaultChannel)
v1Version := "1.1.1-e2e-test"
InitEmptyKymaBeforeAll(kyma)

Context("Given SKR Cluster with ModuleTemplate", func() {
It("When Template Operator v1 ModuleTemplate is applied in the KCP Cluster with ModuleReleaseMeta", func() {
By("Then the Template Operator v1 ModuleTemplate exists in the KCP Cluster")
Eventually(ModuleTemplateExists).
WithContext(ctx).
WithArguments(kcpClient, module, v1beta2.DefaultChannel).
Should(Succeed())

By("And the Template Operator v1 ModuleTemplate exists in the SKR Cluster")
Eventually(ModuleTemplateExists).
WithContext(ctx).
WithArguments(skrClient, module, v1beta2.DefaultChannel).
Should(Succeed())

By("And the ModuleReleaseMeta exists on the KCP Cluster with the correct channel-version")
Eventually(ModuleReleaseMetaExists).
WithContext(ctx).
WithArguments(module.Name, ControlPlaneNamespace, kcpClient).
Should(Succeed())

Eventually(ModuleReleaseMetaContainsCorrectChannelVersion).
WithContext(ctx).
WithArguments(module.Name, ControlPlaneNamespace, v1beta2.DefaultChannel, v1Version, kcpClient).
Should(Succeed())

Skip("And the ModuleReleaseMeta exists on the SKR Cluster with the correct channel-version")
Eventually(ModuleReleaseMetaExists).
WithContext(ctx).
WithArguments(module.Name, RemoteNamespace, skrClient).
Should(Succeed())

Eventually(ModuleReleaseMetaContainsCorrectChannelVersion).
WithContext(ctx).
WithArguments(module.Name, RemoteNamespace, v1beta2.DefaultChannel, v1Version, skrClient).
Should(Succeed())
})

It("When Template Operator v1 ModuleTemplate is removed from the KCP Cluster", func() {
Eventually(DeleteModuleTemplate).
WithContext(ctx).
WithArguments(kcpClient, module, v1beta2.DefaultChannel).
Should(Succeed())

By("Then Template Operator v1 ModuleTemplate no longer exists on the KCP Cluster")
Eventually(ModuleTemplateExists).
WithContext(ctx).
WithArguments(kcpClient, module, v1beta2.DefaultChannel).
Should(Equal(ErrNotFound))

By("Then Template Operator v1 ModuleTemplate no longer exists on the SKR Cluster")
Eventually(ModuleTemplateExists).
WithContext(ctx).
WithArguments(skrClient, module, v1beta2.DefaultChannel).
Should(Equal(ErrNotFound))
})

It("When Template Operator v2 ModuleTemplate is applied in the KCP Cluster", func() {
v2Version := "2.4.2-e2e-test"
By("And ModuleReleaseMeta is updated with the correct channel-version")
Eventually(UpdateChannelVersionIfModuleReleaseMetaExists).
WithContext(ctx).
WithArguments(kcpClient, module.Name, ControlPlaneNamespace, v1beta2.DefaultChannel, v2Version).
Should(Succeed())

By("Then the Template Operator v2 ModuleTemplate exists in the KCP Cluster")
Eventually(ModuleTemplateExists).
WithContext(ctx).
WithArguments(kcpClient, module, v1beta2.DefaultChannel).
Should(Succeed())

Skip("And the Template Operator v2 ModuleTemplate exists in the SKR Cluster")
Eventually(ModuleTemplateExists).
WithContext(ctx).
WithArguments(skrClient, module, v1beta2.DefaultChannel).
Should(Succeed())

By("And the ModuleReleaseMeta exists on the KCP Cluster with the correct channel-version")
Eventually(ModuleReleaseMetaExists).
WithContext(ctx).
WithArguments(module.Name, ControlPlaneNamespace, kcpClient).
Should(Succeed())

Eventually(ModuleReleaseMetaContainsCorrectChannelVersion).
WithContext(ctx).
WithArguments(module.Name, ControlPlaneNamespace, v1beta2.DefaultChannel, v2Version, kcpClient).
Should(Succeed())

Skip("And the ModuleReleaseMeta exists on the SKR Cluster with the correct channel-version")
Eventually(ModuleReleaseMetaExists).
WithContext(ctx).
WithArguments(module.Name, RemoteNamespace, skrClient).
Should(Succeed())

Eventually(ModuleReleaseMetaContainsCorrectChannelVersion).
WithContext(ctx).
WithArguments(module.Name, RemoteNamespace, v1beta2.DefaultChannel, v2Version, skrClient).
Should(Succeed())
})

It("When the ModuleReleaseMeta is deleted for the Template Operator Module", func() {
Eventually(DeleteModuleReleaseMeta).
WithContext(ctx).
WithArguments(module.Name, ControlPlaneNamespace, kcpClient).
Should(Succeed())

By("Then the ModuleReleaseMeta no longer exists on the KCP Cluster")
Eventually(ModuleReleaseMetaExists).
WithContext(ctx).
WithArguments(module.Name, ControlPlaneNamespace, kcpClient).
Should(Equal(ErrNotFound))

Skip("And the ModuleReleaseMeta no longer exists on the SKR Cluster")
Eventually(ModuleReleaseMetaExists).
WithContext(ctx).
WithArguments(module.Name, RemoteNamespace, skrClient).
Should(Equal(ErrNotFound))
})
})
})

0 comments on commit de3a208

Please sign in to comment.