{{- if .Values.ingress.enabled -}}
{{- $fullName := include "vmpooler.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
  name: {{ $fullName }}
  labels:
    {{- include "vmpooler.labels" . | nindent 4 }}
  {{- with .Values.ingress.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  rules:
    - host: '{{ .Values.vmpoolerInstance }}.{{ .Values.ingress.domain }}'
      http:
        paths:
          - backend:
              {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
              service:
                name: {{ $fullName }}-api
                port:
                  number: {{ $svcPort }}
              {{- else }}
              serviceName: {{ $fullName }}-api
              servicePort: {{ $svcPort }}
              {{- end }}
            path: /
            {{- if semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion }}
            pathType: ImplementationSpecific
            {{- end }}
  {{ if .Values.ingress.useTLS -}}
  tls:
    - hosts:
        - '{{ .Values.vmpoolerInstance }}.{{ .Values.ingress.domain }}'
      secretName: '{{ .Values.vmpoolerInstance }}.{{ .Values.ingress.domain }}-tls'
  {{- end }}
{{- end }}
