Skip to content

Commit

Permalink
app-serving: check preview-endpoint, too
Browse files Browse the repository at this point in the history
  • Loading branch information
robertchoi80 committed Jun 15, 2023
1 parent 655ae46 commit d43ea9b
Showing 1 changed file with 42 additions and 30 deletions.
72 changes: 42 additions & 30 deletions app_serving/serve-java-app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ spec:
#==========================================================
# function: check_rollout_replicas (when rolling-update)
# function: check_rollout_replicas (for rolling-update)
#==========================================================
function check_rollout_replicas() {
# Check num of replicas
Expand Down Expand Up @@ -480,6 +480,33 @@ spec:
fi
}
#==========================================================
# function: check_endpoint
#==========================================================
function check_endpoint() {
ep=$1
ep_ready=false
echo "Checking if endpoint ${ep} is reachable.." | tee -a $DEPLOY_LOG
for i in `seq 1 20`
do
stat_code=$(curl -o /dev/null -w "%{http_code}" http://${ep} || true)
if [ $stat_code -eq 200 ]; then
echo "Confirmed that the endpoint is reachable." | tee -a $DEPLOY_LOG
ep_ready=true
break
else
echo "Waiting for endpoint to be reachable.. sleeping 3 secs.." | tee -a $DEPLOY_LOG
sleep 3
fi
done
if [ "$ep_ready" = false ]; then
echo "Timed out waiting for endpoint to be reachable.." | tee -a $DEPLOY_LOG
exit 1
fi
}
#==========================================================
Expand Down Expand Up @@ -623,6 +650,7 @@ spec:
echo "Waiting for the deployment to be finished..." | tee -a $DEPLOY_LOG
kubectl wait --for=condition=Available --timeout=300s -n {{workflow.parameters.namespace}} deploy/{{workflow.parameters.app_name}} 2> >(tee -a $DEPLOY_LOG >&2)
echo "The deployment is ready now." | tee -a $DEPLOY_LOG
# Writing helm release info to file.
revision=$(helm history {{workflow.parameters.app_name}} --kubeconfig /etc/kubeconfig_temp -n {{workflow.parameters.namespace}} | grep deployed | cut -d' ' -f1)
Expand Down Expand Up @@ -655,9 +683,7 @@ spec:
check_rollout_phase "Healthy" "Healthy"
echo "Rollout status has changed to 'Healthy'. Checking replicas.." | tee -a $DEPLOY_LOG
check_rollout_replicas
elif [[ "$strategy" == "blue-green" ]]; then
check_rollout_phase "Paused" "Paused"
elif [[ "$strategy" == "canary" ]]; then
elif [[ "$strategy" == "blue-green" ]] || [[ "$strategy" == "canary" ]]; then
check_rollout_phase "Paused" "Paused"
fi
Expand All @@ -667,10 +693,6 @@ spec:
#==========================================================
# write endpoints to file
#==========================================================
# TODO: only do this in blue-green case??
# Writing preview-svc endpoint to file
kubectl get svc ${app_name}-preview -n {{workflow.parameters.namespace}} -o jsonpath='{.status.loadBalancer.ingress[0].hostname}' > /mnt/out/preview_endpoint
# Writing endpoint to file
ep=$(kubectl get svc {{workflow.parameters.app_name}} -n {{workflow.parameters.namespace}} -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
Expand All @@ -680,28 +702,7 @@ spec:
else
echo $ep > /mnt/out/endpoint
fi
#==========================================================
# Check if endpoint is actually reachable
#==========================================================
ep_ready=false
for i in `seq 1 20`
do
stat_code=$(curl -o /dev/null -w "%{http_code}" http://${ep} || true)
if [ $stat_code -eq 200 ]; then
echo "Confirmed that endpoint is reachable." | tee -a $DEPLOY_LOG
ep_ready=true
break
else
echo "Waiting for endpoint to be reachable.. sleeping 3 secs.." | tee -a $DEPLOY_LOG
sleep 3
fi
done
if [ "$ep_ready" = false ]; then
echo "Timed out waiting for endpoint to be reachable.." | tee -a $DEPLOY_LOG
exit 1
fi
check_endpoint $ep
#==========================================================
# Write deploy status to file
Expand All @@ -713,6 +714,17 @@ spec:
# Write deployment status to file for next step
echo "DEPLOY_SUCCESS" > /mnt/out/deploy_status
elif [[ "$strategy" == "blue-green" ]]; then
# Writing preview-svc endpoint to file
prv_ep=$(kubectl get svc ${app_name}-preview -n {{workflow.parameters.namespace}} -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
if [ -z "$prv_ep" ]; then
echo "Couldn't get preview-endpoint url. Exiting.." | tee -a $DEPLOY_LOG
exit 1
else
echo $ep > /mnt/out/preview_endpoint
fi
echo "Checking preview endpoint.." | tee -a $DEPLOY_LOG
check_endpoint $prv_ep
# Write deployment status to file for next step
echo "PROMOTE_WAIT" > /mnt/out/deploy_status
elif [[ "$strategy" == "canary" ]]; then
Expand Down

0 comments on commit d43ea9b

Please sign in to comment.