Add maintenance script.
This commit is contained in:
parent
d27339b1e9
commit
1fc26647b6
2 changed files with 63 additions and 0 deletions
1
dev-example/.gitignore
vendored
1
dev-example/.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
||||||
/test-vm-ci.yaml
|
/test-vm-ci.yaml
|
||||||
/kubeconfig.yaml
|
/kubeconfig.yaml
|
||||||
/crds/
|
/crds/
|
||||||
|
/.vm-operator-cmd.rc
|
||||||
|
|
|
||||||
62
dev-example/pool-action.sh
Executable file
62
dev-example/pool-action.sh
Executable file
|
|
@ -0,0 +1,62 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
function usage() {
|
||||||
|
cat >&2 <<EOF
|
||||||
|
Usage: $0 pool-name action
|
||||||
|
Applys action to all VMs in the pool.
|
||||||
|
|
||||||
|
--context Context to be passed to kubectl (required)
|
||||||
|
-n, --namespace Namespace to be passed to kubectl
|
||||||
|
EOF
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
unset pool
|
||||||
|
unset action
|
||||||
|
unset context
|
||||||
|
namespace=default
|
||||||
|
|
||||||
|
if [ -r .vm-operator-cmd.rc ]; then
|
||||||
|
. .vm-operator-cmd.rc
|
||||||
|
fi
|
||||||
|
|
||||||
|
while [ "$#" -gt 0 ]; do
|
||||||
|
case "$1" in
|
||||||
|
--context) shift; context="$1";;
|
||||||
|
--context=*) IFS='=' read -r option value <<< "$1"; context="$value";;
|
||||||
|
-n|--namespace) shift; namespace="$1";;
|
||||||
|
-*) echo >&2 "Unknown option: $1"; exit 1;;
|
||||||
|
*) if [ ! -v pool ]; then
|
||||||
|
pool="$1"
|
||||||
|
elif [ ! -v action ]; then
|
||||||
|
action="$1"
|
||||||
|
else
|
||||||
|
usage
|
||||||
|
fi;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ ! -v pool -o ! -v "action" -o ! -v context ]; then
|
||||||
|
echo >&2 "Missing arguments or context not set."
|
||||||
|
echo >&2
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
case "$action" in
|
||||||
|
"start"|"stop"|"delete"|"delete-disks") ;;
|
||||||
|
*) usage;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
kubectl --context="$context" -n "$namespace" get vms -o json \
|
||||||
|
| jq -r '.items[] | select(.spec.pools | contains(["'${pool}'"])) | .metadata.name' \
|
||||||
|
| while read vmName; do
|
||||||
|
case "$action" in
|
||||||
|
start) kubectl --context="$context" -n "$namespace" patch vms "$vmName" \
|
||||||
|
--type='merge' -p '{"spec":{"vm":{"state":"Running"}}}';;
|
||||||
|
stop) kubectl --context="$context" -n "$namespace" patch vms "$vmName" \
|
||||||
|
--type='merge' -p '{"spec":{"vm":{"state":"Stopped"}}}';;
|
||||||
|
delete) kubectl --context="$context" -n "$namespace" delete vm/"$vmName";;
|
||||||
|
delete-disks) kubectl --context="$context" -n "$namespace" delete \
|
||||||
|
pvc -l app.kubernetes.io/instance="$vmName" ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
Loading…
Add table
Add a link
Reference in a new issue