{{- if and .Values.meshGateway.enabled .Values.meshGateway.service.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: {{ template "consul.fullname" . }}-mesh-gateway
  namespace: {{ .Release.Namespace }}
  labels:
    app: {{ template "consul.name" . }}
    chart: {{ template "consul.chart" . }}
    heritage: {{ .Release.Service }}
    release: {{ .Release.Name }}
    component: mesh-gateway
  {{- if .Values.meshGateway.service.annotations }}
  annotations:
    {{ tpl .Values.meshGateway.service.annotations . | nindent 4 | trim }}
  {{- end }}
spec:
  selector:
    app: {{ template "consul.name" . }}
    release: "{{ .Release.Name }}"
    component: mesh-gateway
  ports:
    - name: gateway
      port: {{ .Values.meshGateway.service.port }}
      targetPort: {{ .Values.meshGateway.containerPort }}
      {{- if .Values.meshGateway.service.nodePort }}
      nodePort: {{ .Values.meshGateway.service.nodePort }}
      {{- end}}
  type: {{ .Values.meshGateway.service.type }}
  {{- if .Values.meshGateway.service.additionalSpec }}
  {{ tpl .Values.meshGateway.service.additionalSpec . | nindent 2 | trim }}
  {{- end }}
{{- end }}
