MAS-WP-0007 is finished. power.sh scales the MX and statute together and records the power annotation. apply.sh keeps an off facility off. The live facility was annotated power=on and was not restarted. Assistant: grok Assistant-Session: 01a198fa-fd27-7e41-a0a2-57355c3e4efd
73 lines
1.6 KiB
Bash
Executable file
73 lines
1.6 KiB
Bash
Executable file
#!/bin/bash
|
|
# Turn the MAS facility on or off (MAS-WP-0007).
|
|
# Scales only deploy/mas-mx and deploy/mas-statute. The namespace, evidence
|
|
# PVC, Services, Ingress, and ExternalSecret stay.
|
|
# Records the desired power on namespace mas:
|
|
# mas.coulomb.social/power=on|off
|
|
set -eu
|
|
set -o pipefail
|
|
|
|
ns=mas
|
|
annotation=mas.coulomb.social/power
|
|
deployments="mas-mx mas-statute"
|
|
|
|
usage() {
|
|
echo "usage: power.sh on|off|status" >&2
|
|
exit 2
|
|
}
|
|
|
|
power_now() {
|
|
kubectl get namespace "$ns" \
|
|
-o jsonpath='{.metadata.annotations.mas\.coulomb\.social/power}'
|
|
}
|
|
|
|
wait_ready() {
|
|
name=$1
|
|
kubectl -n "$ns" rollout status "deploy/$name" --timeout=180s
|
|
}
|
|
|
|
wait_stopped() {
|
|
name=$1
|
|
i=0
|
|
while [ "$i" -lt 90 ]; do
|
|
left=$(kubectl -n "$ns" get pods -l "app.kubernetes.io/name=$name" --no-headers 2>/dev/null | wc -l)
|
|
left=$(echo "$left" | tr -d ' ')
|
|
if [ "$left" -eq 0 ]; then
|
|
return 0
|
|
fi
|
|
i=$((i + 1))
|
|
sleep 2
|
|
done
|
|
echo "pods for $name are still running" >&2
|
|
exit 1
|
|
}
|
|
|
|
cmd=${1:-}
|
|
case "$cmd" in
|
|
on|off)
|
|
kubectl annotate namespace "$ns" "$annotation=$cmd" --overwrite
|
|
if [ "$cmd" = on ]; then
|
|
replicas=1
|
|
else
|
|
replicas=0
|
|
fi
|
|
for name in $deployments; do
|
|
kubectl -n "$ns" scale "deploy/$name" --replicas="$replicas"
|
|
done
|
|
for name in $deployments; do
|
|
if [ "$cmd" = on ]; then
|
|
wait_ready "$name"
|
|
else
|
|
wait_stopped "$name"
|
|
fi
|
|
done
|
|
;;
|
|
status)
|
|
echo "power=$(power_now)"
|
|
kubectl -n "$ns" get deploy $deployments
|
|
kubectl -n "$ns" get endpointslice -l 'kubernetes.io/service-name in (mas-smtp,mas-statute)'
|
|
;;
|
|
*)
|
|
usage
|
|
;;
|
|
esac
|