github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/deploy/kafka/scripts/kafka-exporter-setup.sh.tpl (about) 1 #!/bin/bash 2 {{- $clusterName := $.cluster.metadata.name }} 3 {{- $namespace := $.cluster.metadata.namespace }} 4 {{- /* find kafka-server component */}} 5 {{- $component := fromJson "{}" }} 6 {{- range $i, $e := $.cluster.spec.componentSpecs }} 7 {{- if eq $e.componentDefRef "kafka-server" }} 8 {{- $component = $e }} 9 {{- end }} 10 {{- end }} 11 {{- if not $component }} 12 {{- /* find kafka-broker component */}} 13 {{- range $i, $e := $.cluster.spec.componentSpecs }} 14 {{- if eq $e.componentDefRef "kafka-broker" }} 15 {{- $component = $e }} 16 {{- end }} 17 {{- end }} 18 {{- end }} 19 {{- /* build --kafka.server= string */}} 20 {{- $replicas := $component.replicas | int }} 21 {{- $servers := "" }} 22 {{- range $i, $e := until $replicas }} 23 {{- $podFQDN := printf "%s-%s-%d.%s-%s-headless.%s.svc.%s" $clusterName $component.name $i $clusterName $component.name $namespace $.clusterDomain }} 24 {{- $server := printf "--kafka.server=%s:9092 \\\n" $podFQDN }} 25 {{- $servers = printf "%s\t%s" $servers $server }} 26 {{- end }} 27 {{ $servers = trimSuffix " \\\n" $servers}} 28 exec kafka_exporter --web.listen-address=:9308 \ 29 {{- if hasKey $component "tls" }} 30 {{- if $component.tls }} 31 --tls.enabled \ 32 {{- end }} 33 {{- end }} 34 {{ $servers }}