{{- range $key, $spec := .Values }}
{{- if and (ne $key "global") (ne $key "enabled") }}
{{- if $spec.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: {{ $key }}
  namespace: {{ $spec.namespace | default $.Release.Namespace }}
  annotations:
    {{- range $key, $val := $spec.serviceAnnotations }}
    {{ $key }}: {{ $val | quote }}
    {{- end }}
  labels:
    chart: {{ $.Chart.Name }}-{{ $.Chart.Version | replace "+" "_" }}
    release: {{ $.Release.Name }}
    heritage: {{ $.Release.Service }}
    {{- range $key, $val := $spec.labels }}
    {{ $key }}: {{ $val }}
    {{- end }}
spec:
{{- if $spec.loadBalancerIP }}
  loadBalancerIP: "{{ $spec.loadBalancerIP }}"
{{- end }}
{{- if $spec.loadBalancerSourceRanges }}
  loadBalancerSourceRanges:
{{ toYaml $spec.loadBalancerSourceRanges | indent 4 }}
{{- end }}
  type: {{ .type }}
  selector:
    {{- range $key, $val := $spec.labels }}
    {{ $key }}: {{ $val }}
    {{- end }}
  ports:
    {{- range $key, $val := $spec.ports }}
    -
      {{- range $pkey, $pval := $val }}
      {{ $pkey}}: {{ $pval }}
      {{- end }}
    {{- end }}
---
{{- end }}
{{- end }}
{{- end }}
