apiVersion: v1
kind: Service
metadata:
  name: {{ include "spark.master.service.name" . }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
  {{- if .Values.service.annotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.service.annotations "context" $) | nindent 4 }}
  {{- end }}
spec:
  type: {{ .Values.service.type }}
  {{- if and (eq .Values.service.type "LoadBalancer") (not (empty .Values.service.loadBalancerIP)) }}
  loadBalancerIP: {{ .Values.service.loadBalancerIP }}
  {{- end }}
  ports:
    - port: {{ .Values.service.clusterPort }}
      targetPort: cluster
      name: cluster
      {{- if and (or (eq .Values.service.type "NodePort") (eq .Values.service.type "LoadBalancer")) (not (empty .Values.service.nodePorts.cluster)) }}
      nodePort: {{ .Values.service.nodePorts.cluster }}
      {{- else if eq .Values.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
    - port: {{ .Values.service.webPort }}
      targetPort: http
      name: http
      protocol: TCP
      {{- if and (or (eq .Values.service.type "NodePort") (eq .Values.service.type "LoadBalancer")) (not (empty .Values.service.nodePorts.web)) }}
      nodePort: {{ .Values.service.nodePorts.web }}
      {{- else if eq .Values.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
  selector: {{- include "common.labels.matchLabels" . | nindent 4 }}
    app.kubernetes.io/component: master
