apiVersion: v1
kind: Service
metadata:
  name: {{ include "ambassador.fullname" . }}
  labels:
    app.kubernetes.io/name: {{ include "ambassador.name" . }}
    helm.sh/chart: {{ include "ambassador.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
  {{- with .Values.service.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  type: {{ .Values.service.type }}
  {{- if .Values.service.loadBalancerIP }}
  loadBalancerIP: "{{ .Values.service.loadBalancerIP }}"
  {{- end }}
  {{- if .Values.service.externalTrafficPolicy }}
  externalTrafficPolicy: "{{ .Values.service.externalTrafficPolicy }}"
  {{- end }}
  type: {{ .Values.service.type }}
  ports:
    {{- if .Values.service.http.enabled }}
    - port: {{ .Values.service.http.port }}
      targetPort: {{ .Values.service.http.targetPort }}
      protocol: TCP
      name: http
      {{- with .Values.service.http.nodePort }}
      nodePort: {{ toYaml . }}
      {{- end }}
    {{- end }}
    {{- if .Values.service.https.enabled }}
    - port: {{ .Values.service.https.port }}
      targetPort: {{ .Values.service.https.targetPort }}
      protocol: TCP
      name: https
      {{- with .Values.service.https.nodePort }}
      nodePort: {{ toYaml . }}
      {{- end }}
    {{- end }}
  selector:
    app.kubernetes.io/name: {{ include "ambassador.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
  {{- with .Values.service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges:
    {{- toYaml . | nindent 4 }}
  {{- end }}
