{{- if .Values.ingress.enabled }}
{{- if .Values.service.enabled }}
{{- $serviceName := include "apm-server.fullname" . -}}
{{- $servicePort := .Values.service.port -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  labels:
    app.kubernetes.io/name: {{ include "apm-server.name" . }}
    helm.sh/chart: {{ include "apm-server.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
  {{- range $key, $value := .Values.ingress.labels }}
    {{ $key }}: {{ $value | quote }}
  {{- end }}
  name: {{ template "apm-server.fullname" . }}
  {{- with .Values.ingress.annotations }}
  annotations:
    {{- range $key, $value := . }}
      {{ $key }}: {{ $value | quote }}
    {{- end }}
  {{- end }}
spec:
{{- if .Values.ingress.tls }}
  tls:
  {{- range .Values.ingress.tls }}
    - hosts:
      {{- range .hosts }}
        - {{ . | quote }}
      {{- end }}
      secretName: {{ .secretName }}
  {{- end }}
{{- end }}
  backend:
    serviceName: {{ $serviceName }}
    servicePort: {{ $servicePort }}
{{- if .Values.ingress.hosts }}
  rules:
  {{- range $host := .Values.ingress.hosts }}
  - host: {{ $host }}
    http:
      paths:
        - path: /
          backend:
            serviceName: {{ $serviceName }}
            servicePort: {{ $servicePort }}
  {{- end -}}
{{- end -}}
{{- end }}
{{- end }}
