{{- if and (.Values.appdaemon.enabled) (.Values.appdaemon.ingress.enabled) }}
{{- $fullName := include "home-assistant.fullname" . -}}
{{- $servicePort := .Values.appdaemon.service.port -}}
{{- $ingressPath := .Values.appdaemon.ingress.path -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ $fullName }}-appdaemon
  labels:
    app.kubernetes.io/name: {{ include "home-assistant.name" . }}
    helm.sh/chart: {{ include "home-assistant.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- with .Values.appdaemon.ingress.annotations }}
  annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
{{- if .Values.appdaemon.ingress.tls }}
  tls:
  {{- range .Values.appdaemon.ingress.tls }}
    - hosts:
      {{- range .hosts }}
        - {{ . }}
      {{- end }}
      secretName: {{ .secretName }}
  {{- end }}
{{- end }}
  rules:
  {{- range .Values.appdaemon.ingress.hosts }}
    - host: {{ . }}
      http:
        paths:
          - path: {{ $ingressPath }}
            backend:
              serviceName: {{ $fullName }}
              servicePort: {{ $servicePort }}
  {{- end }}
{{- end }}
