{{- if not .Values.server.configMap }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "scdf.fullname" . }}-server
  labels:
    app: {{ template "scdf.name" . }}
    component: server
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
data:
  application.yaml: |-
    spring:
      {{- if .Values.features.batch.enabled }}
      cloud:
        dataflow:
          task:
            platform:
              kubernetes:
                accounts:
                  {{ .Values.server.platformName }}:
                    limits:
                      memory: {{ .Values.deployer.resourceLimits.memory }}
                      cpu: {{ .Values.deployer.resourceLimits.cpu }}
{{- if .Values.server.containerConfiguration }}
{{ toYaml .Values.server.containerConfiguration | indent 10 }}
{{- end }}
      {{- end }}
          {{- if .Values.features.monitoring.enabled }}
          applicationProperties:
          {{- if .Values.features.streaming.enabled }}
            stream:
              management:
                metrics:
                  export:
                    prometheus:
                      enabled: true
                      rsocket:
                        enabled: true
                        host: {{ printf "${%s_PROMETHEUS_PROXY_SERVICE_HOST}" (include "scdf.envrelease" . ) }}
                        port: {{ printf "${%s_PROMETHEUS_PROXY_SERVICE_PORT_RSOCKET}" (include "scdf.envrelease" . ) }}
            {{- end }}
            {{- if .Values.features.batch.enabled }}
            task:
              management:
                metrics:
                  export:
                    prometheus:
                      enabled: true
                      rsocket:
                        enabled: true
                        host: {{ printf "${%s_PROMETHEUS_PROXY_SERVICE_HOST}" (include "scdf.envrelease" . ) }}
                        port: {{ printf "${%s_PROMETHEUS_PROXY_SERVICE_PORT_RSOCKET}" (include "scdf.envrelease" . ) }}
            {{- end }}
          {{- end }}
          {{- if .Values.features.monitoring.enabled }}
          grafana-info:
            {{- if .Values.ingress.enabled }}
            url: {{ .Values.ingress.protocol }}://{{ .Values.ingress.grafana.host }}
            {{- else }}
            url: http://{{- printf "${%s_GRAFANA_SERVICE_HOST}" (include "scdf.envrelease" . ) -}}:{{- printf "${%s_GRAFANA_SERVICE_PORT}" (include "scdf.envrelease" . ) }}
            {{- end }}
          {{- end }}
      datasource:
        url: 'jdbc:{{ template "scdf.database.scheme" . }}://{{ template "scdf.database.host" . }}:{{ template "scdf.database.port" . }}/{{ template "scdf.database.dataflow" . }}'
        driverClassName: {{ template "scdf.database.driver" . }}
        username: {{ template "scdf.database.user" . }}
        password: {{ template "scdf.database.password" . }}
        testOnBorrow: true
        validationQuery: "SELECT 1"
{{- end }}
