{{- if .Values.ingress.enabled -}}
{{- $fullName := include "drone.fullname" . }}
{{- $httpPort := .Values.service.httpPort }}
apiVersion: {{ template "drone.ingress.apiVersion" . }}
kind: Ingress
metadata:
  annotations:
  {{- range $key, $value := .Values.ingress.annotations }}
    {{ $key }}: {{ $value | quote }}
  {{- end }}
  labels:
    app: {{ template "drone.name" . }}
    heritage: "{{ .Release.Service }}"
    release: "{{ .Release.Name }}"
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
  name: {{ template "drone.fullname" . }}
spec:
  rules:
  {{- range .Values.ingress.hosts }}
    - host: {{ . }}
      http:
        paths:
        {{- if $.Values.ingress.path }}
          - path: {{ $.Values.ingress.path }}
        {{- else if index $.Values.ingress "annotations" }}
          {{- if eq (index $.Values.ingress.annotations "kubernetes.io/ingress.class" | default "") "gce" "alb" "istio" }}
          - path: /*
          {{- else }}{{/* Has annotations but ingress class is not "gce" nor "alb" nor "istio" */}}
          - path: /
          {{- end }}
        {{- else }}{{/* Has no annotations */}}
          - path: /
        {{- end }}
            backend:
              serviceName: {{ $fullName }}
              servicePort: {{ $httpPort }}
  {{- end -}}
  {{- if .Values.ingress.tls }}
  tls:
{{ toYaml .Values.ingress.tls | indent 4 }}
  {{- end -}}
{{- end -}}
