Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add ModuleReleaseMeta Sync test #1980

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
})
})
})
Loading