Skip to content

Commit 46258f8

Browse files
authoredMar 7, 2018
Merge pull request #18677 from mrsiano/dynamictoken
Automatic merge from submit-queue. Grab the sa token per namespace. the following script uses prometheus namespace on the fly (if not specified by the user). we should use that namespace accordingly when generate the payload.
2 parents 8f44e66 + 7a9a019 commit 46258f8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed
 

‎examples/grafana/setup-grafana.sh

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ setoauth=0
44
node_exporter=0
55
datasource_name=''
66
prometheus_namespace=''
7+
sa_reader=''
78
graph_granularity=''
89
yaml=''
910
protocol="https://"
1011

11-
while getopts 'n:p:g:y:ae' flag; do
12+
while getopts 'n:s:p:g:y:ae' flag; do
1213
case "${flag}" in
1314
n) datasource_name="${OPTARG}" ;;
15+
s) sa_reader="${OPTARG}" ;;
1416
p) prometheus_namespace="${OPTARG}" ;;
1517
g) graph_granularity="${OPTARG}" ;;
1618
y) yaml="${OPTARG}" ;;
@@ -23,10 +25,11 @@ done
2325
usage() {
2426
echo "
2527
USAGE
26-
setup-grafana.sh -n <datasource_name> -a [optional: -p <prometheus_namespace> -g <graph_granularity> -y <yaml> -e]
28+
setup-grafana.sh -n <datasource_name> -a [optional: -p <prometheus_namespace> -s <prometheus_serviceaccount> -g <graph_granularity> -y <yaml> -e]
2729
2830
switches:
2931
-n: grafana datasource name
32+
-s: prometheus serviceaccount name
3033
-p: existing prometheus name e.g openshift-metrics
3134
-g: specifiy granularity
3235
-y: specifies the grafana yaml
@@ -65,6 +68,7 @@ mv "${dashboard_file}.bak" "${dashboard_file}"
6568
}
6669

6770
[[ -n ${datasource_name} ]] || usage
71+
[[ -n ${sa_reader} ]] || sa_reader="prometheus"
6872
[[ -n ${prometheus_namespace} ]] || get::namespace
6973
[[ -n ${graph_granularity} ]] || graph_granularity="2m"
7074
[[ -n ${yaml} ]] || yaml="grafana.yaml"
@@ -87,7 +91,7 @@ cat <<EOF >"${payload}"
8791
"withCredentials": false,
8892
"jsonData": {
8993
"tlsSkipVerify":true,
90-
"token":"$( oc sa get-token grafana )"
94+
"token":"$( oc sa get-token "${sa_reader}" -n "${prometheus_namespace}" )"
9195
}
9296
}
9397
EOF

0 commit comments

Comments
 (0)
Please sign in to comment.