{{- if and .Values.admin.enabled .Values.admin.ingress.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" . }}-admin
  namespace: {{ .Release.Namespace }}
  annotations:
  {{- if and (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) .Values.admin.ingress.className }}
    kubernetes.io/ingress.class: {{ .Values.admin.ingress.className }}
  {{- end }}
  {{- with .Values.admin.ingress.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: admin
spec:
  {{- if and (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) .Values.admin.ingress.className }}
  ingressClassName: {{ .Values.admin.ingress.className | quote }}
  {{- end }}
  tls:
    {{ .Values.admin.ingress.tls | default list | toYaml | nindent 6}}
  rules:
  - {{- if .Values.admin.ingress.host }}
    host: {{ .Values.admin.ingress.host | quote }}
    {{- end }}
    http:
      paths:
      - path: {{ .Values.admin.ingress.path | quote }}
        {{- if semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion }}
        pathType: {{ .Values.admin.ingress.pathType | quote }}
        {{- end }}
        backend:
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion }}
          service:
            name: {{ include "seaweedfs.componentName" (list . "admin") }}
            port:
              number: {{ .Values.admin.port }}
{{- else }}
          serviceName: {{ include "seaweedfs.componentName" (list . "admin") }}
          servicePort: {{ .Values.admin.port }}
{{- end }}
{{- end }}
