diff --git a/hack/local-up-karmada.sh b/hack/local-up-karmada.sh index 6e3d42c13..164d9aa26 100755 --- a/hack/local-up-karmada.sh +++ b/hack/local-up-karmada.sh @@ -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 diff --git a/hack/update-vendor.sh b/hack/update-vendor.sh index 73c1dce8e..70a295345 100755 --- a/hack/update-vendor.sh +++ b/hack/update-vendor.sh @@ -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 diff --git a/hack/util.sh b/hack/util.sh index a76396139..77133384c 100755 --- a/hack/util.sh +++ b/hack/util.sh @@ -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}