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"