Skip to content

Commit

Permalink
Merge pull request #3767 from uselagoon/ssh-unidling-refactor
Browse files Browse the repository at this point in the history
refactor: support lagoon.sh idling changes in ssh
  • Loading branch information
tobybellwood authored Sep 2, 2024
2 parents 7476383 + 034449d commit 85f3698
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions services/ssh/home/rsh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ if [[ $($KUBECTL get deployment -l "lagoon.sh/service=${SERVICE}" 2> /dev/null)
# get any other deployments that may have been idled and unidle them if required
# this only needs to be done for kubernetes
# we do this first to give the services a bit of time to unidle before starting the one that was requested
DEPLOYMENTS=$($KUBECTL get deployments -l "idling.amazee.io/watch=true" -o name)
DEPLOYMENTS=$($KUBECTL get deployments -l "idling.lagoon.sh/watch=true" -o name)
if [ -z "${DEPLOYMENTS}" ]; then
DEPLOYMENTS=$($KUBECTL get deployments -l "idling.amazee.io/watch=true" -o name)
fi
if [ ! -z "${DEPLOYMENTS}" ]; then
echo "${UUID}: Environment is idled attempting to scale up for project='${PROJECT}' cluster='${CLUSTER_NAME}' service='${SERVICE}'" >> /proc/1/fd/1
# loop over the deployments and unidle them
Expand All @@ -138,8 +141,12 @@ if [[ $($KUBECTL get deployment -l "lagoon.sh/service=${SERVICE}" 2> /dev/null)
# if the deployment is idled, unidle it :)
DEP_JSON=$($KUBECTL get ${DEP} -o json)
if [ $(echo "$DEP_JSON" | jq -r '.status.replicas // 0') == "0" ]; then
REPLICAS=$(echo "$DEP_JSON" | jq -r '.metadata.annotations."idling.amazee.io/unidle-replicas" // 1')
if [ ! -z "$REPLICAS" ]; then
REPLICAS=$(echo "$DEP_JSON" | jq -r '.metadata.annotations."idling.lagoon.sh/unidle-replicas" // 1')
if [ -z "$REPLICAS" ]; then
REPLICAS=$(echo "$DEP_JSON" | jq -r '.metadata.annotations."idling.amazee.io/unidle-replicas" // 1')
fi
# if no replicas in annotations, set 1
if [ -z "$REPLICAS" ]; then
REPLICAS=1
fi
echo "${UUID}: Attempting to scale deployment='${DEP}' for project='${PROJECT}' cluster='${CLUSTER_NAME}' service='${SERVICE}'" >> /proc/1/fd/1
Expand Down

0 comments on commit 85f3698

Please sign in to comment.