Skip to content

Commit

Permalink
Improve snapshot pod running checks and improve version_gt
Browse files Browse the repository at this point in the history
Signed-off-by: Grant Griffiths <grant@portworx.com>
  • Loading branch information
ggriffiths committed Dec 4, 2019
1 parent 6d674a7 commit 4ad6949
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions prow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -713,10 +713,11 @@ install_snapshot_controller() {

kubectl apply -f "https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/${CSI_SNAPSHOTTER_VERSION}/deploy/kubernetes/snapshot-controller/setup-snapshot-controller.yaml"
cnt=0
until kubectl get statefulset snapshot-controller | grep snapshot-controller | grep "1/1"; do
expected_running_pods=$(curl https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/"${CSI_SNAPSHOTTER_VERSION}"/deploy/kubernetes/snapshot-controller/setup-snapshot-controller.yaml | grep replicas | cut -d ':' -f 2-)
while [ "$(kubectl get pods -l app=snapshot-controller | grep 'Running' -c)" -lt "$expected_running_pods" ]; do
if [ $cnt -gt 30 ]; then
echo "Running statefulsets:"
kubectl describe statefulsets
echo "snapshot-controller pod status:"
kubectl describe pods -l app=snapshot-controller
echo >&2 "ERROR: snapshot controller not ready after over 5 min"
exit 1
fi
Expand Down Expand Up @@ -996,8 +997,30 @@ make_test_to_junit () {
fi
}

# version_gt returns true if arg1 is greater than arg2.
#
# This function expects versions to be one of the following formats:
# X.Y.Z, release-X.Y.Z, vX.Y.Z
#
# where X,Y, and Z are any number.
#
# Partial versions (1.2, release-1.2) work as well.
# The follow substrings are stripped before version comparison:
# - "v"
# - "release-"
#
# Usage:
# version_gt release-1.3 v1.2.0 (returns true)
# version_gt v1.1.1 v1.2.0 (returns false)
# version_gt 1.1.1 v1.2.0 (returns false)
# version_gt 1.3.1 v1.2.0 (returns true)
# version_gt 1.1.1 release-1.2.0 (returns false)
# version_gt 1.2.0 1.2.2 (returns false)
function version_gt() {
test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1";
versions=$(for ver in "$@"; do ver=${ver#release-}; echo "${ver#v}"; done)
greaterVersion=${1#"release-"};
greaterVersion=${greaterVersion#"v"};
test "$(printf '%s' "$versions" | sort -V | head -n 1)" != "$greaterVersion"
}

main () {
Expand Down

0 comments on commit 4ad6949

Please sign in to comment.