Skip to content

Commit 320887d

Browse files
committed
add script easzctl: cluster manage tool
1 parent c381639 commit 320887d

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ roles/cluster-backup/files/*
2020
# role based variable settings, exclude roles/os-harden/vars/
2121
/roles/*/vars/*
2222
!/roles/os-harden/vars/
23+
24+
# cluster backups
25+
.cluster/

tools/easzctl

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/bin/bash
2+
#
3+
# This script can be used to manage multiple k8s clusters. (unfinished)
4+
5+
set -o nounset
6+
set -o errexit
7+
#set -o xtrace
8+
9+
function process_cmd {
10+
echo "$ACTION : $CMD"
11+
$CMD
12+
if [[ $? -ne 0 ]]; then
13+
echo "Command failed $CMD"
14+
exit 1
15+
fi
16+
}
17+
18+
function usage {
19+
cat <<EOF
20+
Usage: $0 COMMAND [args]
21+
Commands:
22+
backup To backup the current cluster (data and config)
23+
checkout <name> To checkout and to use the chosen cluster context
24+
create <name> To create a new cluster and to checkout the new cluster
25+
delete To delete the current cluster (keeping backups)
26+
destroy To delete the current cluster and its backups
27+
help To display usage
28+
list To list the existing cluster names
29+
rename <oldname> <newname> To rename an existing cluster's name
30+
restore To restore the current cluster from backups
31+
test To do some smoke tests on the current cluster
32+
untest To remove smoke tests on the current cluster
33+
upgrade Upgrades the current kubernetes cluster
34+
EOF
35+
}
36+
37+
function cp_role_conf {
38+
ROLESPATH=$BASEPATH/../roles
39+
for ROLE in $(ls $ROLESPATH);
40+
do
41+
if [ -d "$ROLESPATH/$ROLE/defaults" ]; then
42+
mkdir -p $BASEPATH/../.cluster/$CLUSTERNAME/$ROLE/defaults/
43+
cp -rp $ROLESPATH/$ROLE/defaults/* $BASEPATH/../.cluster/$CLUSTERNAME/$ROLE/defaults/
44+
fi
45+
done;
46+
}
47+
48+
function init {
49+
if [ ! -d "$BASEPATH/../.cluster" ]; then
50+
mkdir -p $BASEPATH/../.cluster
51+
CLUSTERNAME=default
52+
cp_role_conf
53+
fi
54+
}
55+
56+
###############################################################
57+
58+
BASEPATH=$(cd `dirname $0`; pwd)
59+
60+
init
61+
62+
[ "$#" -gt 0 ] || { usage >&2; exit 2; }
63+
64+
case "$1" in
65+
66+
(backup)
67+
ACTION="action backup"
68+
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=precheck"
69+
;;
70+
(checkout)
71+
ACTION="action checkout"
72+
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
73+
;;
74+
(create)
75+
ACTION="action create"
76+
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=deploy -e common_run=true"
77+
PLAYBOOK="${BASEDIR}/ansible/mariadb_recovery.yml"
78+
;;
79+
(delete)
80+
ACTION="action delete"
81+
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
82+
;;
83+
(destroy)
84+
ACTION="action destroy"
85+
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
86+
;;
87+
(help)
88+
usage
89+
;;
90+
(list)
91+
ACTION="action list"
92+
CMD="ls $BASEPATH/../.cluster"
93+
process_cmd
94+
;;
95+
(rename)
96+
ACTION="action rename"
97+
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
98+
;;
99+
(restore)
100+
ACTION="action restore"
101+
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
102+
;;
103+
(test)
104+
ACTION="action test"
105+
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
106+
;;
107+
(untest)
108+
ACTION="action untest"
109+
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
110+
;;
111+
(upgrade)
112+
ACTION="action upgrade"
113+
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
114+
;;
115+
(*)
116+
usage
117+
exit 0
118+
;;
119+
esac
120+
121+
#CMD="echo $BASEPATH $ACTION"
122+
#process_cmd
123+

0 commit comments

Comments
 (0)