apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "datalore.fullname" . }}-agents-config
  labels:
    {{- include "datalore.labels" . | nindent 4 }}
data:
  agents-config.yaml: |-
{{- if .Values.agentsConfig }}
{{- tpl (toYaml .Values.agentsConfig) . | nindent 4 }}
{{- else }}
    k8s:
      namespace: {{ .Release.Namespace }}
      instances:
        - id: k8s-datalore-agent
          label: "K8s Local"
          description: "Local K8s instance"
          features:
            - "1 CPU cores"
            - "2 GB RAM"
          initialPoolSize: 1
          numCPUs: 1
          cpuMemoryText: "2 GB"
          numGPUs: 0
          gpuMemoryText: ""
          default: true
          yaml:
            apiVersion: v1
            kind: Pod
            metadata:
              name: k8s-agent
              labels:
                podType: dataloreKubernetesAgent
            spec:
              enableServiceLinks: false
              serviceAccountName: {{ .Values.agentsServiceAccountName }}
              containers:
                - name: agent
                  image: {{ .Values.agentImage.repository }}:{{ include "datalore.agentImage.version" . }}
                  imagePullPolicy: {{ .Values.agentImage.pullPolicy }}
                  securityContext:
                    privileged: true
                  env:
                    - name: MAX_HEAP_SIZE
                      value: 512m
                  {{- if .Values.logbackConfig }}
                  volumeMounts:
                    - mountPath: /etc/datalore/logback-config
                      name: logback-config
                  {{- end }}
                  resources:
                    limits:
                      cpu: "1"
                      memory: "2048Mi"
                    requests:
                      cpu: "200m"
                      memory: "2048Mi"
              {{- if .Values.logbackConfig }}
              volumes:
                - name: logback-config
                  configMap:
                    name: {{ include "datalore.fullname" . }}-logback-config
              {{- end }}
              {{- with .Values.agentsNodeSelector }}
              nodeSelector:
                {{- toYaml . | nindent 16 }}
              {{- end }}
              {{- with .Values.agentsAffinity }}
              affinity:
                {{- toYaml . | nindent 16 }}
              {{- end }}
              {{- with .Values.agentsTolerations }}
              tolerations:
                {{- toYaml . | nindent 16 }}
              {{- end }}
{{- end }}
