From fd7e73adc33761e4918050b21e492b09af05982c Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Tue, 23 Feb 2021 12:04:49 +1100 Subject: [PATCH] scaled deployments in k8s appear to not set `.status.replicas` like openshift deploymentconfigs, so if it returns a null value, assume 0 --- services/ssh/home/rsh.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/ssh/home/rsh.sh b/services/ssh/home/rsh.sh index bca59a114c..09b1816965 100755 --- a/services/ssh/home/rsh.sh +++ b/services/ssh/home/rsh.sh @@ -122,7 +122,8 @@ fi if [[ $($OC get deployment -l "lagoon.sh/service=${SERVICE}" 2> /dev/null) ]]; then DEPLOYMENT=$($OC get deployment -l "lagoon.sh/service=${SERVICE}" -o name) # If the deployment is scaled to 0, scale to 1 - if [[ $($OC get ${DEPLOYMENT} -o go-template --template='{{.status.replicas}}') == "0" ]]; then + # .status.replicas doesn't exist on a scaled to 0 deployment in k8s so assume it is 0 if nothing is returned + if [[ $($OC get ${DEPLOYMENT} -o json | jq -r '.status.replicas // 0') == "0" ]]; then $OC scale --replicas=1 ${DEPLOYMENT} >/dev/null 2>&1 @@ -139,7 +140,8 @@ fi if [[ $($OC get deployment -l lagoon/service=${SERVICE} 2> /dev/null) ]]; then DEPLOYMENT=$($OC get deployment -l lagoon/service=${SERVICE} -o name) # If the deployment is scaled to 0, scale to 1 - if [[ $($OC get ${DEPLOYMENT} -o go-template --template='{{.status.replicas}}') == "0" ]]; then + # .status.replicas doesn't exist on a scaled to 0 deployment in k8s so assume it is 0 if nothing is returned + if [[ $($OC get ${DEPLOYMENT} -o json | jq -r '.status.replicas // 0') == "0" ]]; then $OC scale --replicas=1 ${DEPLOYMENT} >/dev/null 2>&1