From d43ea9bdcd259c94f8e8f4316d9c88ccd1706762 Mon Sep 17 00:00:00 2001 From: Robert Choi Date: Thu, 15 Jun 2023 15:15:25 +0900 Subject: [PATCH] app-serving: check preview-endpoint, too --- app_serving/serve-java-app.yaml | 72 +++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/app_serving/serve-java-app.yaml b/app_serving/serve-java-app.yaml index d787a020..565e7a80 100644 --- a/app_serving/serve-java-app.yaml +++ b/app_serving/serve-java-app.yaml @@ -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 @@ -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 + } + #========================================================== @@ -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) @@ -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 @@ -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}') @@ -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 @@ -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