{{- $service := .Values.service }}
{{- $ctx := dict "helm" . }}
{{- $fullname := include "vm.plain.fullname" $ctx }}
{{- $ns := include "vm.namespace" $ctx }}
apiVersion: v1
kind: Service
metadata:
  namespace: {{ $ns }}
  {{- with $service.annotations }}
  annotations: {{ toYaml . | nindent 4 }}
  {{- end }}
  {{- $_ := set $ctx "extraLabels" .Values.extraLabels }}
  labels: {{ include "vm.labels" $ctx | nindent 4 }}
  {{- $_ := unset $ctx "extraLabels" }}
  name: {{ $fullname }}
spec:
  {{- with $service.clusterIP }}
  clusterIP: {{ . }}
  {{- end }}
  {{- with $service.externalIPs }}
  externalIPs: {{ toYaml . | nindent 4 }}
  {{- end }}
  {{- with $service.loadBalancerIP }}
  loadBalancerIP: {{ . }}
  {{- end }}
  {{- with $service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges: {{ toYaml . | nindent 4 }}
  {{- end }}
  type: {{ $service.type }}
  {{- with $service.healthCheckNodePort }}
  healthCheckNodePort: {{ . }}
  {{- end }}
  {{- with $service.externalTrafficPolicy }}
  externalTrafficPolicy: {{ . }}
  {{- end }}
  {{- with $service.ipFamilyPolicy }}
  ipFamilyPolicy: {{ . }}
  {{- end }}
  {{- with $service.ipFamilies }}
  ipFamilies: {{ toYaml . | nindent 4 }}
  {{- end }}
  ports:
    - name: http
      port: {{ $service.servicePort }}
      targetPort: http
      protocol: TCP
    - name: webhook
      port: {{ $service.webhookPort }}
      targetPort: webhook
  selector: {{ include "vm.selectorLabels" $ctx | nindent 4 }}
