diff --git a/pkg/testutils/moduletemplate.go b/pkg/testutils/moduletemplate.go index fae821e135..e8f6183d6d 100644 --- a/pkg/testutils/moduletemplate.go +++ b/pkg/testutils/moduletemplate.go @@ -2,6 +2,7 @@ package testutils import ( "context" + "errors" "fmt" "sigs.k8s.io/controller-runtime/pkg/client" @@ -9,6 +10,7 @@ import ( "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, @@ -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 } } @@ -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 +} diff --git a/tests/e2e/module_deletion_test.go b/tests/e2e/module_deletion_test.go index bd7c0a26f1..fe7fb7e36a 100644 --- a/tests/e2e/module_deletion_test.go +++ b/tests/e2e/module_deletion_test.go @@ -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)) + }) }) }) diff --git a/tests/integration/controller/controlplane/kyma_remote_sync_test.go b/tests/integration/controller/controlplane/kyma_remote_sync_test.go index 059bed819c..b3cb22c199 100644 --- a/tests/integration/controller/controlplane/kyma_remote_sync_test.go +++ b/tests/integration/controller/controlplane/kyma_remote_sync_test.go @@ -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") @@ -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).