-
Notifications
You must be signed in to change notification settings - Fork 29
enhanced script to be able to support waiting for stateful sets #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
christiangroth
wants to merge
3
commits into
timoreimann:master
Choose a base branch
from
christiangroth:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,20 +45,20 @@ get_updated_replicas() { | |
get_deployment_jsonpath '{.status.updatedReplicas}' | ||
} | ||
|
||
get_available_replicas() { | ||
get_deployment_jsonpath '{.status.availableReplicas}' | ||
get_ready_replicas() { | ||
get_deployment_jsonpath '{.status.readyReplicas}' | ||
} | ||
|
||
get_deployment_jsonpath() { | ||
local -r jsonpath="$1" | ||
|
||
kubectl --namespace "${namespace}" get deployment "${deployment}" -o "jsonpath=${jsonpath}" | ||
kubectl --namespace "${namespace}" get "${deployment}" -o "jsonpath=${jsonpath}" | ||
} | ||
|
||
display_usage_and_exit() { | ||
echo "Usage: $(basename "$0") [-n <namespace>] [-t <timeout>] <deployment>" >&2 | ||
echo "Usage: $(basename "$0") [-n <namespace>] [-t <timeout>] [deployment|statefulset]/<resource-name>" >&2 | ||
echo "Arguments:" >&2 | ||
echo "deployment REQUIRED: The name of the deployment the script should wait on" >&2 | ||
echo "[deployment/statefulset]/resource-name REQUIRED: The type and name of the resource the script should wait on. Currently deployment and statefulset are supported." >&2 | ||
echo "-n OPTIONAL: The namespace the deployment exists in, defaults is the 'default' namespace" >&2 | ||
echo "-t OPTIONAL: How long to wait for the deployment to be available, defaults to ${DEFAULT_TIMEOUT} seconds, must be greater than 0" >&2 | ||
exit 1 | ||
|
@@ -77,16 +77,26 @@ do | |
done | ||
|
||
shift $((OPTIND-1)) | ||
if [ "$#" -ne 1 ] ; then | ||
if [ "$#" -ne 1 ] ; then | ||
display_usage_and_exit | ||
fi | ||
readonly deployment="$1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you re-apply the readonly declaration after line 92 (after which we do not need to mutate the variable again AFAIU)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed :) |
||
deployment="$1" | ||
|
||
if [[ ${timeout} -le 0 ]]; then | ||
display_usage_and_exit | ||
fi | ||
|
||
echo "Waiting for deployment of ${deployment} in namespace ${namespace} with a timeout ${timeout} seconds" | ||
# add deployment as type if no type specified (backwards compatibility) | ||
if ! [[ $deployment =~ .*/.* ]]; then | ||
deployment="deployment/$deployment" | ||
fi | ||
readonly deployment="$deployment" | ||
|
||
if [[ ! $deployment =~ deployment\/.* ]] && [[ ! $deployment =~ statefulset\/.* ]]; then | ||
display_usage_and_exit | ||
fi | ||
|
||
echo "Waiting for ${deployment} in namespace ${namespace} with a timeout ${timeout} seconds" | ||
|
||
monitor_timeout $$ & | ||
readonly timeout_monitor_pid=$! | ||
|
@@ -96,7 +106,7 @@ trap 'kill -- -${timeout_monitor_pid}' EXIT #Stop timeout monitor | |
generation=$(get_generation); readonly generation | ||
current_generation=$(get_observed_generation) | ||
|
||
echo "Expected generation for deployment ${deployment}: ${generation}" | ||
echo "Expected generation for ${deployment}: ${generation}" | ||
while [[ ${current_generation} -lt ${generation} ]]; do | ||
sleep .5 | ||
echo "Currently observed generation: ${current_generation}" | ||
|
@@ -109,14 +119,14 @@ echo "Specified replicas: ${specified_replicas}" | |
|
||
current_replicas=$(get_replicas) | ||
updated_replicas=$(get_updated_replicas) | ||
available_replicas=$(get_available_replicas) | ||
ready_replicas=$(get_ready_replicas) | ||
|
||
while [[ ${updated_replicas} -lt ${specified_replicas} || ${current_replicas} -gt ${updated_replicas} || ${available_replicas} -lt ${updated_replicas} ]]; do | ||
sleep .5 | ||
echo "current/updated/available replicas: ${current_replicas}/${updated_replicas}/${available_replicas}, waiting" | ||
while [[ ${updated_replicas} -lt ${specified_replicas} || ${current_replicas} -gt ${updated_replicas} || ${ready_replicas} -lt ${updated_replicas} ]]; do | ||
sleep 5 | ||
echo "${deployment} current/updated/ready replicas: ${current_replicas}/${updated_replicas}/${ready_replicas}, waiting" | ||
current_replicas=$(get_replicas) | ||
updated_replicas=$(get_updated_replicas) | ||
available_replicas=$(get_available_replicas) | ||
ready_replicas=$(get_ready_replicas) | ||
done | ||
|
||
echo "Deployment ${deployment} successful. All ${available_replicas} replicas are ready." | ||
echo "Update of ${deployment} successful. All ${ready_replicas} replicas are ready." |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why you changed this from available to ready? Apologies, it's been a while since I looked into the exact logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because readyReplicas is available for both deployment and stateful sets and availableReplicas only for deployments. So using readyReplicas allows us checking deployments and stateful sets the same way.