2023-02-01 18:42:20 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
source .utils
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
VERBOSE=""
|
2023-02-02 15:33:07 +00:00
|
|
|
TARGET_RESOURCE="all"
|
|
|
|
NAMESPACES="-A"
|
2023-02-01 18:42:20 +00:00
|
|
|
|
|
|
|
print_usage() {
|
2023-02-02 15:33:07 +00:00
|
|
|
blue "flux-refresh - Refresh all flux resources"
|
2023-02-01 18:42:20 +00:00
|
|
|
echo " "
|
|
|
|
underline "Usage:"
|
2023-02-02 15:33:07 +00:00
|
|
|
echo "flux-refresh [options]"
|
2023-02-01 18:42:20 +00:00
|
|
|
echo " "
|
|
|
|
underline "Options:"
|
2023-02-02 15:33:07 +00:00
|
|
|
echo "-t, --type the resource type to target. Valid options: gitrepo, helmrepository, kustomization, helmrelease & all. Default: all"
|
|
|
|
echo "-n, --namespace the namespace resources belong in. Default: all namespaces"
|
2023-02-01 18:42:20 +00:00
|
|
|
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
|
|
|
|
;;
|
2023-02-02 15:33:07 +00:00
|
|
|
-t|--type)
|
|
|
|
shift
|
|
|
|
TARGET_RESOURCE=$1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-n|--namespace)
|
|
|
|
shift
|
|
|
|
NAMESPACES="-n $1"
|
|
|
|
shift
|
|
|
|
;;
|
2023-02-01 18:42:20 +00:00
|
|
|
--verbose)
|
|
|
|
VERBOSE="true"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
2023-02-02 15:33:07 +00:00
|
|
|
shift
|
2023-02-01 18:42:20 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2023-02-02 15:33:07 +00:00
|
|
|
if [[ "${TARGET_RESOURCE}" == "all" || "${TARGET_RESOURCE}" == "gitrepo" ]]; then
|
|
|
|
GITREPOS=$(kubectl get gitrepo ${NAMESPACES} -o json | jq -r '.items[] | "\(.metadata.namespace)/\( .kind)/\( .metadata.name)"')
|
|
|
|
fi
|
|
|
|
if [[ "${TARGET_RESOURCE}" == "all" || "${TARGET_RESOURCE}" == "helmrepository" ]]; then
|
|
|
|
HELMREPOS=$(kubectl get helmrepository ${NAMESPACES} -o json | jq -r '.items[] | "\(.metadata.namespace)/\( .kind)/\( .metadata.name)"')
|
|
|
|
fi
|
|
|
|
if [[ "${TARGET_RESOURCE}" == "all" || "${TARGET_RESOURCE}" == "kustomization" ]]; then
|
|
|
|
KUSTOMIZATIONS=$(kubectl get kustomization ${NAMESPACES} -o json | jq -r '.items[] | "\(.metadata.namespace)/\( .kind)/\( .metadata.name)"')
|
|
|
|
fi
|
|
|
|
if [[ "${TARGET_RESOURCE}" == "all" || "${TARGET_RESOURCE}" == "helmrelease" ]]; then
|
|
|
|
HEALMRELEASES=$(kubectl get helmrelease ${NAMESPACES} -o json | jq -r '.items[] | "\(.metadata.namespace)/\( .kind)/\( .metadata.name)"')
|
|
|
|
fi
|
2023-02-01 18:42:20 +00:00
|
|
|
|
|
|
|
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
|