diff --git a/internal/descriptor/provider/provider.go b/internal/descriptor/provider/provider.go index 138d10d3db..4d36bd06fb 100644 --- a/internal/descriptor/provider/provider.go +++ b/internal/descriptor/provider/provider.go @@ -12,6 +12,7 @@ import ( var ( ErrTypeAssert = errors.New("failed to convert to v1beta2.Descriptor") ErrDecode = errors.New("failed to decode to descriptor target") + ErrEncode = errors.New("failed to encode the descriptor") ErrTemplateNil = errors.New("module template is nil") ErrDescriptorNil = errors.New("module template contains nil descriptor") ) @@ -70,6 +71,20 @@ func (c *CachedDescriptorProvider) GetDescriptor(template *v1beta2.ModuleTemplat return descriptor, nil } +func (c *CachedDescriptorProvider) SetDescriptor(template *v1beta2.ModuleTemplate, descriptor *v1beta2.Descriptor, +) error { + if template == nil { + return ErrTemplateNil + } + template.Spec.Descriptor.Object = descriptor + encoded, err := compdesc.Encode(descriptor.ComponentDescriptor, compdesc.DefaultJSONCodec) + template.Spec.Descriptor.Raw = encoded + if err != nil { + return errors.Join(ErrEncode, err) + } + return nil +} + func (c *CachedDescriptorProvider) Add(template *v1beta2.ModuleTemplate) error { if template == nil { return ErrTemplateNil diff --git a/pkg/testutils/moduletemplate.go b/pkg/testutils/moduletemplate.go index 91f82fea18..1425a44bf0 100644 --- a/pkg/testutils/moduletemplate.go +++ b/pkg/testutils/moduletemplate.go @@ -27,6 +27,16 @@ func GetModuleTemplate(ctx context.Context, return templateInfo.ModuleTemplate, nil } +func UpdateModuleTemplate(ctx context.Context, + clnt client.Client, + moduleTemplate *v1beta2.ModuleTemplate, +) error { + if err := clnt.Update(ctx, moduleTemplate); err != nil { + return fmt.Errorf("update module tempate: %w", err) + } + return nil +} + func ModuleTemplateExists(ctx context.Context, clnt client.Client, module v1beta2.Module, @@ -65,8 +75,8 @@ func UpdateModuleTemplateSpec(ctx context.Context, return ErrManifestResourceIsNil } moduleTemplate.Spec.Data.Object["spec"] = map[string]any{key: newValue} - if err := clnt.Update(ctx, moduleTemplate); err != nil { - return fmt.Errorf("update module tempate: %w", err) + if err := UpdateModuleTemplate(ctx, clnt, moduleTemplate); err != nil { + return err } return nil } @@ -102,3 +112,18 @@ func ReadModuleVersionFromModuleTemplate(ctx context.Context, clnt client.Client return ocmDesc.Version, nil } + +func ModifyModuleTemplateVersion(moduleTemplate *v1beta2.ModuleTemplate, newVersion string) error { + descriptorProvider := provider.NewCachedDescriptorProvider(nil) + ocmDesc, err := descriptorProvider.GetDescriptor(moduleTemplate) + if err != nil { + return fmt.Errorf("failed to get descriptor: %w", err) + } + ocmDesc.Version = newVersion + err = descriptorProvider.SetDescriptor(moduleTemplate, ocmDesc) + if err != nil { + return fmt.Errorf("failed to set descriptor: %w", err) + } + + return nil +} diff --git a/tests/integration/controller/kyma/kyma_test.go b/tests/integration/controller/kyma/kyma_test.go index 3e9b01f66b..7fc9bb6cf9 100644 --- a/tests/integration/controller/kyma/kyma_test.go +++ b/tests/integration/controller/kyma/kyma_test.go @@ -514,9 +514,33 @@ func updateKCPModuleTemplateSpecData(kymaName, valueUpdated string) func() error return err } for _, activeModule := range createdKyma.Spec.Modules { - return UpdateModuleTemplateSpec(ctx, kcpClient, + err := UpdateModuleTemplateSpec(ctx, kcpClient, activeModule, InitSpecKey, valueUpdated, createdKyma.Spec.Channel) + if err != nil { + return err + } + err = changeKCPModuleTemplateVersion(ctx, activeModule, createdKyma.Spec.Channel, "v1.7.2") // required to allow SSA for manifest + if err != nil { + return err + } } return nil } } + +func changeKCPModuleTemplateVersion(ctx context.Context, + module v1beta2.Module, channel, version string, +) error { + moduleTemplate, err := GetModuleTemplate(ctx, kcpClient, module, channel) + if err != nil { + return err + } + err = ModifyModuleTemplateVersion(moduleTemplate, version) + if err != nil { + return err + } + if err := UpdateModuleTemplate(ctx, kcpClient, moduleTemplate); err != nil { + return err + } + return nil +} diff --git a/tests/integration/controller/kyma/manifest_test.go b/tests/integration/controller/kyma/manifest_test.go index 82a7048e4f..c30471a323 100644 --- a/tests/integration/controller/kyma/manifest_test.go +++ b/tests/integration/controller/kyma/manifest_test.go @@ -112,6 +112,7 @@ var _ = Describe("Update Manifest CR", Ordered, func() { Fail("Can't find \"baseUrl\" property in ModuleTemplate spec") } repositoryContext["baseUrl"] = updateRepositoryURL + descriptor.Version = "v1.7.3" // required to allow for SSA of manifest newDescriptorRaw, err := compdesc.Encode(descriptor.ComponentDescriptor, compdesc.DefaultJSONCodec) Expect(err).ToNot(HaveOccurred())