Commit 527cb505 authored by Tim Hockin's avatar Tim Hockin

Demand at least go1.6

parent cbf886c7
...@@ -253,27 +253,14 @@ kube::golang::create_gopath_tree() { ...@@ -253,27 +253,14 @@ kube::golang::create_gopath_tree() {
ln -s "${KUBE_ROOT}" "${go_pkg_dir}" ln -s "${KUBE_ROOT}" "${go_pkg_dir}"
} }
# kube::golang::setup_env will check that the `go` commands is available in # Ensure the go tool exists and is a viable version.
# ${PATH}. If not running on Travis, it will also check that the Go version is kube::golang::verify_go_version() {
# good enough for the Kubernetes build.
#
# Inputs:
# KUBE_EXTRA_GOPATH - If set, this is included in created GOPATH
#
# Outputs:
# env-var GOPATH points to our local output dir
# env-var GOBIN is unset (we want binaries in a predictable place)
# env-var GO15VENDOREXPERIMENT=1
# current directory is within GOPATH
kube::golang::setup_env() {
kube::golang::create_gopath_tree
if [[ -z "$(which go)" ]]; then if [[ -z "$(which go)" ]]; then
kube::log::usage_from_stdin <<EOF kube::log::usage_from_stdin <<EOF
Can't find 'go' in PATH, please fix and retry. Can't find 'go' in PATH, please fix and retry.
See http://golang.org/doc/install for installation instructions. See http://golang.org/doc/install for installation instructions.
EOF EOF
exit 2 return 2
fi fi
# Travis continuous build uses a head go release that doesn't report # Travis continuous build uses a head go release that doesn't report
...@@ -282,15 +269,33 @@ EOF ...@@ -282,15 +269,33 @@ EOF
if [[ "${TRAVIS:-}" != "true" ]]; then if [[ "${TRAVIS:-}" != "true" ]]; then
local go_version local go_version
go_version=($(go version)) go_version=($(go version))
if [[ "${go_version[2]}" < "go1.4" ]]; then if [[ "${go_version[2]}" < "go1.6" ]]; then
kube::log::usage_from_stdin <<EOF kube::log::usage_from_stdin <<EOF
Detected go version: ${go_version[*]}. Detected go version: ${go_version[*]}.
Kubernetes requires go version 1.4 or greater. Kubernetes requires go version 1.6 or greater.
Please install Go version 1.4 or later. Please install Go version 1.6 or later.
EOF EOF
exit 2 return 2
fi fi
fi fi
}
# kube::golang::setup_env will check that the `go` commands is available in
# ${PATH}. If not running on Travis, it will also check that the Go version is
# good enough for the Kubernetes build.
#
# Inputs:
# KUBE_EXTRA_GOPATH - If set, this is included in created GOPATH
#
# Outputs:
# env-var GOPATH points to our local output dir
# env-var GOBIN is unset (we want binaries in a predictable place)
# env-var GO15VENDOREXPERIMENT=1
# current directory is within GOPATH
kube::golang::setup_env() {
kube::golang::verify_go_version
kube::golang::create_gopath_tree
export GOPATH=${KUBE_GOPATH} export GOPATH=${KUBE_GOPATH}
...@@ -441,16 +446,12 @@ kube::golang::build_binaries_for_platform() { ...@@ -441,16 +446,12 @@ kube::golang::build_binaries_for_platform() {
for test in "${tests[@]:+${tests[@]}}"; do for test in "${tests[@]:+${tests[@]}}"; do
local outfile=$(kube::golang::output_filename_for_binary "${test}" \ local outfile=$(kube::golang::output_filename_for_binary "${test}" \
"${platform}") "${platform}")
# Go 1.4 added -o to control where the binary is saved, but Go 1.3 doesn't
# have this flag. Whenever we deprecate go 1.3, update to use -o instead of
# changing into the output directory.
mkdir -p "$(dirname ${outfile})" mkdir -p "$(dirname ${outfile})"
pushd "$(dirname ${outfile})" >/dev/null
go test -c \ go test -c \
"${goflags[@]:+${goflags[@]}}" \ "${goflags[@]:+${goflags[@]}}" \
-ldflags "${goldflags}" \ -ldflags "${goldflags}" \
-o "${outfile}" \
"$(dirname ${test})" "$(dirname ${test})"
popd >/dev/null
done done
} }
......
...@@ -107,18 +107,11 @@ kube::version::load_version_vars() { ...@@ -107,18 +107,11 @@ kube::version::load_version_vars() {
source "${version_file}" source "${version_file}"
} }
# golang 1.5+ wants `-X key=val`, but golang 1.4- REQUIRES `-X key val`
kube::version::ldflag() { kube::version::ldflag() {
local key=${1} local key=${1}
local val=${2} local val=${2}
GO_VERSION=($(go version)) echo "-X ${KUBE_GO_PACKAGE}/pkg/version.${key}=${val}"
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
} }
# Prints the value that needs to be passed to the -ldflags parameter of go build # Prints the value that needs to be passed to the -ldflags parameter of go build
......
...@@ -46,7 +46,6 @@ kube::test::find_dirs() { ...@@ -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_TIMEOUT=${KUBE_TIMEOUT:--timeout 120s}
KUBE_COVER=${KUBE_COVER:-n} # set to 'y' to enable coverage collection KUBE_COVER=${KUBE_COVER:-n} # set to 'y' to enable coverage collection
KUBE_COVERMODE=${KUBE_COVERMODE:-atomic} KUBE_COVERMODE=${KUBE_COVERMODE:-atomic}
......
#!/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
...@@ -21,13 +21,9 @@ set -o nounset ...@@ -21,13 +21,9 @@ set -o nounset
set -o pipefail set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/hack/lib/init.sh"
GO_VERSION=($(go version)) kube::golang::verify_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
cd "${KUBE_ROOT}" cd "${KUBE_ROOT}"
......
...@@ -21,13 +21,9 @@ set -o nounset ...@@ -21,13 +21,9 @@ set -o nounset
set -o pipefail set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/hack/lib/init.sh"
GO_VERSION=($(go version)) kube::golang::verify_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
cd "${KUBE_ROOT}" cd "${KUBE_ROOT}"
......
...@@ -1739,10 +1739,7 @@ func appendAllLabels(showLabels bool, itemLabels map[string]string) string { ...@@ -1739,10 +1739,7 @@ func appendAllLabels(showLabels bool, itemLabels map[string]string) string {
func appendLabelTabs(columnLabels []string) string { func appendLabelTabs(columnLabels []string) string {
var buffer bytes.Buffer var buffer bytes.Buffer
for i := range columnLabels { for range columnLabels {
// NB: This odd dance is to make the loop both compatible with go 1.3 and
// pass `gofmt -s`
_ = i
buffer.WriteString("\t") buffer.WriteString("\t")
} }
buffer.WriteString("\n") buffer.WriteString("\n")
......
...@@ -22,8 +22,7 @@ import ( ...@@ -22,8 +22,7 @@ import (
"path/filepath" "path/filepath"
) )
//IoUtil is a util for common IO operations // IoUtil is a mockable util for common IO operations
//it also backports certain operations from golang 1.5
type IoUtil interface { type IoUtil interface {
ReadDir(dirname string) ([]os.FileInfo, error) ReadDir(dirname string) ([]os.FileInfo, error)
Lstat(name string) (os.FileInfo, error) Lstat(name string) (os.FileInfo, error)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment