到Yaml生成问题的多行舵值

问题描述 投票:0回答:1

我有一个带有入口类对象的头盔图。在入口类型中,我想允许从值文件中加载自定义注释。我的入口类型如下:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: "bla"
  {{- if .Values.routing.annotations }}
  annotations:
    {{ toYaml .Values.routing.annotations | indent 4 }}
  {{- end }}
  labels:
    app: {{ template "name" . }}
    chart: {{ template "chart" . }}
    release: {{ .Release.Name }}
spec:
  {{- if .Values.routing.tls_enabled }}
  tls:
    - hosts:
        - {{ .Values.routing.host }}
      secretName: {{ .Values.routing.tls_secretName }}
  {{- end }}
  rules:
    - host: {{ .Values.routing.host }}
      http:
        paths:
          - path: /{{ .Values.routing.path }}
            backend:
              serviceName: service-{{ .Values.app.name }}-{{ .Values.app.CustomerName }}
              servicePort: {{ .Values.service.port }}
{{- end }}

My Values.yaml文件如下:

  enabled: yes
  # Note: For OpenShift change the type to route
  type: ingress
  annotations: |-
    nginx.ingress.kubernetes.io/affinity: "cookie"
    nginx.ingress.kubernetes.io/session-cookie-name: "route"
    nginx.ingress.kubernetes.io/session-cookie-expires: "172800"
    nginx.ingress.kubernetes.io/session-cookie-max-age: "172800"
  # Recommendation: Set the host to {model type}-{container version}.{rest of the DNS name}
  # Note: You must update the hostname in the relevant DNS service to match the value set for the host variable
  host: localhost
  path:
  tls_enabled: no
  # For OpenShift the value of the tls_secretName variable is ignored because TLS is handled differently
  tls_secretName: chart-example.voicelab.local

[当我想测试头盔如何生成yaml文件时,我运行命令:

helm template .

然后生成带有以下内容的种类对象:

# Source: rcm/templates/ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: "bla"
  annotations:
        |-
      nginx.ingress.kubernetes.io/affinity: "cookie"
      nginx.ingress.kubernetes.io/session-cookie-name: "route"
      nginx.ingress.kubernetes.io/session-cookie-expires: "172800"
      nginx.ingress.kubernetes.io/session-cookie-max-age: "172800"

  labels:
....

如何删除'|-'?为什么生成它?

kubernetes-helm helmfile
1个回答
0
投票

只需删除|-。没有它应该可以工作。

此外,如果您在values.yaml中执行类似的操作,那么>

routing:
  annotations:
    nginx.ingress.kubernetes.io/affinity: "cookie"
    nginx.ingress.kubernetes.io/session-cookie-name: "route"
    nginx.ingress.kubernetes.io/session-cookie-expires: "172800"
    nginx.ingress.kubernetes.io/session-cookie-max-age: "172800"

那么您可以指的是地图

  annotations:
    {{- range $key, $value := .Values.routing.annotations }}
    {{ $key }}: {{ $value | quote }}
    {{- end }}
© www.soinside.com 2019 - 2024. All rights reserved.