From 527cb50583a2599823e1784b0c35deb1e8ad763a Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Fri, 22 Apr 2016 22:37:32 -0700 Subject: [PATCH] Demand at least go1.6 --- hack/lib/golang.sh | 59 +++++++++++++++++---------------- hack/lib/version.sh | 9 +---- hack/test-go.sh | 1 - hack/travis/install-std-race.sh | 30 ----------------- hack/update-gofmt.sh | 8 ++--- hack/verify-gofmt.sh | 8 ++--- pkg/kubectl/resource_printer.go | 5 +-- pkg/volume/util/io_util.go | 3 +- 8 files changed, 37 insertions(+), 86 deletions(-) delete mode 100755 hack/travis/install-std-race.sh diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh index 175ef361fcb..0aa1a3d3d95 100755 --- a/hack/lib/golang.sh +++ b/hack/lib/golang.sh @@ -253,6 +253,33 @@ kube::golang::create_gopath_tree() { ln -s "${KUBE_ROOT}" "${go_pkg_dir}" } +# Ensure the go tool exists and is a viable version. +kube::golang::verify_go_version() { + if [[ -z "$(which go)" ]]; then + kube::log::usage_from_stdin </dev/null go test -c \ "${goflags[@]:+${goflags[@]}}" \ -ldflags "${goldflags}" \ + -o "${outfile}" \ "$(dirname ${test})" - popd >/dev/null done } diff --git a/hack/lib/version.sh b/hack/lib/version.sh index c8cf6f6de31..ed19dd5a2f1 100644 --- a/hack/lib/version.sh +++ b/hack/lib/version.sh @@ -107,18 +107,11 @@ kube::version::load_version_vars() { source "${version_file}" } -# golang 1.5+ wants `-X key=val`, but golang 1.4- REQUIRES `-X key val` kube::version::ldflag() { local key=${1} local val=${2} - GO_VERSION=($(go version)) - - if [[ -n $(echo "${GO_VERSION[2]}" | grep -E 'go1.1|go1.2|go1.3|go1.4') ]]; then - echo "-X ${KUBE_GO_PACKAGE}/pkg/version.${key} ${val}" - else - echo "-X ${KUBE_GO_PACKAGE}/pkg/version.${key}=${val}" - fi + echo "-X ${KUBE_GO_PACKAGE}/pkg/version.${key}=${val}" } # Prints the value that needs to be passed to the -ldflags parameter of go build diff --git a/hack/test-go.sh b/hack/test-go.sh index 052dbc1fcd1..35c769ab838 100755 --- a/hack/test-go.sh +++ b/hack/test-go.sh @@ -46,7 +46,6 @@ kube::test::find_dirs() { ) } -# -covermode=atomic becomes default with -race in Go >=1.3 KUBE_TIMEOUT=${KUBE_TIMEOUT:--timeout 120s} KUBE_COVER=${KUBE_COVER:-n} # set to 'y' to enable coverage collection KUBE_COVERMODE=${KUBE_COVERMODE:-atomic} diff --git a/hack/travis/install-std-race.sh b/hack/travis/install-std-race.sh deleted file mode 100755 index 38c30bd45e8..00000000000 --- a/hack/travis/install-std-race.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -# Copyright 2014 The Kubernetes Authors All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This script installs std -race on Travis (see https://code.google.com/p/go/issues/detail?id=6479) - -set -o errexit -set -o nounset -set -o pipefail - -if [[ "${TRAVIS}" == "true" ]]; then - GO_VERSION=($(go version)) - - if [[ ${GO_VERSION[2]} < "go1.3" ]]; then - echo "Installing the -race compatible version of the std go library" - go install -a -race std - fi -fi diff --git a/hack/update-gofmt.sh b/hack/update-gofmt.sh index f6c380c2e48..8d67656ae05 100755 --- a/hack/update-gofmt.sh +++ b/hack/update-gofmt.sh @@ -21,13 +21,9 @@ set -o nounset set -o pipefail KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "${KUBE_ROOT}/hack/lib/init.sh" -GO_VERSION=($(go version)) - -if [[ -n $(echo "${GO_VERSION[2]}" | grep -E 'go1.1|go1.2|go1.3') ]]; then - echo "Unsupported go version '${GO_VERSION}', skipping gofmt." - exit 0 -fi +kube::golang::verify_go_version cd "${KUBE_ROOT}" diff --git a/hack/verify-gofmt.sh b/hack/verify-gofmt.sh index 91207061743..b848b1eb959 100755 --- a/hack/verify-gofmt.sh +++ b/hack/verify-gofmt.sh @@ -21,13 +21,9 @@ set -o nounset set -o pipefail KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "${KUBE_ROOT}/hack/lib/init.sh" -GO_VERSION=($(go version)) - -if [[ -z $(echo "${GO_VERSION[2]}" | grep -E 'go1.4|go1.6') ]]; then - echo "Unsupported go version '${GO_VERSION[2]}', skipping gofmt." - exit 1 -fi +kube::golang::verify_go_version cd "${KUBE_ROOT}" diff --git a/pkg/kubectl/resource_printer.go b/pkg/kubectl/resource_printer.go index 692d2c78c1c..59533ccec82 100644 --- a/pkg/kubectl/resource_printer.go +++ b/pkg/kubectl/resource_printer.go @@ -1739,10 +1739,7 @@ func appendAllLabels(showLabels bool, itemLabels map[string]string) string { func appendLabelTabs(columnLabels []string) string { var buffer bytes.Buffer - for i := range columnLabels { - // NB: This odd dance is to make the loop both compatible with go 1.3 and - // pass `gofmt -s` - _ = i + for range columnLabels { buffer.WriteString("\t") } buffer.WriteString("\n") diff --git a/pkg/volume/util/io_util.go b/pkg/volume/util/io_util.go index 95acbe94109..309a408f5c0 100644 --- a/pkg/volume/util/io_util.go +++ b/pkg/volume/util/io_util.go @@ -22,8 +22,7 @@ import ( "path/filepath" ) -//IoUtil is a util for common IO operations -//it also backports certain operations from golang 1.5 +// IoUtil is a mockable util for common IO operations type IoUtil interface { ReadDir(dirname string) ([]os.FileInfo, error) Lstat(name string) (os.FileInfo, error)