apiVersion: v1
kind: Service
metadata:
  name: {{ template "concourse.web.fullname" . }}
  labels:
    app: {{ template "concourse.web.fullname" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
  annotations:
    {{- range $key, $value := .Values.web.service.annotations }}
    {{ $key }}: {{ $value | quote }}
    {{- end }}
    {{- if .Values.web.metrics.prometheus.enabled }}
    prometheus.io/scrape: "true"
    prometheus.io/port: {{ .Values.web.metrics.prometheus.port | quote }}
    {{- end }}
spec:
  type: {{ .Values.web.service.type }}
  {{ if .Values.web.service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges:
    {{- range .Values.web.service.loadBalancerSourceRanges }}
    - {{ . }}
    {{- end }}
  {{ end }}
  {{ if and (eq "LoadBalancer" .Values.web.service.type) .Values.web.service.loadBalancerIP }}
  loadBalancerIP: {{ .Values.web.service.loadBalancerIP }}
  {{ end }}
  ports:
    - name: atc
      port: {{ .Values.concourse.atcPort }}
      targetPort: atc
      {{ if and (eq "NodePort" .Values.web.service.type) .Values.web.service.atcNodePort }}
      nodePort: {{ .Values.web.service.atcNodePort}}
      {{ end }}
    - name: tsa
      port: {{ .Values.concourse.tsaPort }}
      targetPort: tsa
      {{ if and (eq "NodePort" .Values.web.service.type) .Values.web.service.tsaNodePort }}
      nodePort: {{ .Values.web.service.tsaNodePort}}
      {{ end }}
    {{- if .Values.web.metrics.prometheus.enabled }}
    - name: prometheus
      port: {{ .Values.web.metrics.prometheus.port }}
      targetPort: prometheus
    {{- end }}
  selector:
    app: {{ template "concourse.web.fullname" . }}
