apiVersion: v1
kind: Service
metadata:
  name: {{template "jenkins.fullname" . }}
  labels:
    app: {{ template "jenkins.fullname" . }}
    heritage: {{.Release.Service | quote }}
    release: {{.Release.Name | quote }}
    chart: "{{.Chart.Name}}-{{.Chart.Version}}"
    component: "{{.Release.Name}}-{{.Values.Master.Component}}"
{{- if .Values.Master.ServiceAnnotations }}
  annotations:
{{ toYaml .Values.Master.ServiceAnnotations | indent 4 }}
{{- end }}
spec:
  ports:
    - port: {{.Values.Master.ServicePort}}
      name: http
      targetPort: 8080
      {{if (and (eq .Values.Master.ServiceType "NodePort") (not (empty .Values.Master.NodePort)))}}
      nodePort: {{.Values.Master.NodePort}}
      {{end}}
  selector:
    component: "{{.Release.Name}}-{{.Values.Master.Component}}"
  type: {{.Values.Master.ServiceType}}
  {{if eq .Values.Master.ServiceType "LoadBalancer"}}
{{- if .Values.Master.LoadBalancerSourceRanges }}
  loadBalancerSourceRanges:
{{ toYaml .Values.Master.LoadBalancerSourceRanges | indent 4 }}
{{- end }}
  {{if .Values.Master.LoadBalancerIP}}
  loadBalancerIP: {{.Values.Master.LoadBalancerIP}}
  {{end}}
  {{end}}
