From c0c62821d789deeb1986f8505938a27145e4a7ca Mon Sep 17 00:00:00 2001 From: Christoph Blecker Date: Thu, 1 Feb 2018 15:19:15 -0800 Subject: [PATCH] Install ensured godep inside hermetic GOPATH --- hack/lib/util.sh | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/hack/lib/util.sh b/hack/lib/util.sh index 099abc5502..e5172b550a 100755 --- a/hack/lib/util.sh +++ b/hack/lib/util.sh @@ -441,28 +441,35 @@ kube::util::ensure_clean_working_dir() { # Ensure that the given godep version is installed and in the path. Almost # nobody should use any version but the default. +# +# Sets: +# KUBE_GODEP: The path to the godep binary +# kube::util::ensure_godep_version() { - GODEP_VERSION=${1:-"v80"} # this version is known to work + local godep_target_version=${1:-"v80-k8s-r1"} # this version is known to work - if [[ "$(godep version 2>/dev/null)" == *"godep ${GODEP_VERSION}"* ]]; then + # If KUBE_GODEP is already set, and it's the right version, then use it. + if [[ -n "${KUBE_GODEP:-}" && "$(${KUBE_GODEP:?} version 2>/dev/null)" == *"godep ${godep_target_version}"* ]]; then + kube::log::status "Using ${KUBE_GODEP}" return fi - kube::log::status "Installing godep version ${GODEP_VERSION}" - go install k8s.io/kubernetes/vendor/github.com/tools/godep/ - if ! which godep >/dev/null 2>&1; then - kube::log::error "Can't find godep - is your GOPATH 'bin' in your PATH?" - kube::log::error " GOPATH: ${GOPATH}" - kube::log::error " PATH: ${PATH}" - return 1 + # If GODEP is in the path, then use it. + if [[ "$(godep version 2>/dev/null)" == *"godep ${godep_target_version}"* ]]; then + export KUBE_GODEP="$(which godep)" + kube::log::status "Using ${KUBE_GODEP}" + return fi - if [[ "$(godep version 2>/dev/null)" != *"godep ${GODEP_VERSION}"* ]]; then - kube::log::error "Wrong godep version - is your GOPATH 'bin' in your PATH?" - kube::log::error " expected: godep ${GODEP_VERSION}" - kube::log::error " got: $(godep version)" - kube::log::error " GOPATH: ${GOPATH}" - kube::log::error " PATH: ${PATH}" + kube::log::status "Installing godep version ${godep_target_version}" + # Run in hermetic GOPATH + kube::golang::setup_env + go install k8s.io/kubernetes/third_party/forked/godep + export KUBE_GODEP="${KUBE_GOPATH}/bin/godep" + kube::log::status "Installed ${KUBE_GODEP}" + + if [[ "$(${KUBE_GODEP:?} version 2>/dev/null)" != *"godep ${godep_target_version}"* ]]; then + kube::log::error "Expected godep ${godep_target_version} from ${KUBE_GODEP}, got $(${KUBE_GODEP:?} version)" return 1 fi }