{{- $root := . -}}
{{- range $ingress, $ingressValue := .Values.ingresses }}
{{- if $ingressValue.enabled }}
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ include "owrrm.fullname" $root }}-{{ $ingress }}
  labels:
    app.kubernetes.io/name: {{ include "owrrm.name" $root }}
    helm.sh/chart: {{ include "owrrm.chart" $root }}
    app.kubernetes.io/instance: {{ $root.Release.Name }}
    app.kubernetes.io/managed-by: {{ $root.Release.Service }}
  {{- with $ingressValue.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}

spec:

{{- if $ingressValue.tls }}
  tls:
  {{- range $ingressValue.tls }}
    - hosts:
      {{- range .hosts }}
        - {{ . | quote }}
      {{- end }}
      secretName: {{ tpl .secretName $root }}
  {{- end }}
{{- end }}

  rules:
  {{- range $ingressValue.hosts }}
  - host: {{ . | quote }}
    http:
      paths:
      {{- range $ingressValue.paths }}
        - path: {{ .path }}
          backend:
            serviceName: {{ include "owrrm.fullname" $root }}-{{ .serviceName }}
            servicePort: {{ .servicePort }}
      {{- end }}
  {{- end }}

{{- end }}

{{- end }}
