-
Notifications
You must be signed in to change notification settings - Fork 10
/
k8s-deploy
executable file
·111 lines (97 loc) · 3.22 KB
/
k8s-deploy
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
####################################################################################################
# Installer for Platform9 Bare-Metal Kubernetes using PMK
#
# Sample Invocations:
# ./k8s-deploy create-cluster c2 10.20.0.0/16 10.40.0.0/16 \
# 5f50c197-782c-48f0-8587-e75c21ce778d 172.16.7.254 ens192 172.20.10.121 172.20.10.124
####################################################################################################
config_file=$(dirname $0)/pf9-express.conf
libdir=$(dirname $0)/lib/k8s-deploy
tokendb=/tmp/token.dat
flag_update_token=0
flag_verbose=0
log_hostagent=/var/log/pf9/hostagent.log
assert() {
if [ $# -eq 1 ]; then echo "ASSERT: ${1}"; fi
exit 1
}
usage() {
echo -e "Usage: `basename $0` [-d] <Method> [Args]\n"
echo "Methods:"
echo " `${libdir}/create-cluster -h`"
echo " `${libdir}/attach-master -h`"
echo " `${libdir}/attach-worker -h`"
echo " `${libdir}/get-node -h`"
echo " `${libdir}/get-cluster -h`"
echo " `${libdir}/get-clusterNode -h`"
echo " `${libdir}/get-provider -h`"
echo " `${libdir}/get-tenant -h`"
echo " `${libdir}/detach-worker -h`"
echo " `${libdir}/detach-master -h`"
echo " `${libdir}/install-kubectl -h`"
echo " `${libdir}/auth-node -h`"
echo
exit 1
}
read_config() {
if [ ! -r ${config_file} ]; then assert "config file missing: ${config_file}"; fi
du_url=$(grep ^du_url ${config_file} | cut -d \| -f2)
admin_user=$(grep ^os_username ${config_file} | cut -d \| -f2)
admin_password=$(grep ^os_password ${config_file} | cut -d \| -f2)
}
get_token() {
# manage token
if [ ! -r ${tokendb} ]; then
flag_update_token=1
else
token_ts=$(head -1 ${tokendb})
current_time=$(date +%s)
token_expire_ts=$((token_ts + 86400))
if [ ${current_time} -ge ${token_expire_ts} ]; then flag_update_token=1; fi
fi
if [ ${flag_update_token} -eq 1 ]; then
token=`curl -k -i -H "Content-Type: application/json" ${du_url}/keystone/v3/auth/tokens?nocatalog \
-d "{ \"auth\": { \"identity\": { \"methods\": [\"password\"], \"password\": { \"user\": { \"name\": \"${admin_user}\", \
\"domain\": {\"id\": \"default\"}, \"password\": \"${admin_password}\" } } }, \
\"scope\": { \"project\": { \"name\": \"service\", \"domain\": {\"id\": \"default\"}}}}}" 2>/dev/null \
| grep -i ^X-Subject-Token | awk -F : '{print $2}' | sed -e 's/ //g' | sed -e 's/\r//g'`
# update tokendb
if [ -z "${token}" ]; then assert "failed to get token"; fi
echo "$(date +%s)" > ${tokendb}
echo "${token}" >> ${tokendb}
else
token=$(cat ${tokendb} | tail -1)
fi
}
# read config file
read_config
# get keystone token
get_token
# validate command-line
if [ $# -eq 0 ]; then usage; fi
# process optional args
while [ $# -gt 0 ]; do
case ${1} in
-d|--debug)
flag_verbose=1
shift
;;
*)
break
;;
esac
done
# execute methods
op=${1}
case ${op} in
auth-node|create-cluster|attach-master|attach-worker|get-node|get-cluster|get-clusterNode|get-provider|get-tenant|delete-cluster|install-kubectl|detach-worker|detach-master)
if [ ! -r ${libdir}/${op} ]; then assert "missing library: ${libdir}/${op}"; fi
source ${libdir}/${op} $*
;;
*)
usage
;;
esac
# exit cleanly
exit 0