# helm_charts_web-svc.yaml
{{- if .Values.web.enabled -}}
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 }}"
    {{- range $key, $value := .Values.web.service.labels }}
    {{ $key }}: {{ $value | quote }}
    {{- end }}
  {{- if or .Values.web.service.annotations .Values.concourse.web.prometheus.enabled }}
  annotations:
    {{- range $key, $value := .Values.web.service.annotations }}
    {{ $key }}: {{ $value | quote }}
    {{- end }}
    {{- if .Values.concourse.web.prometheus.enabled }}
    prometheus.io/scrape: "true"
    prometheus.io/port: {{ .Values.concourse.web.prometheus.bindPort | quote }}
    {{- end }}
  {{- 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.web.bindPort }}
      targetPort: atc
      {{ if and (eq "NodePort" .Values.web.service.type) .Values.web.service.atcNodePort }}
      nodePort: {{ .Values.web.service.atcNodePort}}
      {{ end }}
    {{- if .Values.concourse.web.tls.enabled }}
    - name: atc-tls
      port: {{ .Values.concourse.web.tls.bindPort }}
      targetPort: atc-tls
      {{ if and (eq "NodePort" .Values.web.service.type) .Values.web.service.atcTlsNodePort }}
      nodePort: {{ .Values.web.service.atcTlsNodePort}}
      {{ end }}
    {{- end }}
    - name: tsa
      port: {{ .Values.concourse.web.tsa.bindPort }}
      targetPort: tsa
      {{ if and (eq "NodePort" .Values.web.service.type) .Values.web.service.tsaNodePort }}
      nodePort: {{ .Values.web.service.tsaNodePort}}
      {{ end }}
    {{- if .Values.concourse.web.prometheus.enabled }}
    - name: prometheus
      port: {{ .Values.concourse.web.prometheus.bindPort }}
      targetPort: prometheus
    {{- end }}
  selector:
    app: {{ template "concourse.web.fullname" . }}
{{- end }}