如何在 kubernetes 中的 ingress 模板中使用条件

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

我有以下 Values.yaml 文件

ingress: {backendServiceName: serv-swarm-lc001, cluster_issuer: letsencrypt-oe-dev-001,
  ingressClassName: nginx-lc001, tls_acme: 'true'}
route:
  hosts:
    abcM:
      active: false
      host: chair112.abc.com
      logicalclustername: lc001
      offboardtimestamp: null
      physicalclustername: oe-dev-001
      region: us-east-1
      status: Triggered
      timestamp: |-
        {
          "timestamp": "2024-02-05T14:43:18.00847359Z"
        }
    SDzWAgVebH:
      active: true
      host: bis311.abc.com
      logicalclustername: lc001
      offboardtimestamp: NA
      physicalclustername: oe-dev-001
      region: us-east-1
      status: triggered
      timestamp: |-
        {
          "timestamp": "2024-04-04T15:54:21.649644213Z"
        }

下面是入口的模板

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    cert-manager.io/cluster-issuer: {{ .Values.ingress.cluster_issuer }}
    kubernetes.io/tls-acme: {{ .Values.ingress.tls_acme | quote }}
    nginx.ingress.kubernetes.io/client-max-body-size: 16m
    nginx.ingress.kubernetes.io/proxy-body-size: 16m
  name: ingress-{{ .Release.Name }}
  namespace: {{ .Release.Namespace }}
  labels:
{{ include "common.labels" . | indent 4 }}
spec:
  ingressClassName: {{ .Values.ingress.ingressClassName }}
  rules:
  {{- range .Values.route.hosts }}
  - host: {{ - if .Values.route.hosts.host.active }} {{- end }}
    http:
      paths:
      - backend:
          service:
            name: {{ $.Values.ingress.backendServiceName }}
            port:
              number: 80
        path: /
        pathType: Prefix
      - backend:
          service:
            name: swaggerservice
            port:
              number: 80
        path: /swagger
        pathType: Prefix
  {{- end }}
  tls:
  {{- range .Values.route.hosts }}
  - hosts:
    - {{ .host | quote }}
    secretName: commodo-tls5
  {{- end }}

我们需要的是,我们只想处理/添加那些值为 true 的主机条目。如果为 false ,则不应将主机添加到 ingress 中。

在入口中添加了条件,第 17 行,但是,它不起作用。解析时出错。

请建议我们如何添加条件。

yaml kubernetes-helm helm3
© www.soinside.com 2019 - 2024. All rights reserved.