Skip to content

Commit

Permalink
prometheus: keep all grafana functions under grafana flag
Browse files Browse the repository at this point in the history
Signed-off-by: Maryam Tahhan <[email protected]>
  • Loading branch information
maryamtahhan committed Apr 29, 2024
1 parent 76241dc commit 7ef63c0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
26 changes: 18 additions & 8 deletions lib/prometheus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ deploy_prometheus_operator() {
mv kube-prometheus/manifests/prometheus-prometheus.yaml.tmp \
kube-prometheus/manifests/prometheus-prometheus.yaml

_setup_dashboard
_run_yq
_load_prometheus_operator_images_to_local_registry
kubectl create -f kube-prometheus/manifests/setup
kubectl wait \
Expand All @@ -60,9 +58,12 @@ deploy_prometheus_operator() {
-exec kubectl create -f {} \;

is_set "$GRAFANA_ENABLE" && {
find kube-prometheus/manifests -name 'grafana-*.yaml' -type f \
-exec kubectl create -f {} \;
ok "Grafana deployed"
# Double check yq is available
command -v yq >/dev/null 2>&1 && {
_setup_dashboard_configmap
_add_dashboard_to_grafana
}
_deploy_grafana
}

ok "Prometheus deployed"
Expand Down Expand Up @@ -114,11 +115,11 @@ _load_prometheus_operator_images_to_local_registry() {
done
}

_setup_dashboard(){
_setup_dashboard_configmap(){
if [ -f "$DASHBOARD_DIR/grafana-dashboards/kepler-exporter-configmap.yaml" ]; then
return 0
else
header "Setup Dashboard"
header "Create Dashboard Configmap"
mkdir -p "$DASHBOARD_DIR/grafana-dashboards/"
cat - > "$DASHBOARD_DIR/grafana-dashboards/kepler-exporter-configmap.yaml" << EOF
apiVersion: v1
Expand All @@ -136,12 +137,21 @@ metadata:
namespace: monitoring
EOF
fi
ok "Create Dashboard Configmap"
}

_run_yq(){
_add_dashboard_to_grafana() {
header "Edit Kepler Grafana Dashboard "
f="$DASHBOARD_DIR/grafana-dashboards/kepler-exporter-configmap.yaml" \
yq -i e '.items += [load(env(f))]' "$KUBE_PROM_DIR"/manifests/grafana-dashboardDefinitions.yaml;
yq -i e '.spec.template.spec.containers.0.volumeMounts += [ {"mountPath": "/grafana-dashboard-definitions/0/kepler-exporter", "name": "grafana-dashboard-kepler-exporter", "readOnly": false} ]' "$KUBE_PROM_DIR"/manifests/grafana-deployment.yaml
yq -i e '.spec.template.spec.volumes += [ {"configMap": {"name": "grafana-dashboard-kepler-exporter"}, "name": "grafana-dashboard-kepler-exporter"} ]' "$KUBE_PROM_DIR"/manifests/grafana-deployment.yaml;
ok "Dashboard setup complete"
}

_deploy_grafana() {
header "Deploy Grafana"
find kube-prometheus/manifests -name 'grafana-*.yaml' -type f \
-exec kubectl create -f {} \;
ok "Grafana deployed"
}
28 changes: 27 additions & 1 deletion main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ ebpf() {
cd /tmp/elfutils-source/elfutils-0.189
./configure --disable-debuginfod
make install

mkdir -p /tmp/libbpf-source
cd /tmp/libbpf-source
yumdownloader --source libbpf
Expand All @@ -188,6 +187,32 @@ ebpf() {
fi
}

yq_install() {
# Will only install yq if GRAFANA_ENABLE option is set to true
if is_set "$GRAFANA_ENABLE"; then
command -v yq >/dev/null 2>&1 && {
ok "yq is already installed"
return 0
}

GOOS="$(go env GOOS)"
GOARCH="$(go env GOARCH)"
YQ_VERSION=${YQ_VERSION:-v4.34.2}
YQ_INSTALL="https://github.com/mikefarah/yq/releases/download/$YQ_VERSION/yq_${GOOS}_${GOARCH}"
LOCAL_BIN="/usr/bin"

info "installing yq with version: $YQ_VERSION"
mkdir -p "$LOCAL_BIN"
curl -sSLo "$LOCAL_BIN/yq" "$YQ_INSTALL" || {
fail "failed to install yq"
return 1
}

chmod +x "$LOCAL_BIN/yq"
ok "yq was installed successfully"
fi
}

containerruntime() {
set -x
echo start install container runtime as docker
Expand Down Expand Up @@ -243,6 +268,7 @@ main() {
prerequisites)
linuxHeader
ebpf
yq_install
return $?
;;
containerruntime)
Expand Down

0 comments on commit 7ef63c0

Please sign in to comment.