From 6336e8337147519fbe109c757a35e5de428876c8 Mon Sep 17 00:00:00 2001 From: Marcus Noble Date: Wed, 1 Feb 2023 18:42:20 +0000 Subject: [PATCH] Added flux-refresh-all Signed-off-by: Marcus Noble --- home/.bin/flux-refresh-all | 107 +++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100755 home/.bin/flux-refresh-all diff --git a/home/.bin/flux-refresh-all b/home/.bin/flux-refresh-all new file mode 100755 index 0000000..24970ad --- /dev/null +++ b/home/.bin/flux-refresh-all @@ -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