Skip to content

Commit

Permalink
add script easzctl: cluster manage tool
Browse files Browse the repository at this point in the history
  • Loading branch information
gjmzj committed Nov 5, 2018
1 parent c381639 commit 320887d
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ roles/cluster-backup/files/*
# role based variable settings, exclude roles/os-harden/vars/
/roles/*/vars/*
!/roles/os-harden/vars/

# cluster backups
.cluster/
123 changes: 123 additions & 0 deletions tools/easzctl
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/bin/bash
#
# This script can be used to manage multiple k8s clusters. (unfinished)

set -o nounset
set -o errexit
#set -o xtrace

function process_cmd {
echo "$ACTION : $CMD"
$CMD
if [[ $? -ne 0 ]]; then
echo "Command failed $CMD"
exit 1
fi
}

function usage {
cat <<EOF
Usage: $0 COMMAND [args]
Commands:
backup To backup the current cluster (data and config)
checkout <name> To checkout and to use the chosen cluster context
create <name> To create a new cluster and to checkout the new cluster
delete To delete the current cluster (keeping backups)
destroy To delete the current cluster and its backups
help To display usage
list To list the existing cluster names
rename <oldname> <newname> To rename an existing cluster's name
restore To restore the current cluster from backups
test To do some smoke tests on the current cluster
untest To remove smoke tests on the current cluster
upgrade Upgrades the current kubernetes cluster
EOF
}

function cp_role_conf {
ROLESPATH=$BASEPATH/../roles
for ROLE in $(ls $ROLESPATH);
do
if [ -d "$ROLESPATH/$ROLE/defaults" ]; then
mkdir -p $BASEPATH/../.cluster/$CLUSTERNAME/$ROLE/defaults/
cp -rp $ROLESPATH/$ROLE/defaults/* $BASEPATH/../.cluster/$CLUSTERNAME/$ROLE/defaults/
fi
done;
}

function init {
if [ ! -d "$BASEPATH/../.cluster" ]; then
mkdir -p $BASEPATH/../.cluster
CLUSTERNAME=default
cp_role_conf
fi
}

###############################################################

BASEPATH=$(cd `dirname $0`; pwd)

init

[ "$#" -gt 0 ] || { usage >&2; exit 2; }

case "$1" in

(backup)
ACTION="action backup"
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=precheck"
;;
(checkout)
ACTION="action checkout"
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
;;
(create)
ACTION="action create"
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=deploy -e common_run=true"
PLAYBOOK="${BASEDIR}/ansible/mariadb_recovery.yml"
;;
(delete)
ACTION="action delete"
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
;;
(destroy)
ACTION="action destroy"
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
;;
(help)
usage
;;
(list)
ACTION="action list"
CMD="ls $BASEPATH/../.cluster"
process_cmd
;;
(rename)
ACTION="action rename"
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
;;
(restore)
ACTION="action restore"
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
;;
(test)
ACTION="action test"
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
;;
(untest)
ACTION="action untest"
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
;;
(upgrade)
ACTION="action upgrade"
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
;;
(*)
usage
exit 0
;;
esac

#CMD="echo $BASEPATH $ACTION"
#process_cmd

0 comments on commit 320887d

Please sign in to comment.