{{ $namespace := .Release.Namespace }}
{{ $appVersion := .Chart.AppVersion | quote }}
{{ $releaseService := .Release.Service }}
{{ $releaseName := .Release.Name }}
{{- range $service := .Values.[[ .Name ]].services }}
---
apiVersion: v1
kind: Service
metadata:
  name: {{ $service.name }}
  namespace: {{ $namespace }}
  labels:
    app.kubernetes.io/version: {{ $appVersion }}
    app.kubernetes.io/name: {{ $service.name | quote }}
    app.kubernetes.io/managed-by: {{ $releaseService }}
    app.kubernetes.io/instance: {{ $releaseName }}
spec:
  ports:
    - port: {{ $service.port }}
      targetPort: {{ $service.targetPort }}
  selector:
    app.kubernetes.io/version: {{ $appVersion }}
    app.kubernetes.io/name: [[ .Name | quote ]]
    app.kubernetes.io/managed-by: {{ $releaseService }}
    app.kubernetes.io/instance: {{ $releaseName }}
{{- end }}