掌舵迭代,射程不良后返回破折号
对不起,我的英语不好。 我尝试使用射程迭代,但在破折号之后我的马车返回不良。 我测试了不同的著作,但没有找到自己的幸福。
运行命令: 头盔模板光电击。 -f〜/repogit/clusters/prod/helm-values/app-public/phototest/dureat.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
我的模板:我的模板:
apiVersion: apps/v1
kind: Deployment
[...]
spec:
[...]
template:
[...]
spec:
{{- if .Values.topologySpreadConstraints.enabled }}
topologySpreadConstraints:
{{- range .Values.topologySpreadConstraints.contraints }}
- {{- toYaml . | nindent 10 -}}
{{- end }}
{{- end }}
输出:
topologySpreadConstraints:
-
maxSkew: 1
topologyKey: topology.kubernetes.io/datacenter
whenUnsatisfiable: ScheduleAnyway
-
maxSkew: 2
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
我希望:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/datacenter
whenUnsatisfiable: ScheduleAnyway
- maxSkew: 2
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
我尝试过,但我尝试过,但是相同结果:
{{- 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 }}
我尝试使用选项缩进而不是nindent,并且得到了此输出:
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
我在网络上搜索了任何解决方案,但我找不到。
Helm版本的输出:V3.8.0“,GitCommit:” D14138609B01886F544B2025F5000351C9EB092E,Gittreestate:“ Cleans of goversion”,goversion:“ go1.17.5”}
客户端版本:version.info {major:“ 1”,次要:“ 22”,gitversion:“ v1.22.1”,gitcommit:“ 632ED300F2C34F6D6D6D6D6D15CA4CEF3D3C7073C7073412212” 37Z“,戈尔维”:“ go1.16.7”,编译器:“ gc”,platform:“ linux/amd64”} 服务器版本:版本。 29Z“,goversion:“ GO1.16.4”,编译器:“ GC”,Platform:“ Linux/amd64”}
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"}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您遇到的基本问题是您使用
nindent
。n
代表一个新线,这是预先审核的。在简而言之的情况下将一条新的行预付给$ str,因此您不能使用
nindent
。但是,它对新线是有效的YAML,因此您不必费心尝试修复它。它没有破碎。The fundamental problem you have is that you use
nindent
. Then
stands for a newline, which is prepended.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.