{{- if .Values.service.enabled -}}
---
apiVersion: v1
kind: Service
metadata:
  name: {{ include "nexus.fullname" . }}
{{- if .Values.service.annotations }}
  annotations:
{{ toYaml .Values.service.annotations | indent 4 }}
{{- end }}
  labels:
    {{- include "nexus.labels" . | nindent 4 }}
    {{- if .Values.nexus.extraLabels }}
      {{- with .Values.nexus.extraLabels }}
        {{ toYaml . | indent 4 }}
      {{- end }}
    {{- end }}
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.nexus.nexusPort }}
      protocol: TCP
      name: nexus-ui
      {{- if eq .Values.service.type "NodePort" }}
      nodePort: {{ .Values.service.nodePort }}
      {{- end }}
  selector:
    {{- include "nexus.selectorLabels" . | nindent 4 }}
    {{- if .Values.nexus.extraSelectorLabels }}
      {{- with .Values.nexus.extraSelectorLabels }}
        {{ toYaml . | indent 4 }}
      {{- end }}
    {{- end }}

{{- if .Values.nexus.docker.enabled }}
{{- range $registry := .Values.nexus.docker.registries }}
---
apiVersion: v1
kind: Service
metadata:
  name: {{ include "nexus.fullname" $ | trunc 49 }}-docker-{{ $registry.port }}
{{- if $.Values.service.annotations }}
  annotations:
{{ toYaml $.Values.service.annotations | indent 4 }}
{{- end }}
  labels:
    {{- include "nexus.labels" $ | nindent 4 }}
    {{- if $.Values.nexus.extraLabels }}
      {{- with $.Values.nexus.extraLabels }}
        {{ toYaml . | indent 4 }}
      {{- end }}
    {{- end }}
spec:
  type: {{ $.Values.service.type }}
  ports:
    - port: {{ $registry.port }}
      protocol: TCP
      name: docker-{{ $registry.port }}
  selector:
    {{- include "nexus.selectorLabels" $ | nindent 4 }}
    {{- if $.Values.nexus.extraSelectorLabels }}
      {{- with $.Values.nexus.extraSelectorLabels }}
        {{ toYaml . | indent 4 }}
      {{- end }}
    {{- end }}
{{- end }}

{{- end }}
{{- end }}
