Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nesmabadr committed Nov 6, 2024
1 parent eb79b11 commit 61211d5
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 32 deletions.
19 changes: 11 additions & 8 deletions pkg/testutils/moduletemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ func GetModuleTemplate(ctx context.Context,
clnt client.Client,
module v1beta2.Module,
defaultChannel string,
namespace string,
) (*v1beta2.ModuleTemplate, error) {
descriptorProvider := provider.NewCachedDescriptorProvider()
templateLookup := templatelookup.NewTemplateLookup(clnt, descriptorProvider)
availableModule := templatelookup.AvailableModule{
Module: module,
}
templateInfo := templateLookup.PopulateModuleTemplateInfo(ctx, availableModule, ControlPlaneNamespace,
templateInfo := templateLookup.PopulateModuleTemplateInfo(ctx, availableModule, namespace,
defaultChannel)

if templateInfo.Err != nil {
Expand All @@ -36,8 +37,9 @@ func ModuleTemplateExists(ctx context.Context,
clnt client.Client,
module v1beta2.Module,
defaultChannel string,
namespace string,
) error {
moduleTemplate, err := GetModuleTemplate(ctx, clnt, module, defaultChannel)
moduleTemplate, err := GetModuleTemplate(ctx, clnt, module, defaultChannel, namespace)
if moduleTemplate == nil || errors.Is(err, templatelookup.ErrNoTemplatesInListResult) {
return ErrNotFound
}
Expand All @@ -47,7 +49,7 @@ func ModuleTemplateExists(ctx context.Context,

func AllModuleTemplatesExists(ctx context.Context, clnt client.Client, kyma *v1beta2.Kyma) error {
for _, module := range kyma.Spec.Modules {
if err := ModuleTemplateExists(ctx, clnt, module, kyma.Spec.Channel); err != nil {
if err := ModuleTemplateExists(ctx, clnt, module, kyma.Spec.Channel, kyma.Namespace); err != nil {
return err
}
}
Expand All @@ -61,8 +63,9 @@ func UpdateModuleTemplateSpec(ctx context.Context,
key,
newValue,
kymaChannel string,
namespace string,
) error {
moduleTemplate, err := GetModuleTemplate(ctx, clnt, module, kymaChannel)
moduleTemplate, err := GetModuleTemplate(ctx, clnt, module, kymaChannel, namespace)
if err != nil {
return err
}
Expand All @@ -77,9 +80,9 @@ func UpdateModuleTemplateSpec(ctx context.Context,
}

func DeleteModuleTemplate(ctx context.Context,
clnt client.Client, module v1beta2.Module, kymaChannel string,
clnt client.Client, module v1beta2.Module, kymaChannel string, namespace string,
) error {
moduleTemplate, err := GetModuleTemplate(ctx, clnt, module, kymaChannel)
moduleTemplate, err := GetModuleTemplate(ctx, clnt, module, kymaChannel, namespace)
if util.IsNotFound(err) {
return nil
}
Expand All @@ -92,9 +95,9 @@ func DeleteModuleTemplate(ctx context.Context,
}

func ReadModuleVersionFromModuleTemplate(ctx context.Context, clnt client.Client, module v1beta2.Module,
channel string,
channel string, namespace string,
) (string, error) {
moduleTemplate, err := GetModuleTemplate(ctx, clnt, module, channel)
moduleTemplate, err := GetModuleTemplate(ctx, clnt, module, channel, namespace)
if err != nil {
return "", fmt.Errorf("failed to fetch ModuleTemplate: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/module_deletion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ var _ = Describe("Non Blocking Kyma Module Deletion", Ordered, func() {
It("Then ModuleTemplate is no longer in SKR Cluster", func() {
Eventually(ModuleTemplateExists).
WithContext(ctx).
WithArguments(skrClient, module, kyma.Spec.Channel).
WithArguments(skrClient, module, kyma.Spec.Channel, RemoteNamespace).
Should(Equal(ErrNotFound))
})
})
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/module_upgrade_new_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ var _ = Describe("Module Upgrade By New Version", Ordered, func() {

By("And Kyma Module Version in Kyma Status is updated")
newModuleTemplateVersion, err := ReadModuleVersionFromModuleTemplate(ctx, kcpClient, module,
kyma.Spec.Channel)
kyma.Spec.Channel, ControlPlaneNamespace)
Expect(err).ToNot(HaveOccurred())

Eventually(ModuleVersionInKymaStatusIsCorrect).
Expand Down
14 changes: 7 additions & 7 deletions tests/e2e/modulereleasemeta_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ var _ = Describe("ModuleReleaseMeta Sync", Ordered, func() {
By("Then the Template Operator v1 ModuleTemplate exists in the KCP Cluster")
Eventually(ModuleTemplateExists).
WithContext(ctx).
WithArguments(kcpClient, module, v1beta2.DefaultChannel).
WithArguments(kcpClient, module, v1beta2.DefaultChannel, ControlPlaneNamespace).
Should(Succeed())

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

By("And the ModuleReleaseMeta exists on the KCP Cluster with the correct channel-version")
Expand Down Expand Up @@ -55,19 +55,19 @@ var _ = Describe("ModuleReleaseMeta Sync", Ordered, func() {
It("When Template Operator v1 ModuleTemplate is removed from the KCP Cluster", func() {
Eventually(DeleteModuleTemplate).
WithContext(ctx).
WithArguments(kcpClient, module, v1beta2.DefaultChannel).
WithArguments(kcpClient, module, v1beta2.DefaultChannel, ControlPlaneNamespace).
Should(Succeed())

By("Then Template Operator v1 ModuleTemplate no longer exists on the KCP Cluster")
Eventually(ModuleTemplateExists).
WithContext(ctx).
WithArguments(kcpClient, module, v1beta2.DefaultChannel).
WithArguments(kcpClient, module, v1beta2.DefaultChannel, ControlPlaneNamespace).
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).
WithArguments(skrClient, module, v1beta2.DefaultChannel, RemoteNamespace).
Should(Equal(ErrNotFound))
})

Expand All @@ -82,13 +82,13 @@ var _ = Describe("ModuleReleaseMeta Sync", Ordered, func() {
By("Then the Template Operator v2 ModuleTemplate exists in the KCP Cluster")
Eventually(ModuleTemplateExists).
WithContext(ctx).
WithArguments(kcpClient, module, v1beta2.DefaultChannel).
WithArguments(kcpClient, module, v1beta2.DefaultChannel, ControlPlaneNamespace).
Should(Succeed())

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

By("And the ModuleReleaseMeta exists on the KCP Cluster with the correct channel-version")
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/controller/kcp/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ func expectModuleTemplateSpecGetReset(
clnt client.Client,
module v1beta2.Module,
kymaChannel string,
namespace string,
) error {
moduleTemplate, err := GetModuleTemplate(ctx, clnt, module, kymaChannel)
moduleTemplate, err := GetModuleTemplate(ctx, clnt, module, kymaChannel, namespace)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/controller/kcp/remote_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ var _ = Describe("Kyma sync into Remote Cluster", Ordered, func() {
Should(Succeed())
By("ModuleTemplate exists in KCP cluster")
Eventually(ModuleTemplateExists, Timeout, Interval).
WithArguments(ctx, kcpClient, moduleInKCP, kyma.Spec.Channel).
WithArguments(ctx, kcpClient, moduleInKCP, kyma.Spec.Channel, ControlPlaneNamespace).
Should(Succeed())
By("ModuleTemplate exists in SKR cluster")
Eventually(ModuleTemplateExists, Timeout, Interval).WithArguments(ctx, skrClient, moduleInKCP,
kyma.Spec.Channel).Should(Succeed())
kyma.Spec.Channel, RemoteNamespace).Should(Succeed())

By("No module synced to remote Kyma")
Eventually(NotContainsModuleInSpec, Timeout, Interval).
Expand All @@ -106,7 +106,7 @@ var _ = Describe("Kyma sync into Remote Cluster", Ordered, func() {

By("Remote Module Catalog created")
Eventually(ModuleTemplateExists, Timeout, Interval).
WithArguments(ctx, skrClient, moduleInSKR, kyma.Spec.Channel).
WithArguments(ctx, skrClient, moduleInSKR, kyma.Spec.Channel, RemoteNamespace).
Should(Succeed())
Eventually(containsModuleTemplateCondition, Timeout, Interval).
WithArguments(skrClient, skrKyma.GetName(), flags.DefaultRemoteSyncNamespace).
Expand Down Expand Up @@ -170,13 +170,13 @@ var _ = Describe("Kyma sync into Remote Cluster", Ordered, func() {
By("Update SKR Module Template spec.data.spec field")
Eventually(UpdateModuleTemplateSpec, Timeout, Interval).
WithContext(ctx).
WithArguments(skrClient, moduleInSKR, InitSpecKey, "valueUpdated", kyma.Spec.Channel).
WithArguments(skrClient, moduleInSKR, InitSpecKey, "valueUpdated", kyma.Spec.Channel, RemoteNamespace).
Should(Succeed())

By("Expect SKR Module Template spec.data.spec field get reset")
Eventually(expectModuleTemplateSpecGetReset, 2*Timeout, Interval).
WithArguments(skrClient,
moduleInSKR, kyma.Spec.Channel).
moduleInSKR, kyma.Spec.Channel, RemoteNamespace).
Should(Succeed())
})

Expand Down
5 changes: 3 additions & 2 deletions tests/integration/controller/kyma/kyma_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ var _ = Describe("Kyma enable one Module", Ordered, func() {
if len(modulesStatus) != 1 {
return ErrWrongModulesStatus
}
template, err := GetModuleTemplate(ctx, kcpClient, module, v1beta2.DefaultChannel)
template, err := GetModuleTemplate(ctx, kcpClient, module, v1beta2.DefaultChannel,
ControlPlaneNamespace)
if err != nil {
return err
}
Expand Down Expand Up @@ -515,7 +516,7 @@ func updateKCPModuleTemplateSpecData(kymaName, valueUpdated string) func() error
}
for _, activeModule := range createdKyma.Spec.Modules {
return UpdateModuleTemplateSpec(ctx, kcpClient,
activeModule, InitSpecKey, valueUpdated, createdKyma.Spec.Channel)
activeModule, InitSpecKey, valueUpdated, createdKyma.Spec.Channel, ControlPlaneNamespace)
}
return nil
}
Expand Down
17 changes: 10 additions & 7 deletions tests/integration/controller/kyma/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ var _ = Describe("Manifest.Spec is rendered correctly", Ordered, func() {
RegisterDefaultLifecycleForKyma(kyma)

It("validate Manifest", func() {
moduleTemplate, err := GetModuleTemplate(ctx, kcpClient, module, kyma.Spec.Channel)
moduleTemplate, err := GetModuleTemplate(ctx, kcpClient, module, kyma.Spec.Channel, ControlPlaneNamespace)
Expect(err).NotTo(HaveOccurred())

expectManifest := expectManifestFor(kyma)
Expand Down Expand Up @@ -209,7 +209,7 @@ var _ = Describe("Manifest.Spec is reset after manual update", Ordered, func() {
})

It("validate Manifest", func() {
moduleTemplate, err := GetModuleTemplate(ctx, kcpClient, module, kyma.Spec.Channel)
moduleTemplate, err := GetModuleTemplate(ctx, kcpClient, module, kyma.Spec.Channel, ControlPlaneNamespace)
Expect(err).NotTo(HaveOccurred())

expectManifest := expectManifestFor(kyma)
Expand Down Expand Up @@ -343,7 +343,8 @@ var _ = Describe("Modules can only be referenced via module name", Ordered, func

Context("When operator is referenced just by the label name", func() {
It("returns the expected operator", func() {
moduleTemplate, err := GetModuleTemplate(ctx, kcpClient, moduleReferencedWithLabel, kyma.Spec.Channel)
moduleTemplate, err := GetModuleTemplate(ctx, kcpClient, moduleReferencedWithLabel, kyma.Spec.Channel,
ControlPlaneNamespace)
Expect(err).ToNot(HaveOccurred())

foundModuleName := moduleTemplate.Labels[shared.ModuleName]
Expand All @@ -353,14 +354,16 @@ var _ = Describe("Modules can only be referenced via module name", Ordered, func

Context("When operator is referenced by Namespace/Name", func() {
It("cannot find the operator", func() {
_, err := GetModuleTemplate(ctx, kcpClient, moduleReferencedWithNamespacedName, kyma.Spec.Channel)
_, err := GetModuleTemplate(ctx, kcpClient, moduleReferencedWithNamespacedName, kyma.Spec.Channel,
ControlPlaneNamespace)
Expect(err.Error()).Should(ContainSubstring(templatelookup.ErrNoTemplatesInListResult.Error()))
})
})

Context("When operator is referenced by FQDN", func() {
It("cannot find the operator", func() {
_, err := GetModuleTemplate(ctx, kcpClient, moduleReferencedWithFQDN, kyma.Spec.Channel)
_, err := GetModuleTemplate(ctx, kcpClient, moduleReferencedWithFQDN, kyma.Spec.Channel,
ControlPlaneNamespace)
Expect(err.Error()).Should(ContainSubstring(templatelookup.ErrNoTemplatesInListResult.Error()))
})
})
Expand Down Expand Up @@ -510,7 +513,7 @@ func validateManifestSpecResource(manifestResource, moduleTemplateData *unstruct
// getKCPModuleTemplate is a generic ModuleTemplate validation function.
func validateKCPModuleTemplate(module v1beta2.Module, kymaChannel string) func(moduleTemplateFn) error {
return func(validateFunc moduleTemplateFn) error {
moduleTemplate, err := GetModuleTemplate(ctx, kcpClient, module, kymaChannel)
moduleTemplate, err := GetModuleTemplate(ctx, kcpClient, module, kymaChannel, ControlPlaneNamespace)
if err != nil {
return err
}
Expand All @@ -527,7 +530,7 @@ func validateKCPModuleTemplate(module v1beta2.Module, kymaChannel string) func(m
// updateKCPModuleTemplate is a generic ModuleTemplate update function.
func updateKCPModuleTemplate(module v1beta2.Module, kymaChannel string) func(moduleTemplateFn) error {
return func(updateFunc moduleTemplateFn) error {
moduleTemplate, err := GetModuleTemplate(ctx, kcpClient, module, kymaChannel)
moduleTemplate, err := GetModuleTemplate(ctx, kcpClient, module, kymaChannel, ControlPlaneNamespace)
if err != nil {
return err
}
Expand Down

0 comments on commit 61211d5

Please sign in to comment.