Unverified Commit f0458106 authored by sed-i's avatar sed-i Committed by Marc Cornellà

feat(juju): add `jclean` function to destroy all registered controllers (#10426)

Closes #10426
parent c41f2e7a
...@@ -113,5 +113,6 @@ Naming convention: ...@@ -113,5 +113,6 @@ Naming convention:
- `jaddr <app_name> [unit_num]`: display app or unit IP address. - `jaddr <app_name> [unit_num]`: display app or unit IP address.
- `jreld <relation_name> <app_name> <unit_num>`: display app and unit relation data. - `jreld <relation_name> <app_name> <unit_num>`: display app and unit relation data.
- `jclean`: destroy all controllers
- `wjst [interval_secs] [args_for_watch]`: watch juju status, with optional interval - `wjst [interval_secs] [args_for_watch]`: watch juju status, with optional interval
(default: 5s); you may pass additional arguments to `watch`. (default: 5s); you may pass additional arguments to `watch`.
...@@ -95,6 +95,37 @@ jaddr() { ...@@ -95,6 +95,37 @@ jaddr() {
fi fi
} }
# Destroy all controllers
jclean() {
if (( ! ${+commands[jq]} )); then
echo "jq is required but could not be found." >&2
return 1
fi
local controllers=$(juju controllers --format=json | jq -r '.controllers | keys[]' 2>/dev/null)
if [[ -z "$controllers" ]]; then
echo "No controllers registered"
return 0
fi
echo "This will forcefully destroy all storages, models and controllers."
echo "Controllers to be destroyed:"
echo "$controllers"
if ! read -q '?Are you sure (y/n)? '; then
echo
echo "Aborted."
return 0
fi
echo
for controller in ${=controllers}; do
timeout 2m juju destroy-controller --destroy-all-models --destroy-storage --force --no-wait -y $controller
timeout 2m juju kill-controller -y -t 0 $controller 2>/dev/null
timeout 10s juju unregister $controller 2>/dev/null
done
}
# Display app and unit relation data # Display app and unit relation data
jreld() { jreld() {
# $1 = relation name # $1 = relation name
...@@ -125,3 +156,4 @@ wjst() { ...@@ -125,3 +156,4 @@ wjst() {
shift $(( $# > 0 )) shift $(( $# > 0 ))
watch -n "$interval" --color juju status --relations --storage --color "$@" watch -n "$interval" --color juju status --relations --storage --color "$@"
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment