add go version check

Signed-off-by: lihanbo <lihanbo2@huawei.com>
This commit is contained in:
lihanbo 2021-10-13 16:02:58 +08:00
parent c2030ca639
commit 064db4123b
3 changed files with 20 additions and 2 deletions

View File

@ -37,8 +37,10 @@ sed -i'' -e "s#k8s.gcr.io#registry.aliyuncs.com/google_containers#g" artifacts/d
sed -i'' -e "s#k8s.gcr.io#registry.aliyuncs.com/google_containers#g" artifacts/deploy/kube-controller-manager.yaml
fi
# Make sure go exists
# Make sure go exists and the go version is a viable version.
util::cmd_must_exist "go"
util::verify_go_version
# install kind and kubectl
kind_version=v0.11.1
if util::cmd_exist kind; then

View File

@ -4,7 +4,10 @@ set -o errexit
set -o nounset
set -o pipefail
# TODO(RainbowMango): checks if the Go version is greater than the minimum go version that we requires.
REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${REPO_ROOT}"/hack/util.sh
util::verify_go_version
echo "vendor: running 'go mod vendor'"
go mod vendor

View File

@ -15,6 +15,8 @@ KARMADA_SCHEDULER_LABEL="karmada-scheduler"
KARMADA_WEBHOOK_LABEL="karmada-webhook"
AGENT_POD_LABEL="karmada-agent"
MIN_Go_VERSION=go1.16.0
# This function installs a Go tools by 'go get' command.
# Parameters:
# - $1: package name, such as "sigs.k8s.io/controller-tools/cmd/controller-gen"
@ -53,6 +55,17 @@ function util::cmd_must_exist {
fi
}
function util::verify_go_version {
local go_version
IFS=" " read -ra go_version <<< "$(GOFLAGS='' go version)"
if [[ "${MIN_Go_VERSION}" != $(echo -e "${MIN_Go_VERSION}\n${go_version[2]}" | sort -s -t. -k 1,1 -k 2,2n -k 3,3n | head -n1) && "${go_version[2]}" != "devel" ]]; then
echo "Detected go version: ${go_version[*]}."
echo "Karmada requires ${MIN_Go_VERSION} or greater."
echo "Please install ${MIN_Go_VERSION} or later."
exit 1
fi
}
# util::cmd_must_exist_cfssl downloads cfssl/cfssljson if they do not already exist in PATH
function util::cmd_must_exist_cfssl {
CFSSL_VERSION=${1}