Skip to content

Commit

Permalink
No, really wait for pods ready after scale/restart (#13)
Browse files Browse the repository at this point in the history
* wait for pods ready after scale/restart

* wait for pods ready after scale/restart
  • Loading branch information
jgreat authored May 23, 2022
1 parent 01e965a commit 4e18334
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,25 @@ then
is_set INPUT_OBJECT_NAME

replicas=$(k get -n "${INPUT_NAMESPACE}" "${INPUT_OBJECT_NAME}" -o=jsonpath='{.spec.replicas}{"\n"}')
echo "${INPUT_OBJECT_NAME} original scale: ${replicas}"
echo "-- ${INPUT_OBJECT_NAME} original scale: ${replicas}"

echo "Scale ${INPUT_OBJECT_NAME} to 0"
echo "-- Scale ${INPUT_OBJECT_NAME} to 0"
k scale -n "${INPUT_NAMESPACE}" "${INPUT_OBJECT_NAME}" --replicas=0 --timeout=5m

echo "Scale ${INPUT_OBJECT_NAME} to ${replicas}"
# Give a pause to wait for api to stabilize.
sleep 10

echo "-- Scale ${INPUT_OBJECT_NAME} to ${replicas}"
k scale -n "${INPUT_NAMESPACE}" "${INPUT_OBJECT_NAME}" --replicas="${replicas}" --timeout=5m

# Need to wait for pods to become healthy.
echo "--- Sleep 60 to wait for new pods to show up."
sleep 60

# Get pods by match labels - yeah jsonpath AND jq!
labels=$(k get -n "${INPUT_NAMESPACE}" "${INPUT_OBJECT_NAME}" -o=jsonpath='{.spec.selector.matchLabels}' | jq -r 'to_entries | .[] |= "\(.key)=\(.value)" | join(",")')

k wait -n "${INPUT_NAMESPACE}" --for=condition=Ready pod -l "${labels}" --timeout=15m
;;

pvcs-delete)
Expand Down

0 comments on commit 4e18334

Please sign in to comment.