Skip to content

Commit

Permalink
Improve snapshot-controller running check and improve version_gt
Browse files Browse the repository at this point in the history
Signed-off-by: Grant Griffiths <[email protected]>
  • Loading branch information
ggriffiths committed Dec 4, 2019
1 parent 6d674a7 commit b2b27e1
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions prow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -583,19 +583,6 @@ EOF
export KUBECONFIG
}

# Deletes kind cluster inside a prow job
delete_cluster_inside_prow_job() {
# Inside a real Prow job it is better to clean up at runtime
# instead of leaving that to the Prow job cleanup code
# because the later sometimes times out (https://github.com/kubernetes-csi/csi-release-tools/issues/24#issuecomment-554765872).
if [ "$JOB_NAME" ]; then
if kind get clusters | grep -q csi-prow; then
run kind delete cluster --name=csi-prow || die "kind delete failed"
fi
unset KUBECONFIG
fi
}

# Looks for the deployment as specified by CSI_PROW_DEPLOYMENT and CSI_PROW_KUBERNETES_VERSION
# in the given directory.
find_deployment () {
Expand Down Expand Up @@ -713,10 +700,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 @@ -977,8 +965,7 @@ make_test_to_junit () {
if [ "$testname" ]; then
# Test output.
echo "$line" | ascii_to_xml >>"$out"
testoutput="$testoutput$line
"
testoutput="$testoutput$line"
fi
fi
done
Expand All @@ -996,8 +983,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 Expand Up @@ -1100,7 +1109,6 @@ main () {
fi
fi
fi
delete_cluster_inside_prow_job
fi

if tests_need_alpha_cluster && [ "${CSI_PROW_E2E_ALPHA_GATES}" ]; then
Expand Down Expand Up @@ -1141,7 +1149,6 @@ main () {
fi
fi
fi
delete_cluster_inside_prow_job
fi
fi

Expand Down

0 comments on commit b2b27e1

Please sign in to comment.