{{- /* Filer ingress works for both normal mode (filer.enabled) and all-in-one mode (allInOne.enabled) */}}
{{- $filerEnabled := or .Values.filer.enabled .Values.allInOne.enabled }}
{{- if and $filerEnabled .Values.filer.ingress.enabled }}
{{- /* Determine service name based on deployment mode */}}
{{- $serviceName := ternary (include "seaweedfs.componentName" (list . "all-in-one")) (include "seaweedfs.componentName" (list . "filer")) .Values.allInOne.enabled }}
{{- 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: ingress-{{ include "seaweedfs.fullname" . }}-filer
  namespace: {{ .Release.Namespace }}
  {{- with .Values.filer.ingress.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
  labels:
    app.kubernetes.io/name: {{ template "seaweedfs.name" . }}
    helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/component: filer
spec:
  ingressClassName: {{ .Values.filer.ingress.className | quote }}
  tls:
    {{ .Values.filer.ingress.tls | default list | toYaml | nindent 6}}
  rules:
  - http:
      paths:
      - path: {{ .Values.filer.ingress.path | quote }}
        pathType: {{ .Values.filer.ingress.pathType | quote }}
        backend:
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion }}
          service:
            name: {{ $serviceName }}
            port:
              number: {{ .Values.filer.port }}
{{- else }}
          serviceName: {{ $serviceName }}
          servicePort: {{ .Values.filer.port }}
{{- end }}
{{- if .Values.filer.ingress.host }}
    host: {{ .Values.filer.ingress.host }}
{{- end }}
{{- end }}
