Skip to content

Commit

Permalink
Use rollout status command to wait for a succesful build
Browse files Browse the repository at this point in the history
  • Loading branch information
leonidlm committed Feb 1, 2017
1 parent 8e069a5 commit 2097d5e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ parameters and configuration of your application.

The following env variables control the deployment configuration:

1. KUBERNETES_DEPLOYMENT_ATTEMPTS - How many times the deployment process should
check for a succesful status before failing. Defaults is 10.
1. KUBERNETES_DEPLOYMENT_TIMEOUT - How much to wait for a successful deployment
before failing the build. Defaults to 120 (secs).
2. KUBERNETES_USER - The user for the Kubernetes cluster. Mandatory.
3. KUBERNETES_PASSWORD - The password for the Kubernetes cluster. Mandatory.
4. KUBERNETES_SERVER - The server (HTTPS endpoint) of the Kubernetes cluster's
Expand Down
24 changes: 3 additions & 21 deletions cf-deploy-kubernetes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ readonly DEFAULT_NAMESPACE=default

deployment_file=${1:-deployment.yml}

: ${KUBERNETES_DEPLOYMENT_ATTEMPTS:=10}
: ${KUBERNETES_DEPLOYMENT_TIMEOUT:=120}

[ -z "$KUBERNETES_USER" ] && echo "Please set KUBERNETES_USER" && exit 1;
[ -z "$KUBERNETES_PASSWORD" ] && echo "Please set KUBERNETES_PASSWORD" && exit 1;
Expand Down Expand Up @@ -32,24 +32,6 @@ fi

echo "---> Waiting for a succesful deployment status..."

available=1
next_wait_time=0
until [ $available -eq 0 -o $next_wait_time -eq $KUBERNETES_DEPLOYMENT_ATTEMPTS ]; do

# Unfortunately, we can't use the `kubectl rollout status` command at the moment.
# The command won't wait until all the replicas are available until the following
# pull request will be merged:
# https://github.com/kubernetes/kubernetes/pull/31499
status=$(kubectl get -f $deployment_file -o jsonpath="{.status.Replicas} {.status.AvailableReplicas} {.status.UpdatedReplicas}")
updatedReplicas=$(echo $status | awk '{print $3}')
availableReplicas=$(echo $status | awk '{print $2}')
replicas=$(echo $status | awk '{print $1}')

echo "---> Current deployment status: updatedReplicas: $updatedReplicas, availableReplicas: $availableReplicas, totalReplicas: $replicas"
[ $updatedReplicas -eq $replicas -a $availableReplicas -eq $replicas ] && available=0 || available=1

sleep $(( next_wait_time++ ))
done

exit $available
timeout -s SIGTERM -t $KUBERNETES_DEPLOYMENT_TIMEOUT kubectl rollout status -f $deployment_file
exit $?

0 comments on commit 2097d5e

Please sign in to comment.