{{- if and .Values.server.enabled .Values.server.ingress.enabled  }}
{{- $ingressApiIsStable := eq (include "victoria-logs.ingress.isStable" .) "true" -}}
{{- $ingressSupportsIngressClassName := eq (include "victoria-logs.ingress.supportsIngressClassName" .) "true" -}}
{{- $ingressSupportsPathType := eq (include "victoria-logs.ingress.supportsPathType" .) "true" -}}
{{- $servicePort := .Values.server.service.servicePort -}}
{{- $ingressPathType := .Values.server.ingress.pathType -}}
apiVersion: {{ include "victoria-logs.ingress.apiVersion" . }}
kind: Ingress
metadata:
{{- if .Values.server.ingress.annotations }}
  annotations:
{{ toYaml .Values.server.ingress.annotations | indent 4 }}
{{- end }}
  labels:
  {{- include "victoria-logs.server.labels" . | nindent 4 }}
  {{ if .Values.server.ingress.extraLabels }}
{{ toYaml .Values.server.ingress.extraLabels | indent 4 }}
  {{ end }}
  name: {{ template "victoria-logs.server.fullname" . }}
  namespace: {{ .Release.Namespace }}
spec:
  {{- if and $ingressSupportsIngressClassName .Values.server.ingress.ingressClassName }}
  ingressClassName: {{ .Values.server.ingress.ingressClassName }}
  {{- end }}
  rules:
  {{- $serviceName := include "victoria-logs.server.fullname" . }}
  {{- range .Values.server.ingress.hosts }}
  - host: {{ .name }}
    http:
      paths:
        - path: {{ .path }}
          {{- if $ingressSupportsPathType }}
          pathType: {{ $ingressPathType }}
          {{- end }}
          backend:
            {{- if $ingressApiIsStable }}
            service:
              name: {{ $serviceName }}
              port:
                number: {{ $servicePort }}
            {{- else }}
            serviceName: {{ $serviceName }}
            servicePort: {{ .port | default "http"}}
            {{- end }}
    {{- end -}}
{{- if .Values.server.ingress.tls }}
  tls:
{{ toYaml .Values.server.ingress.tls | indent 4 }}
{{- end -}}
{{- end -}}
