{{- define "seaweedfs.s3.iceberg.ingress.paths" -}}
paths:
- path: {{ .Values.s3.icebergIngress.path | quote }}
  pathType: {{ .Values.s3.icebergIngress.pathType | quote }}
  backend:
    {{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion }}
    service:
      name: {{ include "seaweedfs.componentName" (list . "s3") }}
      port:
        number: {{ .Values.s3.icebergPort }}
    {{- else }}
    serviceName: {{ include "seaweedfs.componentName" (list . "s3") }}
    servicePort: {{ .Values.s3.icebergPort }}
    {{- end }}
{{- end -}}
{{- if and .Values.s3.enabled .Values.s3.icebergPort .Values.s3.icebergIngress.enabled }}
{{- $hosts := list }}
{{- if kindIs "slice" .Values.s3.icebergIngress.host }}
  {{- $hosts = .Values.s3.icebergIngress.host }}
{{- else if .Values.s3.icebergIngress.host }}
  {{- $hosts = list .Values.s3.icebergIngress.host }}
{{- end }}
{{- 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" . }}-s3-iceberg
  namespace: {{ .Release.Namespace }}
  {{- with .Values.s3.icebergIngress.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: s3-iceberg
spec:
  {{- if .Values.s3.icebergIngress.className }}
  ingressClassName: {{ .Values.s3.icebergIngress.className | quote }}
  {{- end }}
  tls:
    {{ .Values.s3.icebergIngress.tls | default list | toYaml | nindent 6}}
  rules:
{{- if $hosts }}
{{- range $host := $hosts }}
  - host: {{ $host | quote }}
    http:
      {{- include "seaweedfs.s3.iceberg.ingress.paths" $ | nindent 6 }}
{{- end }}
{{- else }}
  - http:
      {{- include "seaweedfs.s3.iceberg.ingress.paths" . | nindent 4 }}
{{- end }}
{{- end }}
