-
Notifications
You must be signed in to change notification settings - Fork 571
Expand file tree
/
Copy pathinstall-grafana-operator.sh
More file actions
executable file
·79 lines (60 loc) · 2.6 KB
/
Copy pathinstall-grafana-operator.sh
File metadata and controls
executable file
·79 lines (60 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
echo "External value for \$GRAFANA_NAMESPACE=$GRAFANA_NAMESPACE"
echo "External value for \$GRAFANA_OPERATOR_VERSION=$GRAFANA_OPERATOR_VERSION"
GRAFANA_NAMESPACE="${GRAFANA_NAMESPACE:-grafana}"
GRAFANA_OPERATOR_VERSION="${GRAFANA_OPERATOR_VERSION:-v5.18.0}"
echo "Setup Grafana"
echo "OPTIONS"
echo "\$GRAFANA_NAMESPACE=${GRAFANA_NAMESPACE}"
echo "\$GRAFANA_OPERATOR_VERSION=${GRAFANA_OPERATOR_VERSION}"
echo ""
echo "!!! IMPORTANT !!!"
echo "If you do not agree with specified options, press ctrl-c now"
if [[ "" == "${NO_WAIT}" ]]; then
sleep 10
fi
echo "Apply options now..."
##
##
##
function clean_dir() {
DIR="$1"
echo "##############################"
echo "Clean dir $DIR ..."
rm -rf "$DIR"
echo "...DONE"
}
##############################
## ##
## Install Grafana operator ##
## ##
##############################
# Download grafana-operator sources into temp dir and run all installation scripts from there
TMP_DIR=$(mktemp -d)
GRAFANA_OPERATOR_DIR="${TMP_DIR}/grafana-operator"
# Ensure temp dir in place
mkdir -p "${GRAFANA_OPERATOR_DIR}"
# Temp dir must not contain any data
if [[ -n "$(ls -A "${GRAFANA_OPERATOR_DIR}")" ]]; then
echo "${GRAFANA_OPERATOR_DIR} is not empty. Abort"
exit 1
fi
# Temp dir is empty, will clear it upon script termination
trap "clean_dir ${TMP_DIR}" SIGHUP SIGINT SIGQUIT SIGFPE SIGALRM SIGTERM
# Continue with sources
echo "Download Grafana operator sources into ${GRAFANA_OPERATOR_DIR}"
git clone -b ${GRAFANA_OPERATOR_VERSION} --single-branch "https://github.com/grafana/grafana-operator" "${GRAFANA_OPERATOR_DIR}"
echo "Setup Grafana operator into ${GRAFANA_NAMESPACE} namespace"
# Let's setup all grafana-related stuff into dedicated namespace
kubectl create namespace "${GRAFANA_NAMESPACE}" || true
# Setup grafana-operator into dedicated namespace
# Use sed with compatibility for both macOS and Linux
if [[ "$(uname)" == "Darwin" ]]; then
sed -i '' "s/namespace: system/namespace: ${GRAFANA_NAMESPACE}/g" "${GRAFANA_OPERATOR_DIR}/deploy/kustomize/overlays/namespace_scoped/kustomization.yaml"
else
sed -i "s/namespace: system/namespace: ${GRAFANA_NAMESPACE}/g" "${GRAFANA_OPERATOR_DIR}/deploy/kustomize/overlays/namespace_scoped/kustomization.yaml"
fi
kubectl kustomize "${GRAFANA_OPERATOR_DIR}/deploy/kustomize/overlays/namespace_scoped" --load-restrictor LoadRestrictionsNone | kubectl apply --server-side -f -
kubectl wait deployment/grafana-operator-controller-manager -n "${GRAFANA_NAMESPACE}" --for=condition=available --timeout=300s
# Remove downloaded sources
clean_dir "${TMP_DIR}"