Fix some indentation behavio + add indent flag
This commit is contained in:
@@ -16,22 +16,25 @@ func BuildDeployment(deployment *helm.Deployment, name, templatesDir string) {
|
||||
fp, _ := os.Create(fname)
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
enc := yaml.NewEncoder(buffer)
|
||||
enc.SetIndent(2)
|
||||
enc.SetIndent(IndentSize)
|
||||
enc.Encode(deployment)
|
||||
_content := string(buffer.Bytes())
|
||||
content := strings.Split(string(_content), "\n")
|
||||
dataname := ""
|
||||
component := deployment.Spec.Selector["matchLabels"].(map[string]string)[helm.K+"/component"]
|
||||
n := 0 // will be count of lines only on "persistentVolumeClaim" line, to indent "else" and "end" at the right place
|
||||
for _, line := range content {
|
||||
if strings.Contains(line, "name:") {
|
||||
dataname = strings.Split(line, ":")[1]
|
||||
dataname = strings.TrimSpace(dataname)
|
||||
} else if strings.Contains(line, "persistentVolumeClaim") {
|
||||
line = " {{- if .Values." + component + ".persistence." + dataname + ".enabled }}\n" + line
|
||||
n = CountSpaces(line)
|
||||
line = strings.Repeat(" ", n) + "{{- if .Values." + component + ".persistence." + dataname + ".enabled }}\n" + line
|
||||
} else if strings.Contains(line, "claimName") {
|
||||
line += "\n {{ else }}"
|
||||
line += "\n emptyDir: {}"
|
||||
line += "\n {{- end }}"
|
||||
spaces := strings.Repeat(" ", n)
|
||||
line += "\n" + spaces + "{{ else }}"
|
||||
line += "\n" + spaces + "emptyDir: {}"
|
||||
line += "\n" + spaces + "{{- end }}"
|
||||
}
|
||||
fp.WriteString(line + "\n")
|
||||
}
|
||||
|
Reference in New Issue
Block a user