Added flux-refresh-all

Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
Marcus Noble 2023-02-01 18:42:20 +00:00
parent c306923371
commit 6336e83371
Signed by: AverageMarcus
GPG Key ID: B8F2DB8A7AEBAF78

107
home/.bin/flux-refresh-all Executable file
View File

@ -0,0 +1,107 @@
#!/usr/bin/env bash
source .utils
set -e
VERBOSE=""
print_usage() {
blue "flux-refresh-all - Refresh all flux resources"
echo " "
underline "Usage:"
echo "flux-refresh-all [options]"
echo " "
underline "Options:"
echo " --verbose show full verbose output"
echo "-h, --help show this help text"
}
while test $# -gt 0; do
case "$1" in
-h|--help)
print_usage
exit 0
;;
--verbose)
VERBOSE="true"
shift
;;
*)
break
;;
esac
done
GITREPOS=$(kubectl get gitrepo -A -o json | jq -r '.items[] | "\(.metadata.namespace)/\( .kind)/\( .metadata.name)"')
HELMREPOS=$(kubectl get helmrepository -A -o json | jq -r '.items[] | "\(.metadata.namespace)/\( .kind)/\( .metadata.name)"')
KUSTOMIZATIONS=$(kubectl get kustomization -A -o json | jq -r '.items[] | "\(.metadata.namespace)/\( .kind)/\( .metadata.name)"')
HEALMRELEASES=$(kubectl get helmrelease -A -o json | jq -r '.items[] | "\(.metadata.namespace)/\( .kind)/\( .metadata.name)"')
if [[ "${GITREPOS}" != "" ]]; then
blue "Refreshing GitRepositories"
for RESOURCE in ${GITREPOS}
do
PARTS=($(echo ${RESOURCE} | tr '[:upper:]' '[:lower:]' | tr "/" "\n"))
printf "${PARTS[0]}/${PARTS[2]}"
if [[ "${VERBOSE}" == "true" ]]; then
echo ""
flux reconcile source git -n ${PARTS[0]} ${PARTS[2]} || true
else
flux reconcile source git -n ${PARTS[0]} ${PARTS[2]} &> /dev/null || true
printf " ✅"
fi
echo ""
done
fi
if [[ "${HELMREPOS}" != "" ]]; then
blue "Refreshing HelmRepositories"
for RESOURCE in ${HELMREPOS}
do
PARTS=($(echo ${RESOURCE} | tr '[:upper:]' '[:lower:]' | tr "/" "\n"))
printf "${PARTS[0]}/${PARTS[2]}"
if [[ "${VERBOSE}" == "true" ]]; then
echo ""
flux reconcile source helm -n ${PARTS[0]} ${PARTS[2]} || true
else
flux reconcile source helm -n ${PARTS[0]} ${PARTS[2]} &> /dev/null || true
printf " ✅"
fi
echo ""
done
fi
if [[ "${KUSTOMIZATIONS}" != "" ]]; then
blue "Refreshing Kustomizations"
for RESOURCE in ${KUSTOMIZATIONS}
do
PARTS=($(echo ${RESOURCE} | tr '[:upper:]' '[:lower:]' | tr "/" "\n"))
printf "${PARTS[0]}/${PARTS[2]}"
if [[ "${VERBOSE}" == "true" ]]; then
echo ""
flux reconcile kustomization -n ${PARTS[0]} ${PARTS[2]} || true
else
flux reconcile kustomization -n ${PARTS[0]} ${PARTS[2]} &> /dev/null || true
printf " ✅"
fi
echo ""
done
fi
if [[ "${HEALMRELEASES}" != "" ]]; then
blue "Refreshing HelmReleases"
for RESOURCE in ${HEALMRELEASES}
do
PARTS=($(echo ${RESOURCE} | tr '[:upper:]' '[:lower:]' | tr "/" "\n"))
printf "${PARTS[0]}/${PARTS[2]}"
if [[ "${VERBOSE}" == "true" ]]; then
echo ""
flux reconcile helmrelease -n ${PARTS[0]} ${PARTS[2]} || true
else
flux reconcile helmrelease -n ${PARTS[0]} ${PARTS[2]} &> /dev/null || true
printf " ✅"
fi
echo ""
done
fi