【问题标题】:Multiline helm values to yaml generation issues多行 helm 值到 yaml 生成问题
【发布时间】:2019-10-07 11:35:23
【问题描述】:

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

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 }}

我的 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

当我想测试 helm 如何生成 yaml 文件时,我运行以下命令:

helm template .

然后它生成 kind 对象:

# 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】:

    你可以在你的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"
    

    那么你可以参考is as to map

      annotations:
        {{- range $key, $value := .Values.routing.annotations }}
        {{ $key }}: {{ $value | quote }}
        {{- end }}
    

    【讨论】:

    • 如果我删除了 |- 它在第一行之后的行有错误的缩进。似乎它无法识别它是一个列表。
    • 您的其他建议效果很好:) 如果您修复删除建议,我会批准您的回答。因为它在第一部分对我不起作用。
    猜你喜欢
    • 1970-01-01
    • 2011-08-19
    • 2022-06-22
    • 1970-01-01
    • 1970-01-01
    • 2021-12-07
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    相关资源
    最近更新 更多