{{- if gt (int .Values.server.workers) 0 }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "presto.worker" . }}
  labels:
    app: {{ template "presto.name" . }}
    chart: {{ template "presto.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
    component: worker
data:
  node.properties: |
    node.environment={{ .Values.server.node.environment }}
    node.data-dir={{ .Values.server.node.dataDir }}
    plugin.dir={{ .Values.server.node.pluginDir }}

  jvm.config: |
    -server
    -Xmx{{ .Values.server.jvm.maxHeapSize }}
    -XX:+{{ .Values.server.jvm.gcMethod.type }}
    -XX:G1HeapRegionSize={{ .Values.server.jvm.gcMethod.g1.heapRegionSize }}
    -XX:+UseGCOverheadLimit
    -XX:+ExplicitGCInvokesConcurrent
    -XX:+HeapDumpOnOutOfMemoryError
    -XX:+ExitOnOutOfMemoryError
    -Djdk.attach.allowAttachSelf=true

  config.properties: |
    coordinator=false
    http-server.http.port={{ .Values.server.config.http.port }}
    query.max-memory={{ .Values.server.config.query.maxMemory }}
    query.max-memory-per-node={{ .Values.server.config.query.maxMemoryPerNode }}
    discovery.uri=http://{{ template "presto.fullname" . }}:{{ .Values.server.config.http.port }}

  log.properties: |
    io.prestosql={{ .Values.server.log.presto.level }}

  health_check.sh: |
    #!/bin/bash 
    curl --silent {{ template "presto.fullname" . }}:{{ .Values.server.config.http.port }}/v1/node | tr "," "\n" | grep --silent $(hostname -i)

---
{{- end }}