]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | #!/bin/bash |
2 | ||
3 | # | |
4 | # Query k8s to determine where the mgr is running and how to reach the | |
5 | # dashboard from the local machine. This assumes that the dashboard is being | |
6 | # exposed via a nodePort service | |
7 | CURR_DIR=`pwd` | |
8 | K8S_NAMESPACE='rook-ceph' | |
9 | ||
10 | HOST=$(kubectl get pods -n $K8S_NAMESPACE -l "app=rook-ceph-mgr" -o json | jq .items[0].spec.nodeName | sed s/\"//g) | |
11 | if [ "$HOST" = "minikube" ]; then | |
12 | HOST=$(minikube ip) | |
13 | fi | |
14 | PORT=$(kubectl get service -n $K8S_NAMESPACE rook-ceph-mgr-dashboard -o yaml | grep nodePort: | awk '{print $2}') | |
15 | API_URL="https://${HOST}:${PORT}" | |
16 | ||
17 | # | |
18 | # Rook automagically sets up an "admin" account with a random PW and stuffs | |
19 | # that into a k8s secret. This fetches it. | |
20 | # | |
21 | PASSWD=$(kubectl -n $K8S_NAMESPACE get secret rook-ceph-dashboard-password -o yaml | grep "password:" | awk '{print $2}' | base64 --decode) | |
22 | ||
23 | if [ "$API_URL" = "null" ]; then | |
24 | echo "Couldn't retrieve API URL, exiting..." >&2 | |
25 | exit 1 | |
26 | fi | |
27 | cd $CURR_DIR | |
28 | ||
29 | TOKEN=`curl --insecure -s -H "Content-Type: application/json" -X POST \ | |
30 | -d "{\"username\":\"admin\",\"password\":\"${PASSWD}\"}" $API_URL/api/auth \ | |
31 | | jq .token | sed -e 's/"//g'` | |
32 | ||
33 | echo "METHOD: $1" | |
34 | echo "URL: ${API_URL}${2}" | |
35 | echo "DATA: $3" | |
36 | echo "" | |
37 | ||
38 | curl --insecure -s -b /tmp/cd-cookie.txt -H "Authorization: Bearer $TOKEN " \ | |
39 | -H "Content-Type: application/json" -X $1 -d "$3" ${API_URL}$2 | jq | |
40 |