{{- if .Values.ingress.enabled }}
---
apiVersion: {{ include "nextcloud.ingress.apiVersion" . }}
kind: Ingress
metadata:
  name: {{ template "nextcloud.fullname" . }}
  labels:
    {{- include "nextcloud.labels"  ( dict "component" "app"  "rootContext" $ ) | nindent 4 }}
    {{- with .Values.ingress.labels }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
  {{- with .Values.ingress.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  {{- with .Values.ingress.className }}
  ingressClassName: {{ . }}
  {{- end }}
  rules:
    - host: {{ .Values.nextcloud.host }}
      http:
        paths:
          - path: {{ .Values.ingress.path }}
            {{- if (eq (include "nextcloud.ingress.apiVersion" $) "networking.k8s.io/v1") }}
            pathType: {{ .Values.ingress.pathType }}
            {{- end }}
            backend:
              {{- if (eq (include "nextcloud.ingress.apiVersion" $) "networking.k8s.io/v1") }}
              service:
                name: {{ template "nextcloud.fullname" . }}
                port:
                  number: {{ .Values.service.port }}
              {{- else }}
              serviceName: {{ template "nextcloud.fullname" . }}
              servicePort: {{ .Values.service.port }}
              {{- end }}
  {{- with .Values.ingress.tls }}
  tls:
    {{- toYaml . | nindent 4 }}
  {{- end }}
{{- end }}
