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 E2E test for ModuleTemplate deletion #1350

Merged
merged 4 commits into from
Mar 1, 2024
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
27 changes: 24 additions & 3 deletions pkg/testutils/moduletemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package testutils

import (
"context"
"errors"
"fmt"

"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/kyma-project/lifecycle-manager/api/v1beta2"
"github.com/kyma-project/lifecycle-manager/internal/descriptor/provider"
"github.com/kyma-project/lifecycle-manager/pkg/templatelookup"
"github.com/kyma-project/lifecycle-manager/pkg/util"
)

func GetModuleTemplate(ctx context.Context,
Expand All @@ -25,18 +27,22 @@ func GetModuleTemplate(ctx context.Context,
return templateInfo.ModuleTemplate, nil
}

func RegularModuleTemplateExists(ctx context.Context,
func ModuleTemplateExists(ctx context.Context,
clnt client.Client,
module v1beta2.Module,
defaultChannel string,
) error {
moduleTemplate, err := GetModuleTemplate(ctx, clnt, module, defaultChannel)
return CRExists(moduleTemplate, err)
if moduleTemplate == nil || errors.Is(err, templatelookup.ErrNoTemplatesInListResult) {
return ErrNotFound
}

return nil
}

func AllModuleTemplatesExists(ctx context.Context, clnt client.Client, kyma *v1beta2.Kyma) error {
for _, module := range kyma.Spec.Modules {
if err := RegularModuleTemplateExists(ctx, clnt, module, kyma.Spec.Channel); err != nil {
if err := ModuleTemplateExists(ctx, clnt, module, kyma.Spec.Channel); err != nil {
return err
}
}
Expand Down Expand Up @@ -64,3 +70,18 @@ func UpdateModuleTemplateSpec(ctx context.Context,
}
return nil
}

func DeleteModuleTemplate(ctx context.Context,
clnt client.Client, module v1beta2.Module, kymaChannel string,
) error {
moduleTemplate, err := GetModuleTemplate(ctx, clnt, module, kymaChannel)
if util.IsNotFound(err) {
return nil
}

err = client.IgnoreNotFound(clnt.Delete(ctx, moduleTemplate))
if err != nil {
return fmt.Errorf("moduletemplate not deleted: %w", err)
}
return nil
}
14 changes: 14 additions & 0 deletions tests/e2e/module_deletion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,19 @@ var _ = Describe("Non Blocking Kyma Module Deletion", Ordered, func() {
WithArguments(defaultRemoteKymaName, remoteNamespace, runtimeClient, shared.StateReady).
Should(Succeed())
})

It("When ModuleTemplate is removed from KCP Cluster", func() {
Eventually(DeleteModuleTemplate).
WithContext(ctx).
WithArguments(controlPlaneClient, module, kyma.Spec.Channel).
Should(Succeed())
})

It("Then ModuleTemplate is no longer in SKR Cluster", func() {
Eventually(ModuleTemplateExists).
WithContext(ctx).
WithArguments(runtimeClient, module, kyma.Spec.Channel).
Should(Equal(ErrNotFound))
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ var _ = Describe("Kyma sync into Remote Cluster", Ordered, func() {
WithArguments(SKRTemplate).
Should(Succeed())
By("ModuleTemplate exists in KCP cluster")
Eventually(RegularModuleTemplateExists, Timeout, Interval).
Eventually(ModuleTemplateExists, Timeout, Interval).
WithArguments(ctx, controlPlaneClient, moduleInKCP, kyma.Spec.Channel).
Should(Succeed())
By("ModuleTemplate exists in SKR cluster")
Eventually(RegularModuleTemplateExists, Timeout, Interval).WithArguments(ctx, runtimeClient, moduleInKCP,
Eventually(ModuleTemplateExists, Timeout, Interval).WithArguments(ctx, runtimeClient, moduleInKCP,
kyma.Spec.Channel).Should(Succeed())

By("No module synced to remote Kyma")
Expand All @@ -111,7 +111,7 @@ var _ = Describe("Kyma sync into Remote Cluster", Ordered, func() {
Should(Succeed())

By("Remote Module Catalog created")
Eventually(RegularModuleTemplateExists, Timeout, Interval).
Eventually(ModuleTemplateExists, Timeout, Interval).
WithArguments(ctx, runtimeClient, moduleInSKR, kyma.Spec.Channel).
Should(Succeed())
Eventually(containsModuleTemplateCondition, Timeout, Interval).
Expand Down
Loading