Skip to content

Commit 09184d2

Browse files
suvaanshkumararttor
authored andcommitted
fix blank lines for namespace, add new flag --preserve-ns
1 parent 3951dd7 commit 09184d2

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

cmd/helmify/flags.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (i *arrayFlags) Set(value string) error {
5454
func ReadFlags() config.Config {
5555
files := arrayFlags{}
5656
result := config.Config{}
57-
var h, help, version, crd bool
57+
var h, help, version, crd , preservens bool
5858
flag.BoolVar(&h, "h", false, "Print help. Example: helmify -h")
5959
flag.BoolVar(&help, "help", false, "Print help. Example: helmify -help")
6060
flag.BoolVar(&version, "version", false, "Print helmify version. Example: helmify -version")
@@ -68,7 +68,7 @@ func ReadFlags() config.Config {
6868
flag.BoolVar(&result.FilesRecursively, "r", false, "Scan dirs from -f option recursively")
6969
flag.BoolVar(&result.OriginalName, "original-name", false, "Use the object's original name instead of adding the chart's release name as the common prefix.")
7070
flag.Var(&files, "f", "File or directory containing k8s manifests")
71-
71+
flag.BoolVar(&preservens, "preserve-ns", false, "Use the object's original namespace instead of adding all the resources to a common namespace")
7272
flag.Parse()
7373
if h || help {
7474
fmt.Print(helpText)
@@ -87,6 +87,9 @@ func ReadFlags() config.Config {
8787
if crd {
8888
result.Crd = crd
8989
}
90+
if preservens {
91+
result.PreserveNs = true
92+
}
9093
result.Files = files
9194
return result
9295
}

pkg/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ type Config struct {
3636
FilesRecursively bool
3737
// OriginalName retains Kubernetes resource's original name
3838
OriginalName bool
39+
// PreserveNs retains the namespaces on the Kubernetes manifests
40+
PreserveNs bool
3941
}
4042

4143
func (c *Config) Validate() error {

pkg/processor/meta.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const metaTemplate = `apiVersion: %[1]s
1616
kind: %[2]s
1717
metadata:
1818
name: %[3]s
19-
%[7]s
19+
%[7]s
2020
labels:
2121
%[5]s
2222
{{- include "%[4]s.labels" . | nindent 4 }}
@@ -82,8 +82,8 @@ func ProcessObjMeta(appMeta helmify.AppMetadata, obj *unstructured.Unstructured,
8282
}
8383
}
8484

85-
if obj.GetNamespace() != "" {
86-
namespace, err = yamlformat.Marshal(map[string]interface{}{"namespace": obj.GetNamespace()}, 0)
85+
if (obj.GetNamespace() != "") && (appMeta.Config().PreserveNs){
86+
namespace, err = yamlformat.Marshal(map[string]interface{}{"namespace": obj.GetNamespace()}, 2)
8787
if err != nil {
8888
return "", err
8989
}

0 commit comments

Comments
 (0)