{{- $chart := include "chart" . }}
{{- $name := include "name" . -}}

{{- range $service, $val := $.Values.services }}
{{- if and .ingress (not .disabled) }}
{{- $serviceName := printf "%s-%s" $name $service -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ $serviceName }}
  namespace: {{ $.Values.namespace }}
  labels:
    app.kubernetes.io/name: {{ $serviceName }}
    app.kubernetes.io/component: {{ $service }}
    helm.sh/chart: {{ $chart }}
    app.kubernetes.io/instance: {{ $.Release.Name }}
    app.kubernetes.io/managed-by: {{ $.Release.Service }}
    app.kubernetes.io/version: {{ $.Values.version | quote }}
    {{- if .labels}}
    {{- toYaml .labels | nindent 4 }}
    {{- end }}
  {{- if $.Values.ingress.annotations }}
  {{- with $.Values.ingress.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
  {{- end }}
spec:
  tls:
  {{- range .ingress.tls }}
    - hosts:
      {{- range .hosts }}
        - {{ . | quote }}
      {{- end }}
      secretName: {{ .secretName }}
  {{- end }}
  rules:
    - host: {{ .ingress.host}}
      http:
        paths:
          {{- range .ingress.paths }}
          - path: {{ . }}
            pathType: Prefix
            backend:
              service:
                name: {{ $serviceName }}
                port:
                  number: {{ $val.service.port }}
          {{- end }}
---
{{- end }}
{{- end }}
