dotfiles/home/.bin/flux-pause
Marcus Noble d7469d40ae
Added an --all flag to flux-pause
Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
2024-02-13 12:44:24 +00:00

69 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
source .utils
set -e
VERBOSE=""
ALL=""
TARGET_RESOURCE="kustomization"
NAMESPACES="-n flux-system"
print_usage() {
blue "flux-pause - Suspends Flux Kustomization resources"
echo " "
underline "Usage:"
echo "flux-pause [options] RESOURCE_NAME..."
echo " "
underline "Options:"
echo " --all pause all Kustomizations"
echo "-n, --namespace the namespace resources belong in. Default: flux-system"
echo "-v --verbose show full verbose output"
echo "-h, --help show this help text"
}
RESOURCES=()
while test $# -gt 0; do
case "$1" in
-h|--help)
print_usage
exit 0
;;
-n|--namespace)
shift
NAMESPACES="-n $1"
shift
;;
-v|--verbose)
VERBOSE="true"
shift
;;
--all)
ALL="true"
shift
;;
*)
RESOURCES+=(${1})
shift
;;
esac
done
if [[ "${ALL}" == "true" ]]; then
RESOURCES=$(kubectl get kustomization ${NAMESPACES} -o json | jq -r '.items[] | "\( .metadata.name)"')
fi
for RESOURCE in ${RESOURCES[@]}
do
printf "Pausing '${RESOURCE}'..."
if [[ "${VERBOSE}" == "true" ]]; then
echo ""
flux suspend kustomization ${NAMESPACES} ${RESOURCE} || true
else
flux suspend kustomization ${NAMESPACES} ${RESOURCE} &> /dev/null || true
printf " ✅"
fi
echo ""
done