{{- if .Values.frontend.ingress.enabled -}}
{{- $gitVersion := .Capabilities.KubeVersion.GitVersion -}}
{{- $fullName := include "penpot.fullname" . -}}
{{- $svcPort := .Values.frontend.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 }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "penpot.labels" . | nindent 4 }}
  {{- with .Values.frontend.ingress.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
{{- if .Values.frontend.ingress.className }}
  ingressClassName: {{ .Values.frontend.ingress.className }} # TODO(giolekva): contribute back
{{- end }}
{{- if .Values.frontend.ingress.tls }}
  tls:
  {{- range .Values.frontend.ingress.tls }} # TODO(giolekva): contribute back
    - hosts:
      {{- range .hosts }}
        - {{ . | quote }}
      {{- end }}
      secretName: {{ .secretName }}
  {{- end }}
{{- end }}
  rules:
  {{- range .Values.frontend.ingress.hosts }}
    - host: {{ . | quote }} # TODO(giolekva): contribute back
      http:
        paths:
{{ if semverCompare ">=1.19-0" $gitVersion }}
          - path: /
            pathType: Prefix
            backend:
              service:
                name: {{ $fullName }}
                port:
                  number: {{ $svcPort }}
{{ else }}
          - path: /
            backend:
              serviceName: {{ $fullName }}
              servicePort: {{ $svcPort }}
{{- end }}
  {{- end }}
{{- end }}
