From 8ac6aef897fcc0c6f4a90f81b2134b9f4d8845ce Mon Sep 17 00:00:00 2001 From: Marcus Noble Date: Fri, 11 Nov 2022 14:39:30 +0000 Subject: [PATCH] Added flux utils Signed-off-by: Marcus Noble --- home/.bin/flux-resume-all | 43 +++++++++++++++++++++++++++++++++++++++ home/.bin/flux-state | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100755 home/.bin/flux-resume-all create mode 100755 home/.bin/flux-state diff --git a/home/.bin/flux-resume-all b/home/.bin/flux-resume-all new file mode 100755 index 0000000..ab9365f --- /dev/null +++ b/home/.bin/flux-resume-all @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +source .utils + +set -e + +print_usage() { + blue "flux-resume-all - Resume all flux resources" + echo " " + underline "Usage:" + echo "flux-resume-all [options]" + echo " " + underline "Options:" + echo "-h, --help show this help text" +} + +while test $# -gt 0; do + case "$1" in + -h|--help) + print_usage + exit 0 + ;; + *) + break + ;; + esac +done + + +KUSTOMIZATIONS=$(kubectl get kustomization -A -o json | jq -r '.items[] | select(.spec.suspend==true) | "\(.metadata.namespace)/\( .kind)/\( .metadata.name)"') +GITREPOS=$(kubectl get gitrepo -A -o json | jq -r '.items[] | select(.spec.suspend==true) | "\(.metadata.namespace)/\( .kind)/\( .metadata.name)"') + +if [[ "${KUSTOMIZATIONS}" == "" ]] && [[ "${GITREPOS}" == "" ]]; then + italic "Nothing to resume" +fi + +for RESOURCE in ${KUSTOMIZATIONS} ${GITREPOS} +do + PARTS=($(echo ${RESOURCE} | tr '[:upper:]' '[:lower:]' | tr "/" "\n")) + blue "Resuming ${PARTS[1]} - ${PARTS[0]}/${PARTS[2]}" + kubectl patch ${PARTS[1]} -n ${PARTS[0]} ${PARTS[2]} -p '{"spec":{"suspend":null}}' --type merge +done + diff --git a/home/.bin/flux-state b/home/.bin/flux-state new file mode 100755 index 0000000..38d540d --- /dev/null +++ b/home/.bin/flux-state @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +source .utils + +set -e + +print_usage() { + blue "flux-state - Check if any Flux resources are suspended" + echo " " + underline "Usage:" + echo "flux-state [options]" + echo " " + underline "Options:" + echo "-h, --help show this help text" +} + +while test $# -gt 0; do + case "$1" in + -h|--help) + print_usage + exit 0 + ;; + *) + break + ;; + esac +done + +blue "'kustomization' resources:" +KUSTOMIZATIONS=$(kubectl get kustomization -A -o json) +echo ${KUSTOMIZATIONS} | jq -r '.items[] | select(.spec.suspend==true) | "\(.metadata.namespace)/\( .metadata.name) - ⚠️Suspended"' | column -t +echo ${KUSTOMIZATIONS} | jq -r '.items[] | select(.spec.suspend!=true) | "\(.metadata.namespace)/\( .metadata.name) - ⚡️Active"' | column -t +echo "" +blue "'gitrepo' resources:" +GITREPOS=$(kubectl get gitrepo -A -o json) +echo ${GITREPOS} | jq -r '.items[] | select(.spec.suspend==true) | "\(.metadata.namespace)/\( .metadata.name) - ⚠️Suspended"' | column -t +echo ${GITREPOS} | jq -r '.items[] | select(.spec.suspend!=true) | "\(.metadata.namespace)/\( .metadata.name) - ⚡️Active"' | column -t