Reputation: 1
sorry for my poor english. I try to iterate with range but I have a bad carriage return after the dash. I tested different writings but I did not find my happiness.
run command: helm template phototest . -f ~/repoGit/clusters/prod/helm-values/app-public/phototest/values.yaml -n phototestyfs --debug
my values.yaml:
topologySpreadConstraints:
enabled: true
contraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/datacenter
whenUnsatisfiable: ScheduleAnyway
- maxSkew: 2
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
My template:
apiVersion: apps/v1
kind: Deployment
[...]
spec:
[...]
template:
[...]
spec:
{{- if .Values.topologySpreadConstraints.enabled }}
topologySpreadConstraints:
{{- range .Values.topologySpreadConstraints.contraints }}
- {{- toYaml . | nindent 10 -}}
{{- end }}
{{- end }}
the output:
topologySpreadConstraints:
-
maxSkew: 1
topologyKey: topology.kubernetes.io/datacenter
whenUnsatisfiable: ScheduleAnyway
-
maxSkew: 2
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
and I wish:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/datacenter
whenUnsatisfiable: ScheduleAnyway
- maxSkew: 2
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
I tried this but the same result:
{{- range $idx, $contraint := .Values.topologySpreadConstraints.contraints}}
- {{- $contraint | toYaml | trimSuffix "\n" | nindent 10 }}
{{- end }
or
{{- range .Values.topologySpreadConstraints.contraints }}
- {{- toYaml . | nindent 10 }}
{{- end }}
or
{{- range .Values.topologySpreadConstraints.contraints }}
- {{- . | toYaml | nindent 10 -}}
{{- end }}
or
{{- range $idx, $contraint := .Values.topologySpreadConstraints.contraints}}
- {{- $contraint | toYaml | nindent 10 -}}
{{- end }}
I tried with option indent instead of nindent and I get this output:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/datacenter
whenUnsatisfiable: ScheduleAnyway
- maxSkew: 2
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
Error: YAML parse error on ilius-java/templates/deployment.yaml: error converting YAML to JSON: yaml: line 103: did not find expected '-' indicator
helm.go:84: [debug] error converting YAML to JSON: yaml: line 103: did not find expected '-' indicator
YAML parse error on ilius-java/templates/deployment.yaml
I searched on the web any solutions but I don't find.
Output of helm version
: v3.8.0", GitCommit:"d14138609b01886f544b2025f5000351c9eb092e", GitTreeState:"clean", GoVersion:"go1.17.5"}
Output of kubectl version
:
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.1", GitCommit:"632ed300f2c34f6d6d15ca4cef3d3c7073412212", GitTreeState:"clean", BuildDate:"2021-08-19T15:45:37Z", GoVersion:"go1.16.7", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.1", GitCommit:"5e58841cce77d4bc13713ad2b91fa0d961e69192", GitTreeState:"clean", BuildDate:"2021-05-12T14:12:29Z", GoVersion:"go1.16.4", Compiler:"gc", Platform:"linux/amd64"}
Upvotes: 0
Views: 686
Reputation: 20517
The fundamental problem you have is that you use nindent
. The n
stands for a newline, which is prepended.
{{ nindent $count $str }}
indent $str with $count space chars on the left and prepend a new line to $str
So in a nutshell, you cannot use nindent
. However, it is valid yaml with the newlines, so you don't have to bother trying to fix it. Its not broken.
Upvotes: 1