From 9cb35374eb343ad68a0ed6e7a3b88aa64bd4b4ea Mon Sep 17 00:00:00 2001 From: "Badr, Nesma" Date: Wed, 27 Nov 2024 12:06:06 +0100 Subject: [PATCH 1/4] Add version and moduleName --- internal/service/templategenerator/templategenerator.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/service/templategenerator/templategenerator.go b/internal/service/templategenerator/templategenerator.go index 5e28edf..e4475a4 100644 --- a/internal/service/templategenerator/templategenerator.go +++ b/internal/service/templategenerator/templategenerator.go @@ -59,6 +59,8 @@ metadata: {{- end}} {{- end}} spec: + moduleName: {{.ModuleName}} + version: {{.ModuleVersion}} mandatory: {{.Mandatory}} info: repository: {{.Repository}} @@ -105,8 +107,10 @@ spec: ) type moduleTemplateData struct { + ModuleName string ResourceName string Namespace string + ModuleVersion string Descriptor compdesc.ComponentDescriptorVersion Repository string Documentation string @@ -159,8 +163,10 @@ func (s *Service) GenerateModuleTemplate( } mtData := moduleTemplateData{ + ModuleName: shortName, ResourceName: moduleTemplateName, Namespace: moduleConfig.Namespace, + ModuleVersion: moduleConfig.Version, Descriptor: cva, Repository: moduleConfig.Repository, Documentation: moduleConfig.Documentation, @@ -217,7 +223,6 @@ func generateAnnotations(config *contentprovider.ModuleConfig, isCrdClusterScope if annotations == nil { annotations = make(map[string]string) } - annotations[shared.ModuleVersionAnnotation] = config.Version if isCrdClusterScoped { annotations[shared.IsClusterScopedAnnotation] = shared.EnableLabelValue } else { From 7cc914610908cb14520357083cc7c7ccb3a5aba7 Mon Sep 17 00:00:00 2001 From: "Badr, Nesma" Date: Wed, 27 Nov 2024 12:11:40 +0100 Subject: [PATCH 2/4] Add unit test --- internal/service/templategenerator/templategenerator_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/service/templategenerator/templategenerator_test.go b/internal/service/templategenerator/templategenerator_test.go index c47ac97..4b3a20b 100644 --- a/internal/service/templategenerator/templategenerator_test.go +++ b/internal/service/templategenerator/templategenerator_test.go @@ -58,6 +58,8 @@ func TestGenerateModuleTemplate_Success(t *testing.T) { require.NoError(t, err) require.Equal(t, "output.yaml", mockFS.path) + require.Contains(t, mockFS.writtenTemplate, "version: 1.0.0") + require.Contains(t, mockFS.writtenTemplate, "moduleName: component") require.Contains(t, mockFS.writtenTemplate, "component-1.0.0") require.Contains(t, mockFS.writtenTemplate, "default") require.Contains(t, mockFS.writtenTemplate, "test-data") From 61a4e95dda97ed19f6ad41ce5fb1fc2023a20acb Mon Sep 17 00:00:00 2001 From: "Badr, Nesma" Date: Wed, 27 Nov 2024 12:15:12 +0100 Subject: [PATCH 3/4] Adapt E2E test --- tests/e2e/create/create_test.go | 38 ++++++++++++++------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/tests/e2e/create/create_test.go b/tests/e2e/create/create_test.go index e680fc2..bc57a4a 100644 --- a/tests/e2e/create/create_test.go +++ b/tests/e2e/create/create_test.go @@ -304,6 +304,8 @@ var _ = Describe("Test 'create' command", Ordered, func() { Expect(template.Name).To(Equal("template-operator-1.0.0")) By("And spec.info should be correct") + Expect(template.Spec.ModuleName).To(Equal("template-operator")) + Expect(template.Spec.Version).To(Equal("1.0.0")) Expect(template.Spec.Info.Repository).To(Equal("https://github.com/kyma-project/template-operator")) Expect(template.Spec.Info.Documentation).To(Equal("https://github.com/kyma-project/template-operator/blob/main/README.md")) Expect(template.Spec.Info.Icons).To(HaveLen(1)) @@ -312,7 +314,6 @@ var _ = Describe("Test 'create' command", Ordered, func() { By("And annotations should be correct") annotations := template.Annotations - Expect(annotations[shared.ModuleVersionAnnotation]).To(Equal("1.0.0")) Expect(annotations[shared.IsClusterScopedAnnotation]).To(Equal("false")) By("And descriptor.component.repositoryContexts should be correct") @@ -402,10 +403,11 @@ var _ = Describe("Test 'create' command", Ordered, func() { descriptor := getDescriptor(template) Expect(descriptor).ToNot(BeNil()) Expect(template.Name).To(Equal("template-operator-1.0.1")) + Expect(template.Spec.ModuleName).To(Equal("template-operator")) + Expect(template.Spec.Version).To(Equal("1.0.1")) By("And new annotation should be correctly added") annotations := template.Annotations - Expect(annotations[shared.ModuleVersionAnnotation]).To(Equal("1.0.1")) Expect(annotations[shared.IsClusterScopedAnnotation]).To(Equal("false")) Expect(annotations["operator.kyma-project.io/doc-url"]).To(Equal("https://kyma-project.io")) @@ -437,10 +439,8 @@ var _ = Describe("Test 'create' command", Ordered, func() { descriptor := getDescriptor(template) Expect(descriptor).ToNot(BeNil()) Expect(template.Name).To(Equal("template-operator-1.0.2")) - - By("And annotation should have correct version") - annotations := template.Annotations - Expect(annotations[shared.ModuleVersionAnnotation]).To(Equal("1.0.2")) + Expect(template.Spec.ModuleName).To(Equal("template-operator")) + Expect(template.Spec.Version).To(Equal("1.0.2")) By("And descriptor.component.resources should be correct") Expect(descriptor.Resources).To(HaveLen(2)) @@ -484,6 +484,8 @@ var _ = Describe("Test 'create' command", Ordered, func() { descriptor := getDescriptor(template) Expect(descriptor).ToNot(BeNil()) Expect(template.Name).To(Equal("template-operator-1.0.3")) + Expect(template.Spec.ModuleName).To(Equal("template-operator")) + Expect(template.Spec.Version).To(Equal("1.0.3")) By("And descriptor.component.resources should be correct") Expect(descriptor.Resources).To(HaveLen(3)) @@ -594,10 +596,8 @@ var _ = Describe("Test 'create' command", Ordered, func() { descriptor := getDescriptor(template) Expect(descriptor).ToNot(BeNil()) Expect(template.Name).To(Equal("template-operator-1.0.4")) - - By("And annotation should have correct version") - annotations := template.Annotations - Expect(annotations[shared.ModuleVersionAnnotation]).To(Equal("1.0.4")) + Expect(template.Spec.ModuleName).To(Equal("template-operator")) + Expect(template.Spec.Version).To(Equal("1.0.4")) By("And spec.mandatory should be true") Expect(template.Spec.Mandatory).To(BeTrue()) @@ -626,10 +626,8 @@ var _ = Describe("Test 'create' command", Ordered, func() { descriptor := getDescriptor(template) Expect(descriptor).ToNot(BeNil()) Expect(template.Name).To(Equal("template-operator-1.0.5")) - - By("And annotation should have correct version") - annotations := template.Annotations - Expect(annotations[shared.ModuleVersionAnnotation]).To(Equal("1.0.5")) + Expect(template.Spec.ModuleName).To(Equal("template-operator")) + Expect(template.Spec.Version).To(Equal("1.0.5")) By("And spec.manager should be correct") manager := template.Spec.Manager @@ -665,10 +663,8 @@ var _ = Describe("Test 'create' command", Ordered, func() { descriptor := getDescriptor(template) Expect(descriptor).ToNot(BeNil()) Expect(template.Name).To(Equal("template-operator-1.0.6")) - - By("And annotation should have correct version") - annotations := template.Annotations - Expect(annotations[shared.ModuleVersionAnnotation]).To(Equal("1.0.6")) + Expect(template.Spec.ModuleName).To(Equal("template-operator")) + Expect(template.Spec.Version).To(Equal("1.0.6")) By("And spec.manager should be correct") manager := template.Spec.Manager @@ -704,10 +700,8 @@ var _ = Describe("Test 'create' command", Ordered, func() { Expect(descriptor).ToNot(BeNil()) Expect(template.Name).To(Equal("template-operator-1.0.7")) - - By("And annotation should have correct version") - annotations := template.Annotations - Expect(annotations[shared.ModuleVersionAnnotation]).To(Equal("1.0.7")) + Expect(template.Spec.ModuleName).To(Equal("template-operator")) + Expect(template.Spec.Version).To(Equal("1.0.7")) By("And spec.associatedResources should be correct") resources := template.Spec.AssociatedResources From 50123026ce517037f526976d598037dc2f506ad2 Mon Sep 17 00:00:00 2001 From: "Badr, Nesma" Date: Thu, 28 Nov 2024 12:29:54 +0100 Subject: [PATCH 4/4] Add fields for checkmarxOne --- sec-scanners-config.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sec-scanners-config.yaml b/sec-scanners-config.yaml index 04402ed..f95e476 100644 --- a/sec-scanners-config.yaml +++ b/sec-scanners-config.yaml @@ -1,4 +1,7 @@ module-name: modulectl +kind: kcp +checkmarxOne: + checkmarx_preset: golang whitesource: language: golang-mod exclude: