{{- if .Values.ingress.enabled -}}
{{- $fullName := include "nexus.fullname" . -}}
{{- $svcPort := .Values.nexus.nexusPort -}}
{{- $ingressPath := .Values.ingress.path -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ $fullName }}
  labels:
    {{- include "nexus.labels" . | nindent 4 }}
    {{- if .Values.nexus.extraLabels }}
      {{- with .Values.nexus.extraLabels }}
        {{ toYaml . | indent 4 }}
      {{- end }}
    {{- end }}
  {{- with .Values.ingress.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  {{- if .Values.ingress.ingressClassName }}
  ingressClassName: {{ .Values.ingress.ingressClassName }}
  {{- end }}
  {{- if .Values.ingress.tls }}
  tls:
    {{- range .Values.ingress.tls }}
    - hosts:
      {{- range .hosts }}
      - {{ . | quote }}
      {{- end }}
      secretName: {{ .secretName }}
    {{- end }}
  {{- end }}
  rules:
    - host: {{ .Values.ingress.hostRepo }}
      http:
        paths:
          - path: {{ .Values.ingress.hostPath }}
            pathType: Prefix
            backend:
              service:
                name: {{ $fullName }}
                port:
                  number: 8081

{{ if .Values.nexus.docker.enabled }}
{{ range $registry := .Values.nexus.docker.registries }}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ $fullName | trunc 49 }}-docker-{{ $registry.port }}
  labels:
    {{- include "nexus.labels" $ | nindent 4 }}
    {{- if $.Values.nexus.extraLabels }}
      {{- with $.Values.nexus.extraLabels }}
        {{ toYaml . | indent 4 }}
      {{- end }}
    {{- end }}
    {{- with $.Values.ingress.annotations }}
  annotations:
      {{- toYaml . | nindent 4 }}
    {{- end }}
spec:
  {{- if $.Values.ingress.ingressClassName }}
  ingressClassName: {{ $.Values.ingress.ingressClassName }}
  {{- end }}
  tls:
    - hosts:
      - {{ $registry.host | quote }}
      secretName: {{ $registry.secretName }}
  rules:
    - host: {{ $registry.host }}
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: {{ $fullName | trunc 49 }}-docker-{{ $registry.port }}
                port:
                  number: {{ $registry.port }}
{{- end }} {{- /* range of nexus.docker.registries */ -}}
{{- end }} {{- /* nexus.docker.enabled */ -}}
{{- end }} {{- /* ingress.enabled */ -}}
