掌舵迭代,射程不良后返回破折号

发布于 2025-01-31 15:50:29 字数 3227 浏览 3 评论 0原文

对不起,我的英语不好。 我尝试使用射程迭代,但在破折号之后我的马车返回不良。 我测试了不同的著作,但没有找到自己的幸福。

运行命令: 头盔模板光电击。 -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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七度光 2025-02-07 15:50:29

您遇到的基本问题是您使用nindentn代表一个新线,这是预先审核的。

{{{nindent $ count $ str}}
缩进$ str,左侧有$ Count Space Chars,并准备了一条新线条

在简而言之的情况下将一条新的行预付给$ str,因此您不能使用nindent。但是,它对新线是有效的YAML,因此您不必费心尝试修复它。它没有破碎。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文