Skip to content

Commit

Permalink
Merge pull request #79 from maryamtahhan/hotfix-grafana
Browse files Browse the repository at this point in the history
prometheus: keep all grafana functions under grafana flag
  • Loading branch information
SamYuan1990 authored May 1, 2024
2 parents 76241dc + 96a63f8 commit a68f078
Show file tree
Hide file tree
Showing 2 changed files with 50 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"
}
33 changes: 32 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,37 @@ 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
}

YQ="/usr/bin/yq"
YQ_VERSION=${YQ_VERSION:-v4.34.2}
ARCH="$(uname -m)"
YQ_ARCH="amd64" # set a reasonable default
if [[ -n "${ARCH}" ]]; then
case "${ARCH}" in
x86_64) YQ_ARCH=amd64;;
aarch64) YQ_ARCH=arm64;;
esac
fi
YQ_INSTALL="https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_${YQ_ARCH}"

info "installing yq version: $YQ_VERSION and arch: $YQ_ARCH"
wget "${YQ_INSTALL}" -O "${YQ}" || {
fail "failed to install yq"
rm -rf "${YQ}" # cleanup in case of fail
return 1
}
chmod +x "${YQ}"
ok "yq was installed successfully"
fi
}

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

0 comments on commit a68f078

Please sign in to comment.