{{ if .Values.ingress.enabled }}
{{- $ingress := .Values.ingress }}
{{- if and $ingress.ingressClassName (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
  {{- if not (hasKey $ingress.annotations "kubernetes.io/ingress.class") }}
  {{- $_ := set $ingress.annotations "kubernetes.io/ingress.class" $ingress.ingressClassName}}
  {{- end }}
{{- end }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: infisical-ingress
  {{- with $ingress.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  {{- if and $ingress.ingressClassName (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
  ingressClassName: {{ $ingress.ingressClassName | default "nginx" }}
  {{- end }}
{{- if $ingress.tls }}
  tls:
  {{- range $ingress.tls }}
    - hosts:
      {{- range .hosts }}
        - {{ . | quote }}
      {{- end }}
      secretName: {{ .secretName }}
  {{- end }}
{{- end }}
  rules:
    - http:
        paths:
        - path: {{ $ingress.frontend.path }}
          pathType: {{ $ingress.frontend.pathType }}
          backend:
            service:
              name: {{ include "infisical.frontend.fullname" . }}
              port:
                number: 3000
        - path: {{ $ingress.backend.path }}
          pathType: {{ $ingress.backend.pathType }}
          backend:
            service:
              name: {{ include "infisical.backend.fullname" . }}
              port:
                number: 4000
      {{- if $ingress.hostName }}
      host: {{ $ingress.hostName }}
      {{- end }}
{{ end }}