{{- if .Values.ingress.enabled -}}
{{- $architecture := .Values.architecture }}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ template "influxdb.fullname" . }}
  labels: {{- include "influxdb.labels" . | nindent 4 }}
  annotations:
    {{- if .Values.ingress.certManager }}
    kubernetes.io/tls-acme: "true"
    {{- end }}
    {{- range $key, $value := .Values.ingress.annotations }}
    {{ $key }}: {{ $value | quote }}
    {{- end }}
spec:
  rules:
  {{- range .Values.ingress.hosts }}
    - host: {{ .name }}
      http:
        paths:
          - path: /
            backend:
              serviceName: {{ include "influxdb.fullname" $ }}
              servicePort: http
          {{- if eq $architecture "high-availability" }}
          - path: /write
            backend:
              serviceName: {{ include "influxdb.fullname" $ }}-relay
              servicePort: http
          {{- end }}
  {{- end }}
  {{- if .Values.ingress.tls }}
  tls:
    {{- toYaml .Values.ingress.tls | nindent 4 }}
  {{- end }}
{{- end }}
