Skip to content

Commit

Permalink
Allow overriding go version when updating vendor
Browse files Browse the repository at this point in the history
This is required because Kubernetes 1.17 lists go1.12 in go.mod,
but it doesn't actually compile using go1.12.
  • Loading branch information
MaciekPytel committed Jul 24, 2020
1 parent 13a6e8e commit e607eb9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cluster-autoscaler/hack/update-vendor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ K8S_REV="master"
BATCH_MODE="false"
TARGET_MODULE=${TARGET_MODULE:-k8s.io/autoscaler/cluster-autoscaler}
VERIFY_COMMAND=${VERIFY_COMMAND:-"go test -mod=vendor ./..."}
OVERRIDE_GO_VERSION="false"

ARGS="$@"
OPTS=`getopt -o f::r::d::v::b:: --long k8sfork::,k8srev::,workdir::,batch:: -n $SCRIPT_NAME -- "$@"`
OPTS=`getopt -o f::r::d::v::b::o:: --long k8sfork::,k8srev::,workdir::,batch::,override-go-version:: -n $SCRIPT_NAME -- "$@"`
if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi
eval set -- "$OPTS"
while true; do
Expand All @@ -32,6 +33,7 @@ while true; do
-r | --k8srev ) K8S_REV="$2"; shift; shift ;;
-d | --workdir ) WORK_DIR="$2"; shift; shift ;;
-b | --batch ) BATCH_MODE="true"; shift; shift ;;
-o | --override-go-version) OVERRIDE_GO_VERSION="true"; shift; shift ;;
-v ) VERBOSE=1; shift; if [[ "$1" == "v" ]]; then VERBOSE=2; shift; fi; ;;
-- ) shift; break ;;
* ) break ;;
Expand Down Expand Up @@ -109,8 +111,13 @@ set +o errexit
REQUIRED_GO_VERSION=$(cat go.mod |grep '^go ' |tr -s ' ' |cut -d ' ' -f 2)
USED_GO_VERSION=$(go version |sed 's/.*go\([0-9]\+\.[0-9]\+\).*/\1/')


if [[ "${REQUIRED_GO_VERSION}" != "${USED_GO_VERSION}" ]];then
err_rerun "Invalid go version ${USED_GO_VERSION}; required go version is ${REQUIRED_GO_VERSION}."
if [[ "${OVERRIDE_GO_VERSION}" == "false" ]]; then
err_rerun "Invalid go version ${USED_GO_VERSION}; required go version is ${REQUIRED_GO_VERSION}."
else
echo "Overriding go version found in go.mod file. Expected go version ${REQUIRED_GO_VERSION}, using ${USED_GO_VERSION}"
fi
fi

# Fix module name and staging modules links
Expand Down

0 comments on commit e607eb9

Please sign in to comment.