{{- if .Values.clusters -}}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "kafka-manager.bootstrap.fullname" . }}
  labels:
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    app.kubernetes.io/name: {{ include "kafka-manager.name" . }}
    app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" | trunc 63 }}
    helm.sh/chart: {{ include "kafka-manager.chart" . }}
data:
  addClusters.sh: |
    #!/bin/bash
    set -e
    {{- range $cluster := .Values.clusters }}
    {{ printf "curl http://%s:9000/clusters -X POST -f " (include "kafka-manager.fullname" $) -}}
    {{- printf "-d name=%s " (default "default" $cluster.name) -}}
    {{- printf "-d zkHosts=%s " (default (include "kafka-manager.zkHosts" $) $cluster.zkHosts ) -}}
    {{- printf "-d kafkaVersion=%s " (default "1.0.0" $cluster.kafkaVersion) -}}
    {{- printf "-d jmxEnabled=%s " (default "false" $cluster.jmxEnabled) -}}
    {{- printf "-d jmxUser=%s " (default "" $cluster.jmxUser) -}}
    {{- printf "-d jmxPass=%s " (default "" $cluster.jmxPass) -}}
    {{- printf "-d jmxSsl=%s " (default "false" $cluster.jmxSsl) -}}
    {{- printf "-d logkafkaEnabled=%s " (default "false" $cluster.logkafkaEnabled) -}}
    {{- printf "-d pollConsumers=%s " (default "false" $cluster.pollConsumers) -}}
    {{- printf "-d filterConsumers=%s " (default "false" $cluster.filterConsumers) -}}
    {{- printf "-d activeOffsetCacheEnabled=%s " (default "false" $cluster.activeOffsetCacheEnabled) -}}
    {{- printf "-d displaySizeEnabled=%s " (default "false" $cluster.displaySizeEnabled) -}}
    {{- printf "-d tuning.brokerViewUpdatePeriodSeconds=%s " (default "30" $cluster.tuning.brokerViewUpdatePeriodSeconds) -}}
    {{- printf "-d tuning.clusterManagerThreadPoolSize=%s " (default "2" $cluster.tuning.clusterManagerThreadPoolSize) -}}
    {{- printf "-d tuning.clusterManagerThreadPoolQueueSize=%s " (default "100" $cluster.tuning.clusterManagerThreadPoolQueueSize) -}}
    {{- printf "-d tuning.kafkaCommandThreadPoolSize=%s " (default "2" $cluster.tuning.kafkaCommandThreadPoolSize) -}}
    {{- printf "-d tuning.kafkaCommandThreadPoolQueueSize=%s " (default "100" $cluster.tuning.kafkaCommandThreadPoolQueueSize) -}}
    {{- printf "-d tuning.logkafkaCommandThreadPoolSize=%s " (default "2" $cluster.tuning.logkafkaCommandThreadPoolSize) -}}
    {{- printf "-d tuning.logkafkaCommandThreadPoolQueueSize=%s " (default "100" $cluster.tuning.logkafkaCommandThreadPoolQueueSize) -}}
    {{- printf "-d tuning.logkafkaUpdatePeriodSeconds=%s " (default "30" $cluster.tuning.logkafkaUpdatePeriodSeconds) -}}
    {{- printf "-d tuning.partitionOffsetCacheTimeoutSecs=%s " (default "5" $cluster.tuning.partitionOffsetCacheTimeoutSecs) -}}
    {{- printf "-d tuning.brokerViewThreadPoolSize=%s " (default "4" $cluster.tuning.brokerViewThreadPoolSize) -}}
    {{- printf "-d tuning.brokerViewThreadPoolQueueSize=%s " (default "1000" $cluster.tuning.brokerViewThreadPoolQueueSize) -}}
    {{- printf "-d tuning.offsetCacheThreadPoolSize=%s " (default "4" $cluster.tuning.offsetCacheThreadPoolSize) -}}
    {{- printf "-d tuning.offsetCacheThreadPoolQueueSize=%s " (default "1000" $cluster.tuning.offsetCacheThreadPoolQueueSize) -}}
    {{- printf "-d tuning.kafkaAdminClientThreadPoolSize=%s " (default "4" $cluster.tuning.kafkaAdminClientThreadPoolSize) -}}
    {{- printf "-d tuning.kafkaAdminClientThreadPoolQueueSize=%s " (default "1000" $cluster.tuning.kafkaAdminClientThreadPoolQueueSize) -}}
    {{- printf "-d tuning.kafkaManagedOffsetMetadataCheckMillis=%s " (default "30000" $cluster.tuning.kafkaManagedOffsetMetadataCheckMillis) -}}
    {{- printf "-d tuning.kafkaManagedOffsetGroupCacheSize=%s " (default "1000000" $cluster.tuning.kafkaManagedOffsetGroupCacheSize) -}}
    {{- printf "-d tuning.kafkaManagedOffsetGroupExpireDays=%s " (default "7" $cluster.tuning.kafkaManagedOffsetGroupExpireDays) -}}
    {{- printf "-d securityProtocol=%s " (default "PLAINTEXT" $cluster.securityProtocol) -}}
    {{- printf "$( if $KAFKA_MANAGER_AUTH_ENABLED; then echo -u $KAFKA_MANAGER_USERNAME:$KAFKA_MANAGER_PASSWORD ; fi ) " -}}
    {{- end -}}
{{- end -}}
