@@ -16,7 +16,7 @@ const metaTemplate = `apiVersion: %[1]s
1616kind: %[2]s
1717metadata:
1818 name: %[3]s
19- namespace: %[7]s # Include the namespace here
19+ %[7]s
2020 labels:
2121%[5]s
2222 {{- include "%[4]s.labels" . | nindent 4 }}
@@ -57,7 +57,7 @@ func ProcessObjMeta(appMeta helmify.AppMetadata, obj *unstructured.Unstructured,
5757 }
5858
5959 var err error
60- var labels , annotations string
60+ var labels , annotations , namespace string
6161 if len (obj .GetLabels ()) != 0 {
6262 l := obj .GetLabels ()
6363 // provided by Helm
@@ -81,7 +81,13 @@ func ProcessObjMeta(appMeta helmify.AppMetadata, obj *unstructured.Unstructured,
8181 return "" , err
8282 }
8383 }
84- ns := obj .GetNamespace ()
84+
85+ if obj .GetNamespace () != "" {
86+ namespace , err = yamlformat .Marshal (map [string ]interface {}{"namespace" : obj .GetNamespace ()}, 0 )
87+ if err != nil {
88+ return "" , err
89+ }
90+ }
8591
8692 templatedName := appMeta .TemplatedName (obj .GetName ())
8793 apiVersion , kind := obj .GetObjectKind ().GroupVersionKind ().ToAPIVersionAndKind ()
@@ -102,7 +108,7 @@ func ProcessObjMeta(appMeta helmify.AppMetadata, obj *unstructured.Unstructured,
102108 annotations = fmt .Sprintf (annotationsTemplate , name , kind )
103109 }
104110
105- metaStr = fmt .Sprintf (metaTemplate , apiVersion , kind , templatedName , appMeta .ChartName (), labels , annotations , ns )
111+ metaStr = fmt .Sprintf (metaTemplate , apiVersion , kind , templatedName , appMeta .ChartName (), labels , annotations , namespace )
106112 metaStr = strings .Trim (metaStr , " \n " )
107113 metaStr = strings .ReplaceAll (metaStr , "\n \n " , "\n " )
108114 return metaStr , nil
0 commit comments