{{- $namespace := .Release.Namespace -}}
{{- $scope := $ -}}
{{- range .Values.application.manifest }}
{{- if .enabled -}}
{{- $applicationName := .name | trunc 63 }}
---
apiVersion: v1
kind: Service
metadata:
  name: {{ $applicationName }}
  namespace: {{ $namespace }}
  labels:
    cmii.type: {{ $.Values.application.type }}
    {{- if .modules  }}
    cmii.modules: {{ .modules }}
    {{- end }}
    cmii.app: {{ $applicationName }}
    helm.sh/chart: {{ include "uavcloud-be-core.chart" $scope }}
    app.kubernetes.io/managed-by: {{ $.Release.Service }}
    {{- if $.Chart.AppVersion }}
    app.kubernetes.io/version: {{ $.Chart.AppVersion | quote }}
    {{- end }}
    app.kubernetes.io/app-version: {{ $.Values.global.image.tag | quote }}
spec:
  type: {{ $.Values.global.appServiceType.backend }}
  selector:
    cmii.type: {{ $.Values.application.type }}
    cmii.app: {{ $applicationName }}
  ports:
    - name: backend-tcp
      port: 8080
      protocol: TCP
      targetPort: 8080
---
{{- end }}
{{- end }}
