# helm_charts_jenkins-master-svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: {{template "jenkins.fullname" . }}
  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.serviceLabels }}
{{ toYaml .Values.master.serviceLabels | indent 4 }}
    {{- end }}
{{- if .Values.master.serviceAnnotations }}
  annotations:
{{ toYaml .Values.master.serviceAnnotations | indent 4 }}
{{- end }}
spec:
  {{- if (and (eq .Values.master.serviceType "ClusterIP") (not (empty .Values.master.clusterIP))) }}
  clusterIP: {{.Values.master.clusterIP}}
  {{- end }}
  ports:
    - port: {{.Values.master.servicePort}}
      name: http
      targetPort: {{ .Values.master.targetPort }}
      {{- if (and (eq .Values.master.serviceType "NodePort") (not (empty .Values.master.nodePort))) }}
      nodePort: {{.Values.master.nodePort}}
      {{- end }}
{{- range $index, $port := .Values.master.extraPorts }}
    - port: {{ $port.port }}
      name: {{ $port.name }}
      targetPort: {{ $port.port }}
{{- end }}
  selector:
    "app.kubernetes.io/component": "{{ .Values.master.componentName }}"
    "app.kubernetes.io/instance": "{{ .Release.Name }}"
  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}}