@@ -95,7 +95,7 @@ var _ = Describe("patternizer init", func() {
9595 expectedClusterGroupValues := types.ValuesClusterGroup {
9696 ClusterGroup : types.ClusterGroup {
9797 Name : "prod" ,
98- Namespaces : []types. NamespaceEntry { types . NewNamespaceEntry ( filepath .Base (tempDir )) },
98+ Namespaces : map [ string ] interface {}{ filepath .Base (tempDir ): nil },
9999 Subscriptions : map [string ]types.Subscription {},
100100 Applications : map [string ]types.Application {},
101101 },
@@ -145,7 +145,7 @@ var _ = Describe("patternizer init", func() {
145145 expectedClusterGroupValues := types.ValuesClusterGroup {
146146 ClusterGroup : types.ClusterGroup {
147147 Name : "prod" ,
148- Namespaces : []types. NamespaceEntry { types . NewNamespaceEntry ( expectedNamespace ) },
148+ Namespaces : map [ string ] interface {}{ expectedNamespace : nil },
149149 Subscriptions : map [string ]types.Subscription {},
150150 Applications : map [string ]types.Application {
151151 "test-app1" : {
@@ -204,7 +204,7 @@ var _ = Describe("patternizer init", func() {
204204 expectedClusterGroupValues := types.ValuesClusterGroup {
205205 ClusterGroup : types.ClusterGroup {
206206 Name : "test" ,
207- Namespaces : []types. NamespaceEntry { types . NewNamespaceEntry ( "test-pattern" ) },
207+ Namespaces : map [ string ] interface {}{ "test-pattern" : nil },
208208 Subscriptions : map [string ]types.Subscription {},
209209 Applications : map [string ]types.Application {},
210210 },
@@ -253,7 +253,7 @@ var _ = Describe("patternizer init", func() {
253253 expectedClusterGroupValues := types.ValuesClusterGroup {
254254 ClusterGroup : types.ClusterGroup {
255255 Name : "test" ,
256- Namespaces : []types. NamespaceEntry { types . NewNamespaceEntry ( "test-pattern" ) },
256+ Namespaces : map [ string ] interface {}{ "test-pattern" : nil },
257257 Subscriptions : map [string ]types.Subscription {},
258258 Applications : map [string ]types.Application {
259259 "custom-user-app" : {
@@ -363,16 +363,14 @@ var _ = Describe("patternizer init --with-secrets", func() {
363363 expectedClusterGroupValues := types.ValuesClusterGroup {
364364 ClusterGroup : types.ClusterGroup {
365365 Name : "prod" ,
366- Namespaces : []types.NamespaceEntry {
367- types .NewNamespaceEntry (filepath .Base (tempDir )),
368- types .NewNamespaceEntry ("vault" ),
369- types .NewMapNamespaceEntry (map [string ]interface {}{
370- "external-secrets-operator" : map [string ]interface {}{
371- "operatorGroup" : true ,
372- "targetNamespaces" : []interface {}{},
373- },
374- }),
375- types .NewNamespaceEntry ("external-secrets" ),
366+ Namespaces : map [string ]interface {}{
367+ filepath .Base (tempDir ): nil ,
368+ "vault" : nil ,
369+ "external-secrets-operator" : map [string ]interface {}{
370+ "operatorGroup" : true ,
371+ "targetNamespaces" : []interface {}{},
372+ },
373+ "external-secrets" : nil ,
376374 },
377375 Subscriptions : map [string ]types.Subscription {
378376 "eso" : {
@@ -446,16 +444,14 @@ var _ = Describe("patternizer init --with-secrets", func() {
446444 expectedClusterGroupValues := types.ValuesClusterGroup {
447445 ClusterGroup : types.ClusterGroup {
448446 Name : "prod" ,
449- Namespaces : []types.NamespaceEntry {
450- types .NewNamespaceEntry (expectedNamespace ),
451- types .NewNamespaceEntry ("vault" ),
452- types .NewMapNamespaceEntry (map [string ]interface {}{
453- "external-secrets-operator" : map [string ]interface {}{
454- "operatorGroup" : true ,
455- "targetNamespaces" : []interface {}{},
456- },
457- }),
458- types .NewNamespaceEntry ("external-secrets" ),
447+ Namespaces : map [string ]interface {}{
448+ expectedNamespace : nil ,
449+ "vault" : nil ,
450+ "external-secrets-operator" : map [string ]interface {}{
451+ "operatorGroup" : true ,
452+ "targetNamespaces" : []interface {}{},
453+ },
454+ "external-secrets" : nil ,
459455 },
460456 Subscriptions : map [string ]types.Subscription {
461457 "eso" : {
@@ -537,16 +533,14 @@ var _ = Describe("patternizer init --with-secrets", func() {
537533 expectedClusterGroupValues := types.ValuesClusterGroup {
538534 ClusterGroup : types.ClusterGroup {
539535 Name : "test" ,
540- Namespaces : []types.NamespaceEntry {
541- types .NewNamespaceEntry ("test-pattern" ),
542- types .NewNamespaceEntry ("vault" ),
543- types .NewMapNamespaceEntry (map [string ]interface {}{
544- "external-secrets-operator" : map [string ]interface {}{
545- "operatorGroup" : true ,
546- "targetNamespaces" : []interface {}{},
547- },
548- }),
549- types .NewNamespaceEntry ("external-secrets" ),
536+ Namespaces : map [string ]interface {}{
537+ "test-pattern" : nil ,
538+ "vault" : nil ,
539+ "external-secrets-operator" : map [string ]interface {}{
540+ "operatorGroup" : true ,
541+ "targetNamespaces" : []interface {}{},
542+ },
543+ "external-secrets" : nil ,
550544 },
551545 Subscriptions : map [string ]types.Subscription {
552546 "eso" : {
@@ -617,16 +611,14 @@ var _ = Describe("patternizer init --with-secrets", func() {
617611 expectedClusterGroupValues := types.ValuesClusterGroup {
618612 ClusterGroup : types.ClusterGroup {
619613 Name : "prod" ,
620- Namespaces : []types.NamespaceEntry {
621- types .NewNamespaceEntry (expectedNamespace ),
622- types .NewNamespaceEntry ("vault" ),
623- types .NewMapNamespaceEntry (map [string ]interface {}{
624- "external-secrets-operator" : map [string ]interface {}{
625- "operatorGroup" : true ,
626- "targetNamespaces" : []interface {}{},
627- },
628- }),
629- types .NewNamespaceEntry ("external-secrets" ),
614+ Namespaces : map [string ]interface {}{
615+ expectedNamespace : nil ,
616+ "vault" : nil ,
617+ "external-secrets-operator" : map [string ]interface {}{
618+ "operatorGroup" : true ,
619+ "targetNamespaces" : []interface {}{},
620+ },
621+ "external-secrets" : nil ,
630622 },
631623 Subscriptions : map [string ]types.Subscription {
632624 "eso" : {
@@ -709,16 +701,14 @@ var _ = Describe("patternizer init --with-secrets", func() {
709701 expectedClusterGroupValues := types.ValuesClusterGroup {
710702 ClusterGroup : types.ClusterGroup {
711703 Name : "test" ,
712- Namespaces : []types.NamespaceEntry {
713- types .NewNamespaceEntry ("test-pattern" ),
714- types .NewNamespaceEntry ("vault" ),
715- types .NewMapNamespaceEntry (map [string ]interface {}{
716- "external-secrets-operator" : map [string ]interface {}{
717- "operatorGroup" : true ,
718- "targetNamespaces" : []interface {}{},
719- },
720- }),
721- types .NewNamespaceEntry ("external-secrets" ),
704+ Namespaces : map [string ]interface {}{
705+ "test-pattern" : nil ,
706+ "vault" : nil ,
707+ "external-secrets-operator" : map [string ]interface {}{
708+ "operatorGroup" : true ,
709+ "targetNamespaces" : []interface {}{},
710+ },
711+ "external-secrets" : nil ,
722712 },
723713 Subscriptions : map [string ]types.Subscription {
724714 "eso" : {
@@ -772,3 +762,95 @@ var _ = Describe("patternizer init --with-secrets", func() {
772762 })
773763 })
774764})
765+
766+ var _ = Describe ("patternizer init namespace migration" , func () {
767+ Context ("on a directory with list-style namespaces" , Ordered , func () {
768+ var tempDir string
769+
770+ BeforeAll (func () {
771+ tempDir = createTestDir ()
772+ listStyleValues := `
773+ clusterGroup:
774+ name: prod
775+ namespaces:
776+ - custom-ns
777+ - vault
778+ - external-secrets-operator:
779+ operatorGroup: true
780+ targetNamespaces: []
781+ - external-secrets
782+ subscriptions: {}
783+ applications: {}
784+ `
785+ Expect (os .WriteFile (filepath .Join (tempDir , "values-global.yaml" ), []byte ("global:\n pattern: custom-ns\n main:\n clusterGroupName: prod\n " ), 0o644 )).To (Succeed ())
786+ Expect (os .WriteFile (filepath .Join (tempDir , "values-prod.yaml" ), []byte (listStyleValues ), 0o644 )).To (Succeed ())
787+ _ = runCLI (tempDir , "init" )
788+ })
789+
790+ It ("should migrate list-style namespaces to map-style" , func () {
791+ clusterGroupValuesFile := filepath .Join (tempDir , "values-prod.yaml" )
792+ expectedClusterGroupValues := types.ValuesClusterGroup {
793+ ClusterGroup : types.ClusterGroup {
794+ Name : "prod" ,
795+ Namespaces : map [string ]interface {}{
796+ "custom-ns" : nil ,
797+ "vault" : nil ,
798+ "external-secrets-operator" : map [string ]interface {}{
799+ "operatorGroup" : true ,
800+ "targetNamespaces" : []interface {}{},
801+ },
802+ "external-secrets" : nil ,
803+ },
804+ Subscriptions : map [string ]types.Subscription {},
805+ Applications : map [string ]types.Application {},
806+ },
807+ }
808+ verifyClusterGroupValues (clusterGroupValuesFile , & expectedClusterGroupValues )
809+ })
810+ })
811+
812+ Context ("on a directory with map-style namespaces" , Ordered , func () {
813+ var tempDir string
814+
815+ BeforeAll (func () {
816+ tempDir = createTestDir ()
817+ mapStyleValues := `
818+ clusterGroup:
819+ name: prod
820+ namespaces:
821+ custom-ns:
822+ vault:
823+ external-secrets-operator:
824+ operatorGroup: true
825+ targetNamespaces: []
826+ external-secrets:
827+ subscriptions: {}
828+ applications: {}
829+ `
830+ Expect (os .WriteFile (filepath .Join (tempDir , "values-global.yaml" ), []byte ("global:\n pattern: custom-ns\n main:\n clusterGroupName: prod\n " ), 0o644 )).To (Succeed ())
831+ Expect (os .WriteFile (filepath .Join (tempDir , "values-prod.yaml" ), []byte (mapStyleValues ), 0o644 )).To (Succeed ())
832+ _ = runCLI (tempDir , "init" )
833+ })
834+
835+ It ("should preserve map-style namespaces" , func () {
836+ clusterGroupValuesFile := filepath .Join (tempDir , "values-prod.yaml" )
837+ expectedClusterGroupValues := types.ValuesClusterGroup {
838+ ClusterGroup : types.ClusterGroup {
839+ Name : "prod" ,
840+ Namespaces : map [string ]interface {}{
841+ "custom-ns" : nil ,
842+ "vault" : nil ,
843+ "external-secrets-operator" : map [string ]interface {}{
844+ "operatorGroup" : true ,
845+ "targetNamespaces" : []interface {}{},
846+ },
847+ "external-secrets" : nil ,
848+ },
849+ Subscriptions : map [string ]types.Subscription {},
850+ Applications : map [string ]types.Application {},
851+ },
852+ }
853+ verifyClusterGroupValues (clusterGroupValuesFile , & expectedClusterGroupValues )
854+ })
855+ })
856+ })
0 commit comments