From 5d4924794554f347f3d16750f3c6090291fb0f33 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Mon, 28 Sep 2020 21:06:55 +0530 Subject: [PATCH] e2e: defend on k8s version for snap-controller install Currently the scripts/install-snapshot.sh script needs to be called depending on the Kubernetes version. It would be much easier to use the script if it is intelligent enough to decide itself whether k8s snapshot controller needs to be installed or not. Fixes: #1139 Signed-off-by: Prasanna Kumar Kalever --- scripts/install-snapshot.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/scripts/install-snapshot.sh b/scripts/install-snapshot.sh index 72e25dfcb..4bbc96976 100755 --- a/scripts/install-snapshot.sh +++ b/scripts/install-snapshot.sh @@ -77,6 +77,30 @@ function delete_snapshot_crd() { kubectl delete -f "${VOLUME_SNAPSHOT}" --ignore-not-found } +# parse the kubernetes version +# v1.17.2 -> kube_version 1 -> 1 (Major) +# v1.17.2 -> kube_version 2 -> 17 (Minor) +function kube_version() { + echo "${KUBE_VERSION}" | sed 's/^v//' | cut -d'.' -f"${1}" +} + +if ! get_kube_version=$(kubectl version --short) || + [[ -z "${get_kube_version}" ]]; then + echo "could not get Kubernetes server version" + echo "hint: check if you have specified the right host or port" + exit 1 +fi + +KUBE_VERSION=$(echo "${get_kube_version}" | grep "^Server Version" | cut -d' ' -f3) +KUBE_MAJOR=$(kube_version 1) +KUBE_MINOR=$(kube_version 2) + +# skip snapshot operation if kube version is less than 1.17.0 +if [[ "${KUBE_MAJOR}" -lt 1 ]] || [[ "${KUBE_MAJOR}" -eq 1 && "${KUBE_MINOR}" -lt 17 ]]; then + echo "skipping: Kubernetes server version is < 1.17.0" + exit 1 +fi + case "${1:-}" in install) install_snapshot_controller "$2"