apiVersion: v1
kind: Service
metadata:
  name: {{ template "jenkins.fullname" . }}-agent
  namespace: {{ template "jenkins.namespace" . }}
  labels:
    "app.kubernetes.io/name": '{{ template "jenkins.name" .}}'
    "helm.sh/chart": "{{ .Chart.Name }}-{{ .Chart.Version }}"
    "app.kubernetes.io/managed-by": "{{ .Release.Service }}"
    "app.kubernetes.io/instance": "{{ .Release.Name }}"
    "app.kubernetes.io/component": "{{ .Values.master.componentName }}"
{{- if .Values.master.slaveListenerServiceAnnotations }}
  annotations:
{{ toYaml .Values.master.slaveListenerServiceAnnotations | indent 4 }}
{{- end }}
spec:
  ports:
    - port: {{ .Values.master.slaveListenerPort }}
      targetPort: {{ .Values.master.slaveListenerPort }}
      {{ if (and (eq .Values.master.slaveListenerServiceType "NodePort") (not (empty .Values.master.slaveListenerPort))) }}
      nodePort: {{.Values.master.slaveListenerPort}}
      {{end}}
      name: slavelistener
  selector:
    "app.kubernetes.io/component": "{{ .Values.master.componentName }}"
    "app.kubernetes.io/instance": "{{ .Release.Name }}"
  type: {{ .Values.master.slaveListenerServiceType }}
  {{  if eq .Values.master.slaveListenerServiceType "LoadBalancer"  }}
  {{  if .Values.master.slaveListenerLoadBalancerIP  }}
  loadBalancerIP: {{  .Values.master.slaveListenerLoadBalancerIP  }}
  {{end}}
  {{end}}
