Files
platform/bin/teardown.sh
2019-10-18 10:23:43 +02:00

42 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
TOP="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/.."
case $* in
--reboot) reboot=1; shift ;;
esac
if [ $# != 1 ]; then
echo "usage: teardown.sh [--reboot] name"
exit 1
fi
d=$1
f=$TOP/clusters/$d/.$d.$$
teardown () {
sed -s 's/cluster.\(apiserver\|worker\)/cluster.host/' $TOP/clusters/$d/default.nix > $f
nixops modify -d $d $f
nixops deploy -d $d
[ ! -z $reboot ] && nixops reboot -d $d
nixops ssh-for-each -d $d "rm -rf /var/run/kubernetes /var/lib/kubernetes /var/lib/etcd /var/lib/kubelet /var/lib/cfssl"
rm $f
}
cat << EOF
************************************************************************
*** ***
*** WARNING: This will irrevokably destroy the running cluster! ***
*** ***
************************************************************************
EOF
echo "Are you sure you want to tear down $d? (YES/no)"
read a
case $a in
YES) teardown ;;
*) echo "Bailing out." ;;
esac