diff --git a/cmd/modulectl/create/long.txt b/cmd/modulectl/create/long.txt index 5e09d764..84fba179 100644 --- a/cmd/modulectl/create/long.txt +++ b/cmd/modulectl/create/long.txt @@ -18,7 +18,6 @@ The module config file is a YAML file used to configure the following attributes - defaultCR: a string, optional, reference to a YAML file containing the default CR for the module, must be a relative file name or URL - mandatory: a boolean, optional, default=false, indicates whether the module is mandatory to be installed on all clusters -- resourceName: a string, optional, default={NAME}-{CHANNEL}, the name for the ModuleTemplate CR that will be created - internal: a boolean, optional, default=false, determines whether the ModuleTemplate CR should have the internal flag or not - beta: a boolean, optional, default=false, determines whether the ModuleTemplate CR should have the beta flag or not - security: a string, optional, name of the security scanners config file diff --git a/docs/gen-docs/modulectl_create.md b/docs/gen-docs/modulectl_create.md index 5bf002fa..f88b5a62 100644 --- a/docs/gen-docs/modulectl_create.md +++ b/docs/gen-docs/modulectl_create.md @@ -26,7 +26,6 @@ The module config file is a YAML file used to configure the following attributes - defaultCR: a string, optional, reference to a YAML file containing the default CR for the module, must be a relative file name or URL - mandatory: a boolean, optional, default=false, indicates whether the module is mandatory to be installed on all clusters -- resourceName: a string, optional, default={NAME}-{CHANNEL}, the name for the ModuleTemplate CR that will be created - internal: a boolean, optional, default=false, determines whether the ModuleTemplate CR should have the internal flag or not - beta: a boolean, optional, default=false, determines whether the ModuleTemplate CR should have the beta flag or not - security: a string, optional, name of the security scanners config file diff --git a/internal/service/contentprovider/moduleconfig.go b/internal/service/contentprovider/moduleconfig.go index b7a752eb..92ca0737 100644 --- a/internal/service/contentprovider/moduleconfig.go +++ b/internal/service/contentprovider/moduleconfig.go @@ -80,21 +80,20 @@ type Manager struct { } type ModuleConfig struct { - Name string `yaml:"name" comment:"required, the name of the Module"` - Version string `yaml:"version" comment:"required, the version of the Module"` - Channel string `yaml:"channel" comment:"required, channel that should be used in the ModuleTemplate"` - Manifest string `yaml:"manifest" comment:"required, relative path or remote URL to the manifests"` - Mandatory bool `yaml:"mandatory" comment:"optional, default=false, indicates whether the module is mandatory to be installed on all clusters"` - DefaultCR string `yaml:"defaultCR" comment:"optional, relative path or remote URL to a YAML file containing the default CR for the module"` - ResourceName string `yaml:"resourceName" comment:"optional, default={name}-{channel}, when channel is 'none', the default is {name}-{version}, the name for the ModuleTemplate that will be created"` - Namespace string `yaml:"namespace" comment:"optional, default=kcp-system, the namespace where the ModuleTemplate will be deployed"` - Security string `yaml:"security" comment:"optional, name of the security scanners config file"` - Internal bool `yaml:"internal" comment:"optional, default=false, determines whether the ModuleTemplate should have the internal flag or not"` - Beta bool `yaml:"beta" comment:"optional, default=false, determines whether the ModuleTemplate should have the beta flag or not"` - Labels map[string]string `yaml:"labels" comment:"optional, additional labels for the ModuleTemplate"` - Annotations map[string]string `yaml:"annotations" comment:"optional, additional annotations for the ModuleTemplate"` - Manager *Manager `yaml:"manager" comment:"optional, the module resource that can be used to indicate the installation readiness of the module. This is typically the manager deployment of the module"` - Resources ResourcesMap `yaml:"resources,omitempty" comment:"optional, additional resources of the ModuleTemplate that may be fetched"` + Name string `yaml:"name" comment:"required, the name of the Module"` + Version string `yaml:"version" comment:"required, the version of the Module"` + Channel string `yaml:"channel" comment:"required, channel that should be used in the ModuleTemplate"` + Manifest string `yaml:"manifest" comment:"required, relative path or remote URL to the manifests"` + Mandatory bool `yaml:"mandatory" comment:"optional, default=false, indicates whether the module is mandatory to be installed on all clusters"` + DefaultCR string `yaml:"defaultCR" comment:"optional, relative path or remote URL to a YAML file containing the default CR for the module"` + Namespace string `yaml:"namespace" comment:"optional, default=kcp-system, the namespace where the ModuleTemplate will be deployed"` + Security string `yaml:"security" comment:"optional, name of the security scanners config file"` + Internal bool `yaml:"internal" comment:"optional, default=false, determines whether the ModuleTemplate should have the internal flag or not"` + Beta bool `yaml:"beta" comment:"optional, default=false, determines whether the ModuleTemplate should have the beta flag or not"` + Labels map[string]string `yaml:"labels" comment:"optional, additional labels for the ModuleTemplate"` + Annotations map[string]string `yaml:"annotations" comment:"optional, additional annotations for the ModuleTemplate"` + Manager *Manager `yaml:"manager" comment:"optional, the module resource that can be used to indicate the installation readiness of the module. This is typically the manager deployment of the module"` + Resources ResourcesMap `yaml:"resources,omitempty" comment:"optional, additional resources of the ModuleTemplate that may be fetched"` } type resource struct { diff --git a/internal/service/moduleconfig/generator/moduleconfig_generator_test.go b/internal/service/moduleconfig/generator/moduleconfig_generator_test.go index 1ee8ed2c..79f1cafa 100644 --- a/internal/service/moduleconfig/generator/moduleconfig_generator_test.go +++ b/internal/service/moduleconfig/generator/moduleconfig_generator_test.go @@ -118,19 +118,18 @@ func (*fileExistsStub) FileExists(_ string) (bool, error) { func (*fileExistsStub) ReadFile(_ string) ([]byte, error) { moduleConfig := contentprovider.ModuleConfig{ - Name: "module-name", - Version: "0.0.1", - Channel: "regular", - Manifest: "path/to/manifests", - Mandatory: false, - DefaultCR: "path/to/defaultCR", - ResourceName: "module-name-0.0.1", - Namespace: "kcp-system", - Security: "path/to/securityConfig", - Internal: false, - Beta: false, - Labels: map[string]string{"label1": "value1"}, - Annotations: map[string]string{"annotation1": "value1"}, + Name: "module-name", + Version: "0.0.1", + Channel: "regular", + Manifest: "path/to/manifests", + Mandatory: false, + DefaultCR: "path/to/defaultCR", + Namespace: "kcp-system", + Security: "path/to/securityConfig", + Internal: false, + Beta: false, + Labels: map[string]string{"label1": "value1"}, + Annotations: map[string]string{"annotation1": "value1"}, Manager: &contentprovider.Manager{ Name: "manager-name", Namespace: "manager-namespace", diff --git a/internal/service/moduleconfig/reader/moduleconfig_reader_test.go b/internal/service/moduleconfig/reader/moduleconfig_reader_test.go index d0bf7986..c72350e1 100644 --- a/internal/service/moduleconfig/reader/moduleconfig_reader_test.go +++ b/internal/service/moduleconfig/reader/moduleconfig_reader_test.go @@ -34,7 +34,6 @@ func Test_ParseModuleConfig_Returns_CorrectModuleConfig(t *testing.T) { require.Equal(t, "regular", result.Channel) require.Equal(t, "https://example.com/path/to/manifests", result.Manifest) require.Equal(t, "https://example.com/path/to/defaultCR", result.DefaultCR) - require.Equal(t, "module-name-0.0.1", result.ResourceName) require.False(t, result.Mandatory) require.Equal(t, "kcp-system", result.Namespace) require.Equal(t, "path/to/securityConfig", result.Security) @@ -121,7 +120,8 @@ func Test_ValidateModuleConfig(t *testing.T) { Namespace: "kcp-system", Manifest: "", }, - expectedError: fmt.Errorf("failed to validate manifest: %w: must not be empty", commonerrors.ErrInvalidOption), + expectedError: fmt.Errorf("failed to validate manifest: %w: must not be empty", + commonerrors.ErrInvalidOption), }, { name: "invalid module resources - not a URL", @@ -135,7 +135,8 @@ func Test_ValidateModuleConfig(t *testing.T) { "key": "%% not a URL", }, }, - expectedError: fmt.Errorf("failed to validate resources: failed to validate link: %w: '%%%% not a URL' is not a valid URL", commonerrors.ErrInvalidOption), + expectedError: fmt.Errorf("failed to validate resources: failed to validate link: %w: '%%%% not a URL' is not a valid URL", + commonerrors.ErrInvalidOption), }, { name: "invalid module resources - empty name", @@ -149,7 +150,8 @@ func Test_ValidateModuleConfig(t *testing.T) { "": "https://github.com/kyma-project/template-operator/releases/download/1.0.1/template-operator.yaml", }, }, - expectedError: fmt.Errorf("failed to validate resources: %w: name must not be empty", commonerrors.ErrInvalidOption), + expectedError: fmt.Errorf("failed to validate resources: %w: name must not be empty", + commonerrors.ErrInvalidOption), }, { name: "invalid module resources - empty link", @@ -163,7 +165,8 @@ func Test_ValidateModuleConfig(t *testing.T) { "name": "", }, }, - expectedError: fmt.Errorf("failed to validate resources: %w: link must not be empty", commonerrors.ErrInvalidOption), + expectedError: fmt.Errorf("failed to validate resources: %w: link must not be empty", + commonerrors.ErrInvalidOption), }, { name: "manifest file path", @@ -174,7 +177,8 @@ func Test_ValidateModuleConfig(t *testing.T) { Namespace: "kcp-system", Manifest: "./test", }, - expectedError: fmt.Errorf("failed to validate manifest: %w: './test' is not using https scheme", commonerrors.ErrInvalidOption), + expectedError: fmt.Errorf("failed to validate manifest: %w: './test' is not using https scheme", + commonerrors.ErrInvalidOption), }, { name: "default CR file path", @@ -186,7 +190,8 @@ func Test_ValidateModuleConfig(t *testing.T) { Manifest: "https://example.com/test", DefaultCR: "/test", }, - expectedError: fmt.Errorf("failed to validate default CR: %w: '/test' is not using https scheme", commonerrors.ErrInvalidOption), + expectedError: fmt.Errorf("failed to validate default CR: %w: '/test' is not using https scheme", + commonerrors.ErrInvalidOption), }, } for _, test := range tests { @@ -308,19 +313,18 @@ func (*fileExistsStub) FileExists(_ string) (bool, error) { } var expectedReturnedModuleConfig = contentprovider.ModuleConfig{ - Name: "github.com/module-name", - Version: "0.0.1", - Channel: "regular", - Manifest: "https://example.com/path/to/manifests", - Mandatory: false, - DefaultCR: "https://example.com/path/to/defaultCR", - ResourceName: "module-name-0.0.1", - Namespace: "kcp-system", - Security: "path/to/securityConfig", - Internal: false, - Beta: false, - Labels: map[string]string{"label1": "value1"}, - Annotations: map[string]string{"annotation1": "value1"}, + Name: "github.com/module-name", + Version: "0.0.1", + Channel: "regular", + Manifest: "https://example.com/path/to/manifests", + Mandatory: false, + DefaultCR: "https://example.com/path/to/defaultCR", + Namespace: "kcp-system", + Security: "path/to/securityConfig", + Internal: false, + Beta: false, + Labels: map[string]string{"label1": "value1"}, + Annotations: map[string]string{"annotation1": "value1"}, Resources: contentprovider.ResourcesMap{ "rawManifest": "https://github.com/kyma-project/template-operator/releases/download/1.0.1/template-operator.yaml", }, diff --git a/internal/service/templategenerator/templategenerator.go b/internal/service/templategenerator/templategenerator.go index 0d5a0bea..91f6a40e 100644 --- a/internal/service/templategenerator/templategenerator.go +++ b/internal/service/templategenerator/templategenerator.go @@ -122,9 +122,7 @@ func (s *Service) GenerateModuleTemplate( } shortName := trimShortNameFromRef(ref) labels[shared.ModuleName] = shortName - if moduleConfig.ResourceName == "" { - moduleConfig.ResourceName = shortName + "-" + moduleConfig.Channel - } + moduleTemplateName := shortName + "-" + moduleConfig.Version moduleTemplate, err := template.New("moduleTemplate").Funcs(template.FuncMap{ "yaml": yaml.Marshal, @@ -140,7 +138,7 @@ func (s *Service) GenerateModuleTemplate( } mtData := moduleTemplateData{ - ResourceName: moduleConfig.ResourceName, + ResourceName: moduleTemplateName, Namespace: moduleConfig.Namespace, Descriptor: cva, Channel: moduleConfig.Channel, diff --git a/internal/service/templategenerator/templategenerator_test.go b/internal/service/templategenerator/templategenerator_test.go index a57eb9cb..7325183b 100644 --- a/internal/service/templategenerator/templategenerator_test.go +++ b/internal/service/templategenerator/templategenerator_test.go @@ -43,14 +43,14 @@ func TestGenerateModuleTemplate_Success(t *testing.T) { svc, _ := templategenerator.NewService(mockFS) moduleConfig := &contentprovider.ModuleConfig{ - ResourceName: "test-resource", - Namespace: "default", - Channel: "stable", - Labels: map[string]string{"key": "value"}, - Annotations: map[string]string{"annotation": "value"}, - Mandatory: true, - Manifest: "https://github.com/kyma-project/template-operator/releases/download/1.0.1/template-operator.yaml", - Resources: contentprovider.ResourcesMap{"someResource": "https://some.other/location/template-operator.yaml"}, + Namespace: "default", + Version: "1.0.0", + Channel: "stable", + Labels: map[string]string{"key": "value"}, + Annotations: map[string]string{"annotation": "value"}, + Mandatory: true, + Manifest: "https://github.com/kyma-project/template-operator/releases/download/1.0.1/template-operator.yaml", + Resources: contentprovider.ResourcesMap{"someResource": "https://some.other/location/template-operator.yaml"}, } descriptor := testutils.CreateComponentDescriptor("example.com/component", "1.0.0") data := []byte("test-data") @@ -59,7 +59,7 @@ func TestGenerateModuleTemplate_Success(t *testing.T) { require.NoError(t, err) require.Equal(t, "output.yaml", mockFS.path) - require.Contains(t, mockFS.writtenTemplate, "test-resource") + require.Contains(t, mockFS.writtenTemplate, "test-resource-1.0.0") require.Contains(t, mockFS.writtenTemplate, "default") require.Contains(t, mockFS.writtenTemplate, "stable") require.Contains(t, mockFS.writtenTemplate, "test-data") @@ -67,7 +67,8 @@ func TestGenerateModuleTemplate_Success(t *testing.T) { require.Contains(t, mockFS.writtenTemplate, "someResource") require.Contains(t, mockFS.writtenTemplate, "https://some.other/location/template-operator.yaml") require.Contains(t, mockFS.writtenTemplate, "rawManifest") - require.Contains(t, mockFS.writtenTemplate, "https://github.com/kyma-project/template-operator/releases/download/1.0.1/template-operator.yaml") + require.Contains(t, mockFS.writtenTemplate, + "https://github.com/kyma-project/template-operator/releases/download/1.0.1/template-operator.yaml") } func TestGenerateModuleTemplate_Success_With_Overwritten_RawManifest(t *testing.T) { @@ -87,7 +88,8 @@ func TestGenerateModuleTemplate_Success_With_Overwritten_RawManifest(t *testing. require.Equal(t, "output.yaml", mockFS.path) require.Contains(t, mockFS.writtenTemplate, "rawManifest") require.Contains(t, mockFS.writtenTemplate, "https://some.other/location/template-operator.yaml") - require.NotContains(t, mockFS.writtenTemplate, "https://github.com/kyma-project/template-operator/releases/download/1.0.1/template-operator.yaml") + require.NotContains(t, mockFS.writtenTemplate, + "https://github.com/kyma-project/template-operator/releases/download/1.0.1/template-operator.yaml") } func TestGenerateModuleTemplateWithManager_Success(t *testing.T) { @@ -95,12 +97,12 @@ func TestGenerateModuleTemplateWithManager_Success(t *testing.T) { svc, _ := templategenerator.NewService(mockFS) moduleConfig := &contentprovider.ModuleConfig{ - ResourceName: "test-resource", - Namespace: "default", - Channel: "stable", - Labels: map[string]string{"key": "value"}, - Annotations: map[string]string{"annotation": "value"}, - Mandatory: true, + Namespace: "default", + Channel: "stable", + Version: "1.0.0", + Labels: map[string]string{"key": "value"}, + Annotations: map[string]string{"annotation": "value"}, + Mandatory: true, Manager: &contentprovider.Manager{ Name: "manager-name", Namespace: "manager-ns", @@ -118,7 +120,7 @@ func TestGenerateModuleTemplateWithManager_Success(t *testing.T) { require.NoError(t, err) require.Equal(t, "output.yaml", mockFS.path) - require.Contains(t, mockFS.writtenTemplate, "test-resource") + require.Contains(t, mockFS.writtenTemplate, "test-resource-1.0.0") require.Contains(t, mockFS.writtenTemplate, "default") require.Contains(t, mockFS.writtenTemplate, "stable") require.Contains(t, mockFS.writtenTemplate, "test-data") @@ -136,12 +138,12 @@ func TestGenerateModuleTemplateWithManagerWithoutNamespace_Success(t *testing.T) svc, _ := templategenerator.NewService(mockFS) moduleConfig := &contentprovider.ModuleConfig{ - ResourceName: "test-resource", - Namespace: "default", - Channel: "stable", - Labels: map[string]string{"key": "value"}, - Annotations: map[string]string{"annotation": "value"}, - Mandatory: true, + Namespace: "default", + Channel: "stable", + Version: "1.0.0", + Labels: map[string]string{"key": "value"}, + Annotations: map[string]string{"annotation": "value"}, + Mandatory: true, Manager: &contentprovider.Manager{ Name: "manager-name", GroupVersionKind: metav1.GroupVersionKind{ @@ -158,7 +160,7 @@ func TestGenerateModuleTemplateWithManagerWithoutNamespace_Success(t *testing.T) require.NoError(t, err) require.Equal(t, "output.yaml", mockFS.path) - require.Contains(t, mockFS.writtenTemplate, "test-resource") + require.Contains(t, mockFS.writtenTemplate, "test-resource-1.0.0") require.Contains(t, mockFS.writtenTemplate, "default") require.Contains(t, mockFS.writtenTemplate, "stable") require.Contains(t, mockFS.writtenTemplate, "test-data") diff --git a/scaffold-create-config.yaml b/scaffold-create-config.yaml index cba04664..e74bf28e 100644 --- a/scaffold-create-config.yaml +++ b/scaffold-create-config.yaml @@ -4,7 +4,6 @@ channel: "regular" # required, channel that should be used in the ModuleTemplate manifest: "manifest.yaml" # required, relative path or remote URL to the manifests # mandatory: false # optional, default=false, indicates whether the module is mandatory to be installed on all clusters # defaultCR: "" # optional, relative path or remote URL to a YAML file containing the default CR for the module -# resourceName: "" # optional, default={name}-{channel}, when channel is 'none', the default is {name}-{version}, the name for the ModuleTemplate that will be created # namespace: "" # optional, default=kcp-system, the namespace where the ModuleTemplate will be deployed # security: "" # optional, name of the security scanners config file # internal: false # optional, default=false, determines whether the ModuleTemplate should have the internal flag or not diff --git a/tests/e2e/create/create_suite_test.go b/tests/e2e/create/create_suite_test.go index f8afc3a4..4059c61b 100644 --- a/tests/e2e/create/create_suite_test.go +++ b/tests/e2e/create/create_suite_test.go @@ -22,7 +22,6 @@ const ( invalidConfigs = testdataDir + "invalid/" duplicateResources = invalidConfigs + "duplicate-resources.yaml" - emptyResourceName = invalidConfigs + "empty-resource-name.yaml" missingNameConfig = invalidConfigs + "missing-name.yaml" missingChannelConfig = invalidConfigs + "missing-channel.yaml" missingVersionConfig = invalidConfigs + "missing-version.yaml" diff --git a/tests/e2e/create/create_test.go b/tests/e2e/create/create_test.go index 9cea55d9..8c5d41c6 100644 --- a/tests/e2e/create/create_test.go +++ b/tests/e2e/create/create_test.go @@ -107,20 +107,6 @@ var _ = Describe("Test 'create' command", Ordered, func() { }) }) - Context("Given 'modulectl create' command", func() { - var cmd createCmd - It("When invoked with empty resource name", func() { - cmd = createCmd{ - moduleConfigFile: emptyResourceName, - } - }) - It("Then the command should fail", func() { - err := cmd.execute() - Expect(err).Should(HaveOccurred()) - Expect(err.Error()).Should(ContainSubstring("failed to parse module config: failed to validate module config: failed to validate resources: invalid Option: name must not be empty")) - }) - }) - Context("Given 'modulectl create' command", func() { var cmd createCmd It("When invoked with non https resource", func() { diff --git a/tests/e2e/create/testdata/moduleconfig/invalid/empty-resource-name.yaml b/tests/e2e/create/testdata/moduleconfig/invalid/empty-resource-name.yaml deleted file mode 100644 index ac32b8d3..00000000 --- a/tests/e2e/create/testdata/moduleconfig/invalid/empty-resource-name.yaml +++ /dev/null @@ -1,7 +0,0 @@ -name: kyma-project.io/module/template-operator -channel: regular -version: 1.0.0 -manifest: https://github.com/kyma-project/template-operator/releases/download/1.0.1/template-operator.yaml -resources: -- name: "" - link: http://some.other/location/template-operator.yaml diff --git a/tests/e2e/scaffold/scaffold_suite_test.go b/tests/e2e/scaffold/scaffold_suite_test.go index a666607d..162f0297 100644 --- a/tests/e2e/scaffold/scaffold_suite_test.go +++ b/tests/e2e/scaffold/scaffold_suite_test.go @@ -157,7 +157,6 @@ type moduleConfig struct { ManifestPath string `yaml:"manifest" comment:"required, relative path or remote URL to the manifests"` Mandatory bool `yaml:"mandatory" comment:"optional, default=false, indicates whether the module is mandatory to be installed on all clusters"` DefaultCRPath string `yaml:"defaultCR" comment:"optional, relative path or remote URL to a YAML file containing the default CR for the module"` - ResourceName string `yaml:"resourceName" comment:"optional, default={name}-{channel}, when channel is 'none', the default is {name}-{version}, the name for the ModuleTemplate that will be created"` Namespace string `yaml:"namespace" comment:"optional, default=kcp-system, the namespace where the ModuleTemplate will be deployed"` Security string `yaml:"security" comment:"optional, name of the security scanners config file"` Internal bool `yaml:"internal" comment:"optional, default=false, determines whether the ModuleTemplate should have the internal flag or not"`