Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prometheus: keep all grafana functions under grafana flag #79

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
SamYuan1990 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading