Skip to content

Commit

Permalink
fix: Add spec.ModuleName and spec.version to ModuleTemplate (#114)
Browse files Browse the repository at this point in the history
* Add version and moduleName

* Add unit test

* Adapt E2E test
  • Loading branch information
nesmabadr authored Nov 27, 2024
1 parent d4e5eb1 commit 5aed1a2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
7 changes: 6 additions & 1 deletion internal/service/templategenerator/templategenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ metadata:
{{- end}}
{{- end}}
spec:
moduleName: {{.ModuleName}}
version: {{.ModuleVersion}}
mandatory: {{.Mandatory}}
info:
repository: {{.Repository}}
Expand Down Expand Up @@ -105,8 +107,10 @@ spec:
)

type moduleTemplateData struct {
ModuleName string
ResourceName string
Namespace string
ModuleVersion string
Descriptor compdesc.ComponentDescriptorVersion
Repository string
Documentation string
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions internal/service/templategenerator/templategenerator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
38 changes: 16 additions & 22 deletions tests/e2e/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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")
Expand Down Expand Up @@ -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"))

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5aed1a2

Please sign in to comment.