{{- if (include "scdf.server.createConfigmap" .) }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "scdf.fullname" . }}-server
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    app.kubernetes.io/component: server
data:
  application.yaml: |-
    spring:
      cloud:
        dataflow:
          {{- if .Values.server.configuration.batchEnabled }}
          task:
            platform:
              kubernetes:
                accounts:
                  {{ .Values.server.configuration.accountName }}:
                    {{- if .Values.deployer.environmentVariables }}
                    environmentVariables: '{{ .Values.deployer.environmentVariables | trim }}'
                    {{- end }}
                    {{- if .Values.deployer.resources.limits }}
                    limits: {{- toYaml .Values.deployer.resources.limits | trim | nindent 22 }}
                    {{- end }}
                    {{- if .Values.deployer.resources.requests }}
                    requests: {{- toYaml .Values.deployer.resources.requests | trim | nindent 22 }}
                    {{- end }}
                    {{- if .Values.deployer.readinessProbe.initialDelaySeconds }}
                    readinessProbeDelay: {{ .Values.deployer.readinessProbe.initialDelaySeconds }}
                    {{- end }}
                    {{- if .Values.deployer.livenessProbe.initialDelaySeconds }}
                    livenessProbeDelay: {{ .Values.deployer.livenessProbe.initialDelaySeconds }}
                    {{- end }}
                    {{- if .Values.deployer.nodeSelector }}
                    nodeSelector: {{ .Values.deployer.nodeSelector }}
                    {{- end }}
                    {{- if .Values.deployer.tolerations }}
                    tolerations: {{- toYaml .Values.deployer.tolerations | nindent 22 }}
                    {{- end }}
                    {{- if .Values.deployer.volumeMounts }}
                    volumeMounts: {{- toYaml .Values.deployer.volumeMounts | nindent 22 }}
                    {{- end }}
                    {{- if .Values.deployer.volumes }}
                    volumes: {{- toYaml .Values.deployer.volumes | nindent 22 }}
                    {{- end }}
                    {{- if .Values.deployer.podSecurityContext }}
                    podSecurityContext: {{- toYaml .Values.deployer.podSecurityContext | nindent 22 }}
                    {{- end }}
          {{- end }}
          {{- if .Values.server.configuration.containerRegistries }}
          container:
            registry-configurations: {{- include "common.tplvalues.render" (dict "value" .Values.server.configuration.containerRegistries "context" $) | nindent 14 }}
          {{- end }}
          {{- if .Values.metrics.enabled }}
          {{- $fullname := include "scdf.fullname" . }}
          {{- $rsocketPort := int .Values.metrics.service.rsocketPort }}
          applicationProperties:
            {{- if .Values.server.configuration.streamingEnabled }}
            stream:
              management:
                metrics:
                  export:
                    prometheus:
                      enabled: true
                      rsocket:
                        enabled: true
                        host: {{ $fullname }}-prometheus-proxy
                        port: {{ $rsocketPort }}
            {{- end }}
            {{- if .Values.server.configuration.batchEnabled }}
            task:
              management:
                metrics:
                  export:
                    prometheus:
                      enabled: true
                      rsocket:
                        enabled: true
                        host: {{ $fullname }}-prometheus-proxy
                        port: {{ $rsocketPort }}
            {{- end }}
          {{- end }}
          {{- if .Values.server.configuration.grafanaInfo }}
          grafana-info:
            url: {{ .Values.server.configuration.grafanaInfo }}
          {{- end }}
      {{- $hibernateDialect := include "scdf.database.hibernate.dialect" .  }}
      {{- if $hibernateDialect }}
      jpa:
        properties:
          hibernate:
            dialect: {{ $hibernateDialect }}
      {{- end }}
      datasource:
        url: '{{ include "scdf.database.dataflow.url" . }}'
        driverClassName: {{ include "scdf.database.driver" . }}
        username: {{ include "scdf.database.server.user" . }}
        {{ if .Values.externalDatabase.existingPasswordSecret }}
        password: ${datasource-password}
        {{- else -}}
        password: ${mariadb-password}
        {{- end }}
        testOnBorrow: true
        validationQuery: "SELECT 1"
{{ end }}
