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 <prasanna.kalever@redhat.com>
This commit is contained in:
Prasanna Kumar Kalever 2020-09-28 21:06:55 +05:30 committed by mergify[bot]
parent 29c78f97c0
commit 5d49247945

View File

@ -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"