From 7adcc6e973686d9210ef968e926718005e90370f Mon Sep 17 00:00:00 2001 From: Olivier Grand Date: Tue, 5 Dec 2023 13:49:32 +0100 Subject: [PATCH] fix issue #146 --- tools/k9s-plugins.yml | 2 +- tools/suspend-resume-hr.sh | 39 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100755 tools/suspend-resume-hr.sh diff --git a/tools/k9s-plugins.yml b/tools/k9s-plugins.yml index e04307e..48555e5 100644 --- a/tools/k9s-plugins.yml +++ b/tools/k9s-plugins.yml @@ -190,7 +190,7 @@ plugin: confirm: true args: - -c - - "flux $([ $(kubectl get helmreleases --context $CONTEXT -n $NAMESPACE $NAME -o=custom-columns=TYPE:.spec.suspend | tail -1) = \"true\" ] && echo \"resume\" || echo \"suspend\") helmrelease --context $CONTEXT -n $NAMESPACE $NAME |& less" + - "suspend-resume-hr.sh $CONTEXT $NAMESPACE $NAME" #--- Suspend/reconcile selected kustomization in current namespace toggle-kustomization: shortCut: Shift-T diff --git a/tools/suspend-resume-hr.sh b/tools/suspend-resume-hr.sh new file mode 100755 index 0000000..fa648bd --- /dev/null +++ b/tools/suspend-resume-hr.sh @@ -0,0 +1,39 @@ +#!/bin/bash +#=========================================================================== +# Suspend/resume k9s selected helm release +#=========================================================================== + +context="$1" +namespace="$2" +name="$3" +LOG_FILE="/tmp/resume-hr-${context}-${namespace}-${name}.log" + +#--- Check if helmrelease is suspended +status="$(kubectl get helmreleases --context ${context} --namespace ${namespace} ${name} -o=custom-columns=TYPE:.spec.suspend | tail -1)" +if [ "${status}" = "true" ] ; then + printf "\n%bResuming \"${name}\" helmrelease in \"${namespace}\" namespace...%b\n" "${REVERSE}${YELLOW}" "${STD}" + printf "$(date +%H:%M:%S) => Resuming \"${name}\" helmrelease in \"${namespace}\" namespace\n" > ${LOG_FILE} + nohup flux resume hr ${name} --namespace ${namespace} >> ${LOG_FILE} 2>&1 & + background_pid="$!" + tail -f ${LOG_FILE} & + display_pid="$!" + + #--- Wait 10s for resuming end task + sleep 5 + check_pid="$(ps ${background_pid} | grep -v "PID")" + if [ "${check_pid}" != "" ] ; then + sleep 5 + check_pid="$(ps ${background_pid} | grep -v "PID")" + if [ "${check_pid}" != "" ] ; then + printf "\n%bResuming \"${name}\" helmrelease exceeded 10s delay.%b\n" "${REVERSE}${YELLOW}" "${STD}" + printf "\n%bYou can follow resuming in \"${LOG_FILE}\" file.%b" "${YELLOW}" "${STD}" + fi + fi + + kill ${display_pid} +else + printf "\n%bSuspending \"${name}\" helmrelease in \"${namespace}\" namespace...%b\n" "${REVERSE}${YELLOW}" "${STD}" + flux suspend hr ${name} --namespace ${namespace} +fi + +printf "\n%bPress \"Enter\" to quit...%b " "${YELLOW}" "${STD}" ; read next