{{- if and .Values.webui.enabled .Values.webui.ingress.enabled -}}
{{- $fullName := include "falcosidekick.fullname" . -}}
{{- $ingressApiIsStable := eq (include "falcosidekick.ingress.isStable" .) "true" -}}
{{- $ingressSupportsPathType := eq (include "falcosidekick.ingress.supportsPathType" .) "true" -}}
---
apiVersion: {{ include "falcosidekick.ingress.apiVersion" . }}
kind: Ingress
metadata:
  name: {{ $fullName }}-ui
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "falcosidekick.labels" . | nindent 4 }}
    app.kubernetes.io/component: ui
  {{- with .Values.webui.ingress.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
{{- if .Values.webui.ingress.ingressClassName }}
  ingressClassName: {{ .Values.webui.ingress.ingressClassName }}
{{- end }}
{{- if .Values.webui.ingress.tls }}
  tls:
  {{- range .Values.webui.ingress.tls }}
    - hosts:
      {{- range .hosts }}
        - {{ . | quote }}
      {{- end }}
      secretName: {{ .secretName }}
  {{- end }}
{{- end }}
  rules:
  {{- range .Values.webui.ingress.hosts }}
    - host: {{ .host | quote }}
      http:
        paths:
        {{- range .paths }}
        - path: {{ .path }}
          {{- if $ingressSupportsPathType }}
          pathType: {{ default "ImplementationSpecific" .pathType }}
          {{- end }}
          backend:
            {{- if $ingressApiIsStable }}
            service:
              name: {{ $fullName }}-ui
              port:
                name: http
            {{- else }}
            serviceName: {{ $fullName }}-ui
            servicePort: http
            {{- end }}
        {{- end }}
  {{- end }}
{{- end }}
