{{- if and .Values.attu.enabled .Values.attu.ingress.enabled }}
{{- $attuServiceName := include "milvus.attu.fullname" . -}}
{{- $attuServicePort := .Values.attu.service.port -}}

{{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1/Ingress" }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ template "milvus.attu.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
{{ include "milvus.labels" . | indent 4 }}
{{- if .Values.attu.ingress.labels }}
{{ toYaml .Values.attu.ingress.labels | indent 4 }}
{{- end }}
{{- with .Values.attu.ingress.annotations }}
  annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
{{- if .Values.attu.ingress.ingressClassName }}
  ingressClassName: {{ .Values.attu.ingress.ingressClassName }}
{{- end }}
{{- if .Values.attu.ingress.tls }}
  tls:
  {{- range .Values.attu.ingress.tls }}
    - hosts:
      {{- range .hosts }}
        - {{ . | quote }}
      {{- end }}
      secretName: {{ .secretName }}
  {{- end }}
  defaultBackend:
    service:
      name: {{ $attuServiceName }}
      port: 
        number: {{ $attuServicePort }}
{{- end }}
  
{{- if .Values.attu.ingress.hosts }}
  rules:
  {{- range $host := .Values.attu.ingress.hosts }}
  - host: {{ $host }}
    http:
      paths:
        - path: /
          pathType: Prefix
          backend:
            service:
              name: {{ $attuServiceName }}
              port: 
                number: {{ $attuServicePort }}
{{- end }}

{{- end }}


{{- else }}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ template "milvus.attu.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
{{ include "milvus.labels" . | indent 4 }}
{{- if .Values.attu.ingress.labels }}
{{ toYaml .Values.attu.ingress.labels | indent 4 }}
{{- end }}
{{- with .Values.attu.ingress.annotations }}
  annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
{{- if .Values.attu.ingress.tls }}
  tls:
  {{- range .Values.attu.ingress.tls }}
    - hosts:
      {{- range .hosts }}
        - {{ . | quote }}
      {{- end }}
      secretName: {{ .secretName }}
  {{- end }}
  backend:
    serviceName: {{ $attuServiceName }}
    servicePort: {{ $attuServicePort }}
{{- end }}
{{- if .Values.attu.ingress.hosts }}
  rules:
  {{- range $host := .Values.attu.ingress.hosts }}
  - host: {{ $host }}
    http:
      paths:
        - path: /
          pathType: Prefix
          backend:
            serviceName: {{ $attuServiceName }}
            servicePort: {{ $attuServicePort }}
  {{- end }}
{{- end }}
{{- end }}
{{- end }}