diff --git a/.gitignore b/.gitignore index 49c7a1e..c8e8653 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/tools/easzctl b/tools/easzctl new file mode 100755 index 0000000..169df0a --- /dev/null +++ b/tools/easzctl @@ -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 < To checkout and to use the chosen cluster context + create 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 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 +