apiVersion: v1
kind: Service
metadata:
  name: {{ include "nifi.fullname" . }}-http
  labels:
    {{- include "nifi.labels" . | nindent 4 }}
spec:
  type: ClusterIP
  ports:
    - port: {{ .Values.ports.https }}
      targetPort: https
      protocol: TCP
      name: https
    - port: {{ .Values.ports.remoteinput }}
      targetPort: remoteinput
      protocol: TCP
      name: remoteinput
    {{- /* Only include extra ports that don't have a nodePort specified. For those that do, include them in a separate Service */}}
    {{- range $name, $port := .Values.extraPorts }}
    {{- if not (and $port.nodePort $port.loadBalancerPort) }}
    - name: {{ $name }}
      port: {{ $port.containerPort }}
      targetPort: {{ $port.containerPort }}
      protocol: {{ $port.protocol | default "TCP" }}
    {{- end }}
    {{- end }}
  selector:
    {{- include "nifi.selectorLabels" . | nindent 4 }}
{{- if eq (include "nifi.hasExternalPorts" . ) "true" }}
---
apiVersion: v1
kind: Service
metadata:
  name: {{ include "nifi.fullname" . }}-external
  labels:
    {{- include "nifi.labels" . | nindent 4 }}
  {{- with .Values.service.external.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  type: {{ .Values.service.external.type }}
  externalTrafficPolicy: {{ .Values.service.external.externalTrafficPolicy }}
  ports:
    {{- range $name, $port := .Values.extraPorts }}
    {{- if or $port.nodePort $port.loadBalancerPort }}
    - name: {{ $name }}
      targetPort: {{ $port.containerPort }}
      protocol: {{ $port.protocol | default "TCP" }}
      {{- if $port.nodePort }}
      nodePort: {{ $port.nodePort }}
      {{- end }}
      {{- if $port.loadBalancerPort }}
      port: {{ $port.loadBalancerPort}}
      {{- else }}
      port: {{ $port.containerPort }}
      {{- end }}
    {{- end }}
    {{- end }}
  selector:
    {{- include "nifi.selectorLabels" . | nindent 4 }}
{{- end }}
{{- range $i, $e := until (int .Values.global.nifi.nodeCount) }}
---
apiVersion: v1
kind: Service
metadata:
  name: {{ include "nifi.fullname" $ }}-{{ $i }}
  labels:
    {{- include "nifi.labels" $ | nindent 4 }}
spec:
  type: ClusterIP
  clusterIP: None
  ports:
    - port: {{ $.Values.ports.https }}
      targetPort: https
      protocol: TCP
      name: https
    - port: {{ $.Values.ports.metrics }}
      targetPort: metrics
      protocol: TCP
      name: metrics
  selector:
    statefulset.kubernetes.io/pod-name: {{ include "nifi.fullname" $ }}-{{ $i }}
    {{- include "nifi.selectorLabels" $ | nindent 4 }}
{{- end }}