Skip to content

Commit

Permalink
Add ModuleReleaseMeta Sync test - CRUD for ModuleTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
nesmabadr committed Oct 24, 2024
1 parent e83a031 commit 97c3e1e
Show file tree
Hide file tree
Showing 5 changed files with 127 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
32 changes: 32 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,32 @@ 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
}
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"
88 changes: 88 additions & 0 deletions tests/e2e/modulereleasemeta_sync_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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 KCP 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() {
By("Then the Template Operator v2 ModuleTemplate exists in the KCP Cluster")
Eventually(ModuleTemplateExists).
WithContext(ctx).
WithArguments(kcpClient, module, v1beta2.DefaultChannel).
Should(Succeed())

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

0 comments on commit 97c3e1e

Please sign in to comment.