Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Patternizer

![Version: 2.1.0](https://img.shields.io/badge/Version-2.1.0-informational?style=flat-square)
![Version: 2.2.0](https://img.shields.io/badge/Version-2.2.0-informational?style=flat-square)
[![Quay Repository](https://img.shields.io/badge/Quay.io-patternizer-blue?logo=quay)](https://quay.io/repository/validatedpatterns/patternizer)
[![CI Pipeline](https://github.com/validatedpatterns/patternizer/actions/workflows/build-push.yaml/badge.svg?branch=main)](https://github.com/validatedpatterns/patternizer/actions/workflows/build-push.yaml)

Expand Down
190 changes: 136 additions & 54 deletions src/cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ var _ = Describe("patternizer init", func() {
expectedClusterGroupValues := types.ValuesClusterGroup{
ClusterGroup: types.ClusterGroup{
Name: "prod",
Namespaces: []types.NamespaceEntry{types.NewNamespaceEntry(filepath.Base(tempDir))},
Namespaces: map[string]interface{}{filepath.Base(tempDir): nil},
Subscriptions: map[string]types.Subscription{},
Applications: map[string]types.Application{},
},
Expand Down Expand Up @@ -145,7 +145,7 @@ var _ = Describe("patternizer init", func() {
expectedClusterGroupValues := types.ValuesClusterGroup{
ClusterGroup: types.ClusterGroup{
Name: "prod",
Namespaces: []types.NamespaceEntry{types.NewNamespaceEntry(expectedNamespace)},
Namespaces: map[string]interface{}{expectedNamespace: nil},
Subscriptions: map[string]types.Subscription{},
Applications: map[string]types.Application{
"test-app1": {
Expand Down Expand Up @@ -204,7 +204,7 @@ var _ = Describe("patternizer init", func() {
expectedClusterGroupValues := types.ValuesClusterGroup{
ClusterGroup: types.ClusterGroup{
Name: "test",
Namespaces: []types.NamespaceEntry{types.NewNamespaceEntry("test-pattern")},
Namespaces: map[string]interface{}{"test-pattern": nil},
Subscriptions: map[string]types.Subscription{},
Applications: map[string]types.Application{},
},
Expand Down Expand Up @@ -253,7 +253,7 @@ var _ = Describe("patternizer init", func() {
expectedClusterGroupValues := types.ValuesClusterGroup{
ClusterGroup: types.ClusterGroup{
Name: "test",
Namespaces: []types.NamespaceEntry{types.NewNamespaceEntry("test-pattern")},
Namespaces: map[string]interface{}{"test-pattern": nil},
Subscriptions: map[string]types.Subscription{},
Applications: map[string]types.Application{
"custom-user-app": {
Expand Down Expand Up @@ -363,16 +363,14 @@ var _ = Describe("patternizer init --with-secrets", func() {
expectedClusterGroupValues := types.ValuesClusterGroup{
ClusterGroup: types.ClusterGroup{
Name: "prod",
Namespaces: []types.NamespaceEntry{
types.NewNamespaceEntry(filepath.Base(tempDir)),
types.NewNamespaceEntry("vault"),
types.NewMapNamespaceEntry(map[string]interface{}{
"external-secrets-operator": map[string]interface{}{
"operatorGroup": true,
"targetNamespaces": []interface{}{},
},
}),
types.NewNamespaceEntry("external-secrets"),
Namespaces: map[string]interface{}{
filepath.Base(tempDir): nil,
"vault": nil,
"external-secrets-operator": map[string]interface{}{
"operatorGroup": true,
"targetNamespaces": []interface{}{},
},
"external-secrets": nil,
},
Subscriptions: map[string]types.Subscription{
"eso": {
Expand Down Expand Up @@ -446,16 +444,14 @@ var _ = Describe("patternizer init --with-secrets", func() {
expectedClusterGroupValues := types.ValuesClusterGroup{
ClusterGroup: types.ClusterGroup{
Name: "prod",
Namespaces: []types.NamespaceEntry{
types.NewNamespaceEntry(expectedNamespace),
types.NewNamespaceEntry("vault"),
types.NewMapNamespaceEntry(map[string]interface{}{
"external-secrets-operator": map[string]interface{}{
"operatorGroup": true,
"targetNamespaces": []interface{}{},
},
}),
types.NewNamespaceEntry("external-secrets"),
Namespaces: map[string]interface{}{
expectedNamespace: nil,
"vault": nil,
"external-secrets-operator": map[string]interface{}{
"operatorGroup": true,
"targetNamespaces": []interface{}{},
},
"external-secrets": nil,
},
Subscriptions: map[string]types.Subscription{
"eso": {
Expand Down Expand Up @@ -537,16 +533,14 @@ var _ = Describe("patternizer init --with-secrets", func() {
expectedClusterGroupValues := types.ValuesClusterGroup{
ClusterGroup: types.ClusterGroup{
Name: "test",
Namespaces: []types.NamespaceEntry{
types.NewNamespaceEntry("test-pattern"),
types.NewNamespaceEntry("vault"),
types.NewMapNamespaceEntry(map[string]interface{}{
"external-secrets-operator": map[string]interface{}{
"operatorGroup": true,
"targetNamespaces": []interface{}{},
},
}),
types.NewNamespaceEntry("external-secrets"),
Namespaces: map[string]interface{}{
"test-pattern": nil,
"vault": nil,
"external-secrets-operator": map[string]interface{}{
"operatorGroup": true,
"targetNamespaces": []interface{}{},
},
"external-secrets": nil,
},
Subscriptions: map[string]types.Subscription{
"eso": {
Expand Down Expand Up @@ -617,16 +611,14 @@ var _ = Describe("patternizer init --with-secrets", func() {
expectedClusterGroupValues := types.ValuesClusterGroup{
ClusterGroup: types.ClusterGroup{
Name: "prod",
Namespaces: []types.NamespaceEntry{
types.NewNamespaceEntry(expectedNamespace),
types.NewNamespaceEntry("vault"),
types.NewMapNamespaceEntry(map[string]interface{}{
"external-secrets-operator": map[string]interface{}{
"operatorGroup": true,
"targetNamespaces": []interface{}{},
},
}),
types.NewNamespaceEntry("external-secrets"),
Namespaces: map[string]interface{}{
expectedNamespace: nil,
"vault": nil,
"external-secrets-operator": map[string]interface{}{
"operatorGroup": true,
"targetNamespaces": []interface{}{},
},
"external-secrets": nil,
},
Subscriptions: map[string]types.Subscription{
"eso": {
Expand Down Expand Up @@ -709,16 +701,14 @@ var _ = Describe("patternizer init --with-secrets", func() {
expectedClusterGroupValues := types.ValuesClusterGroup{
ClusterGroup: types.ClusterGroup{
Name: "test",
Namespaces: []types.NamespaceEntry{
types.NewNamespaceEntry("test-pattern"),
types.NewNamespaceEntry("vault"),
types.NewMapNamespaceEntry(map[string]interface{}{
"external-secrets-operator": map[string]interface{}{
"operatorGroup": true,
"targetNamespaces": []interface{}{},
},
}),
types.NewNamespaceEntry("external-secrets"),
Namespaces: map[string]interface{}{
"test-pattern": nil,
"vault": nil,
"external-secrets-operator": map[string]interface{}{
"operatorGroup": true,
"targetNamespaces": []interface{}{},
},
"external-secrets": nil,
},
Subscriptions: map[string]types.Subscription{
"eso": {
Expand Down Expand Up @@ -772,3 +762,95 @@ var _ = Describe("patternizer init --with-secrets", func() {
})
})
})

var _ = Describe("patternizer init namespace migration", func() {
Context("on a directory with list-style namespaces", Ordered, func() {
var tempDir string

BeforeAll(func() {
tempDir = createTestDir()
listStyleValues := `
clusterGroup:
name: prod
namespaces:
- custom-ns
- vault
- external-secrets-operator:
operatorGroup: true
targetNamespaces: []
- external-secrets
subscriptions: {}
applications: {}
`
Expect(os.WriteFile(filepath.Join(tempDir, "values-global.yaml"), []byte("global:\n pattern: custom-ns\nmain:\n clusterGroupName: prod\n"), 0o644)).To(Succeed())
Expect(os.WriteFile(filepath.Join(tempDir, "values-prod.yaml"), []byte(listStyleValues), 0o644)).To(Succeed())
_ = runCLI(tempDir, "init")
})

It("should migrate list-style namespaces to map-style", func() {
clusterGroupValuesFile := filepath.Join(tempDir, "values-prod.yaml")
expectedClusterGroupValues := types.ValuesClusterGroup{
ClusterGroup: types.ClusterGroup{
Name: "prod",
Namespaces: map[string]interface{}{
"custom-ns": nil,
"vault": nil,
"external-secrets-operator": map[string]interface{}{
"operatorGroup": true,
"targetNamespaces": []interface{}{},
},
"external-secrets": nil,
},
Subscriptions: map[string]types.Subscription{},
Applications: map[string]types.Application{},
},
}
verifyClusterGroupValues(clusterGroupValuesFile, &expectedClusterGroupValues)
})
})

Context("on a directory with map-style namespaces", Ordered, func() {
var tempDir string

BeforeAll(func() {
tempDir = createTestDir()
mapStyleValues := `
clusterGroup:
name: prod
namespaces:
custom-ns:
vault:
external-secrets-operator:
operatorGroup: true
targetNamespaces: []
external-secrets:
subscriptions: {}
applications: {}
`
Expect(os.WriteFile(filepath.Join(tempDir, "values-global.yaml"), []byte("global:\n pattern: custom-ns\nmain:\n clusterGroupName: prod\n"), 0o644)).To(Succeed())
Expect(os.WriteFile(filepath.Join(tempDir, "values-prod.yaml"), []byte(mapStyleValues), 0o644)).To(Succeed())
_ = runCLI(tempDir, "init")
})

It("should preserve map-style namespaces", func() {
clusterGroupValuesFile := filepath.Join(tempDir, "values-prod.yaml")
expectedClusterGroupValues := types.ValuesClusterGroup{
ClusterGroup: types.ClusterGroup{
Name: "prod",
Namespaces: map[string]interface{}{
"custom-ns": nil,
"vault": nil,
"external-secrets-operator": map[string]interface{}{
"operatorGroup": true,
"targetNamespaces": []interface{}{},
},
"external-secrets": nil,
},
Subscriptions: map[string]types.Subscription{},
Applications: map[string]types.Application{},
},
}
verifyClusterGroupValues(clusterGroupValuesFile, &expectedClusterGroupValues)
})
})
})
17 changes: 2 additions & 15 deletions src/internal/pattern/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,8 @@ func mergeClusterGroupValues(defaults, existing *types.ValuesClusterGroup) {
defaults.ClusterGroup.Applications[key] = app
}

existingNamespaceMap := make(map[string]bool)
for _, ns := range existing.ClusterGroup.Namespaces {
found := false
for _, defaultNs := range defaults.ClusterGroup.Namespaces {
if ns.Equal(defaultNs) {
found = true
break
}
}
if !found {
defaults.ClusterGroup.Namespaces = append(defaults.ClusterGroup.Namespaces, ns)
}
if nsStr, ok := ns.GetString(); ok {
existingNamespaceMap[nsStr] = true
}
for nsName, nsConfig := range existing.ClusterGroup.Namespaces {
defaults.ClusterGroup.Namespaces[nsName] = nsConfig
}

existingProjectMap := make(map[string]bool)
Expand Down
6 changes: 6 additions & 0 deletions src/internal/pattern/pattern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ var _ = Describe("ProcessClusterGroupValues", func() {
Expect(getNestedValue(processedValues, tt.path)).To(Equal(tt.expected),
"Field %v should be %v", tt.path, tt.expected)
}

clusterGroup := processedValues["clusterGroup"].(map[string]interface{})
namespaces := clusterGroup["namespaces"].(map[string]interface{})
Expect(namespaces).To(HaveKey("custom-ns1"))
Expect(namespaces).To(HaveKey("custom-ns2"))
Expect(namespaces).To(HaveKey("test-pattern"))
})

It("should preserve custom application fields", func() {
Expand Down
Loading
Loading