Skip to content

Commit

Permalink
fix issue #146
Browse files Browse the repository at this point in the history
  • Loading branch information
ogrand committed Dec 5, 2023
1 parent 2f59a03 commit 7adcc6e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tools/k9s-plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions tools/suspend-resume-hr.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7adcc6e

Please sign in to comment.