From 03043e4114815c9b47cb373986e7fb047d756f3c Mon Sep 17 00:00:00 2001 From: Joe Finney Date: Mon, 21 Mar 2016 11:12:39 -0700 Subject: [PATCH 1/5] Fix pkg/probe/tcp unit test for go 1.6. --- pkg/probe/tcp/tcp_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/probe/tcp/tcp_test.go b/pkg/probe/tcp/tcp_test.go index 298de5acf7f..6061218062c 100644 --- a/pkg/probe/tcp/tcp_test.go +++ b/pkg/probe/tcp/tcp_test.go @@ -66,7 +66,12 @@ func TestTcpHealthChecker(t *testing.T) { // A connection is made and probing would succeed {tHost, tPort, probe.Success, nil, []string{""}}, // No connection can be made and probing would fail - {tHost, -1, probe.Failure, nil, []string{"unknown port", "Servname not supported for ai_socktype", "nodename nor servname provided, or not known"}}, + {tHost, -1, probe.Failure, nil, []string{ + "unknown port", + "Servname not supported for ai_socktype", + "nodename nor servname provided, or not known", + "dial tcp: invalid port", + }}, } prober := New() From bc791cbd4e76d5edd95b0b9984924957115ba15a Mon Sep 17 00:00:00 2001 From: Joe Finney Date: Mon, 21 Mar 2016 14:47:26 -0700 Subject: [PATCH 2/5] Fix pkg/probe/http unit test for go 1.6. --- pkg/probe/http/http_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/probe/http/http_test.go b/pkg/probe/http/http_test.go index 018086c50f3..748abe748ac 100644 --- a/pkg/probe/http/http_test.go +++ b/pkg/probe/http/http_test.go @@ -89,7 +89,10 @@ func TestHTTPProbeChecker(t *testing.T) { handleReq(FailureCode, "fail body"), nil, probe.Failure, - []string{fmt.Sprintf("HTTP probe failed with statuscode: %d", FailureCode)}, + []string{ + fmt.Sprintf("HTTP probe failed with statuscode: %d", FailureCode), + fmt.Sprintf("malformed HTTP status code \"%d\"", FailureCode), + }, }, { func(w http.ResponseWriter, r *http.Request) { From c8c2c58afda106d69b2ed544cf6a562bba005f5e Mon Sep 17 00:00:00 2001 From: Joe Finney Date: Mon, 21 Mar 2016 15:27:34 -0700 Subject: [PATCH 3/5] Bump spew godep to make hash tests pass on go 1.6. --- Godeps/Godeps.json | 2 +- .../github.com/davecgh/go-spew/spew/bypass.go | 151 ++++++++++++++++++ .../davecgh/go-spew/spew/bypasssafe.go | 37 +++++ .../github.com/davecgh/go-spew/spew/common.go | 135 ++-------------- .../github.com/davecgh/go-spew/spew/config.go | 5 +- .../github.com/davecgh/go-spew/spew/dump.go | 29 ++-- 6 files changed, 222 insertions(+), 137 deletions(-) create mode 100644 Godeps/_workspace/src/github.com/davecgh/go-spew/spew/bypass.go create mode 100644 Godeps/_workspace/src/github.com/davecgh/go-spew/spew/bypasssafe.go diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index d2c9c3dc00d..7af62fe6773 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -381,7 +381,7 @@ }, { "ImportPath": "github.com/davecgh/go-spew/spew", - "Rev": "3e6e67c4dcea3ac2f25fd4731abc0e1deaf36216" + "Rev": "5215b55f46b2b919f50a1df0eaa5886afe4e3b3d" }, { "ImportPath": "github.com/daviddengcn/go-colortext", diff --git a/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/bypass.go b/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/bypass.go new file mode 100644 index 00000000000..565bf5899f2 --- /dev/null +++ b/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/bypass.go @@ -0,0 +1,151 @@ +// Copyright (c) 2015 Dave Collins +// +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +// NOTE: Due to the following build constraints, this file will only be compiled +// when the code is not running on Google App Engine and "-tags disableunsafe" +// is not added to the go build command line. +// +build !appengine,!disableunsafe + +package spew + +import ( + "reflect" + "unsafe" +) + +const ( + // UnsafeDisabled is a build-time constant which specifies whether or + // not access to the unsafe package is available. + UnsafeDisabled = false + + // ptrSize is the size of a pointer on the current arch. + ptrSize = unsafe.Sizeof((*byte)(nil)) +) + +var ( + // offsetPtr, offsetScalar, and offsetFlag are the offsets for the + // internal reflect.Value fields. These values are valid before golang + // commit ecccf07e7f9d which changed the format. The are also valid + // after commit 82f48826c6c7 which changed the format again to mirror + // the original format. Code in the init function updates these offsets + // as necessary. + offsetPtr = uintptr(ptrSize) + offsetScalar = uintptr(0) + offsetFlag = uintptr(ptrSize * 2) + + // flagKindWidth and flagKindShift indicate various bits that the + // reflect package uses internally to track kind information. + // + // flagRO indicates whether or not the value field of a reflect.Value is + // read-only. + // + // flagIndir indicates whether the value field of a reflect.Value is + // the actual data or a pointer to the data. + // + // These values are valid before golang commit 90a7c3c86944 which + // changed their positions. Code in the init function updates these + // flags as necessary. + flagKindWidth = uintptr(5) + flagKindShift = uintptr(flagKindWidth - 1) + flagRO = uintptr(1 << 0) + flagIndir = uintptr(1 << 1) +) + +func init() { + // Older versions of reflect.Value stored small integers directly in the + // ptr field (which is named val in the older versions). Versions + // between commits ecccf07e7f9d and 82f48826c6c7 added a new field named + // scalar for this purpose which unfortunately came before the flag + // field, so the offset of the flag field is different for those + // versions. + // + // This code constructs a new reflect.Value from a known small integer + // and checks if the size of the reflect.Value struct indicates it has + // the scalar field. When it does, the offsets are updated accordingly. + vv := reflect.ValueOf(0xf00) + if unsafe.Sizeof(vv) == (ptrSize * 4) { + offsetScalar = ptrSize * 2 + offsetFlag = ptrSize * 3 + } + + // Commit 90a7c3c86944 changed the flag positions such that the low + // order bits are the kind. This code extracts the kind from the flags + // field and ensures it's the correct type. When it's not, the flag + // order has been changed to the newer format, so the flags are updated + // accordingly. + upf := unsafe.Pointer(uintptr(unsafe.Pointer(&vv)) + offsetFlag) + upfv := *(*uintptr)(upf) + flagKindMask := uintptr((1<>flagKindShift != uintptr(reflect.Int) { + flagKindShift = 0 + flagRO = 1 << 5 + flagIndir = 1 << 6 + + // Commit adf9b30e5594 modified the flags to separate the + // flagRO flag into two bits which specifies whether or not the + // field is embedded. This causes flagIndir to move over a bit + // and means that flagRO is the combination of either of the + // original flagRO bit and the new bit. + // + // This code detects the change by extracting what used to be + // the indirect bit to ensure it's set. When it's not, the flag + // order has been changed to the newer format, so the flags are + // updated accordingly. + if upfv&flagIndir == 0 { + flagRO = 3 << 5 + flagIndir = 1 << 7 + } + } +} + +// unsafeReflectValue converts the passed reflect.Value into a one that bypasses +// the typical safety restrictions preventing access to unaddressable and +// unexported data. It works by digging the raw pointer to the underlying +// value out of the protected value and generating a new unprotected (unsafe) +// reflect.Value to it. +// +// This allows us to check for implementations of the Stringer and error +// interfaces to be used for pretty printing ordinarily unaddressable and +// inaccessible values such as unexported struct fields. +func unsafeReflectValue(v reflect.Value) (rv reflect.Value) { + indirects := 1 + vt := v.Type() + upv := unsafe.Pointer(uintptr(unsafe.Pointer(&v)) + offsetPtr) + rvf := *(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&v)) + offsetFlag)) + if rvf&flagIndir != 0 { + vt = reflect.PtrTo(v.Type()) + indirects++ + } else if offsetScalar != 0 { + // The value is in the scalar field when it's not one of the + // reference types. + switch vt.Kind() { + case reflect.Uintptr: + case reflect.Chan: + case reflect.Func: + case reflect.Map: + case reflect.Ptr: + case reflect.UnsafePointer: + default: + upv = unsafe.Pointer(uintptr(unsafe.Pointer(&v)) + + offsetScalar) + } + } + + pv := reflect.NewAt(vt, upv) + rv = pv + for i := 0; i < indirects; i++ { + rv = rv.Elem() + } + return rv +} diff --git a/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/bypasssafe.go b/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/bypasssafe.go new file mode 100644 index 00000000000..457e41235ed --- /dev/null +++ b/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/bypasssafe.go @@ -0,0 +1,37 @@ +// Copyright (c) 2015 Dave Collins +// +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +// NOTE: Due to the following build constraints, this file will only be compiled +// when either the code is running on Google App Engine or "-tags disableunsafe" +// is added to the go build command line. +// +build appengine disableunsafe + +package spew + +import "reflect" + +const ( + // UnsafeDisabled is a build-time constant which specifies whether or + // not access to the unsafe package is available. + UnsafeDisabled = true +) + +// unsafeReflectValue typically converts the passed reflect.Value into a one +// that bypasses the typical safety restrictions preventing access to +// unaddressable and unexported data. However, doing this relies on access to +// the unsafe package. This is a stub version which simply returns the passed +// reflect.Value when the unsafe package is not available. +func unsafeReflectValue(v reflect.Value) reflect.Value { + return v +} diff --git a/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/common.go b/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/common.go index 8252cd3ee58..14f02dc15b7 100644 --- a/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/common.go +++ b/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/common.go @@ -23,116 +23,8 @@ import ( "reflect" "sort" "strconv" - "unsafe" ) -const ( - // ptrSize is the size of a pointer on the current arch. - ptrSize = unsafe.Sizeof((*byte)(nil)) -) - -var ( - // offsetPtr, offsetScalar, and offsetFlag are the offsets for the - // internal reflect.Value fields. These values are valid before golang - // commit ecccf07e7f9d which changed the format. The are also valid - // after commit 82f48826c6c7 which changed the format again to mirror - // the original format. Code in the init function updates these offsets - // as necessary. - offsetPtr = uintptr(ptrSize) - offsetScalar = uintptr(0) - offsetFlag = uintptr(ptrSize * 2) - - // flagKindWidth and flagKindShift indicate various bits that the - // reflect package uses internally to track kind information. - // - // flagRO indicates whether or not the value field of a reflect.Value is - // read-only. - // - // flagIndir indicates whether the value field of a reflect.Value is - // the actual data or a pointer to the data. - // - // These values are valid before golang commit 90a7c3c86944 which - // changed their positions. Code in the init function updates these - // flags as necessary. - flagKindWidth = uintptr(5) - flagKindShift = uintptr(flagKindWidth - 1) - flagRO = uintptr(1 << 0) - flagIndir = uintptr(1 << 1) -) - -func init() { - // Older versions of reflect.Value stored small integers directly in the - // ptr field (which is named val in the older versions). Versions - // between commits ecccf07e7f9d and 82f48826c6c7 added a new field named - // scalar for this purpose which unfortunately came before the flag - // field, so the offset of the flag field is different for those - // versions. - // - // This code constructs a new reflect.Value from a known small integer - // and checks if the size of the reflect.Value struct indicates it has - // the scalar field. When it does, the offsets are updated accordingly. - vv := reflect.ValueOf(0xf00) - if unsafe.Sizeof(vv) == (ptrSize * 4) { - offsetScalar = ptrSize * 2 - offsetFlag = ptrSize * 3 - } - - // Commit 90a7c3c86944 changed the flag positions such that the low - // order bits are the kind. This code extracts the kind from the flags - // field and ensures it's the correct type. When it's not, the flag - // order has been changed to the newer format, so the flags are updated - // accordingly. - upf := unsafe.Pointer(uintptr(unsafe.Pointer(&vv)) + offsetFlag) - upfv := *(*uintptr)(upf) - flagKindMask := uintptr((1<>flagKindShift != uintptr(reflect.Int) { - flagKindShift = 0 - flagRO = 1 << 5 - flagIndir = 1 << 6 - } -} - -// unsafeReflectValue converts the passed reflect.Value into a one that bypasses -// the typical safety restrictions preventing access to unaddressable and -// unexported data. It works by digging the raw pointer to the underlying -// value out of the protected value and generating a new unprotected (unsafe) -// reflect.Value to it. -// -// This allows us to check for implementations of the Stringer and error -// interfaces to be used for pretty printing ordinarily unaddressable and -// inaccessible values such as unexported struct fields. -func unsafeReflectValue(v reflect.Value) (rv reflect.Value) { - indirects := 1 - vt := v.Type() - upv := unsafe.Pointer(uintptr(unsafe.Pointer(&v)) + offsetPtr) - rvf := *(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&v)) + offsetFlag)) - if rvf&flagIndir != 0 { - vt = reflect.PtrTo(v.Type()) - indirects++ - } else if offsetScalar != 0 { - // The value is in the scalar field when it's not one of the - // reference types. - switch vt.Kind() { - case reflect.Uintptr: - case reflect.Chan: - case reflect.Func: - case reflect.Map: - case reflect.Ptr: - case reflect.UnsafePointer: - default: - upv = unsafe.Pointer(uintptr(unsafe.Pointer(&v)) + - offsetScalar) - } - } - - pv := reflect.NewAt(vt, upv) - rv = pv - for i := 0; i < indirects; i++ { - rv = rv.Elem() - } - return rv -} - // Some constants in the form of bytes to avoid string overhead. This mirrors // the technique used in the fmt package. var ( @@ -194,9 +86,14 @@ func handleMethods(cs *ConfigState, w io.Writer, v reflect.Value) (handled bool) // We need an interface to check if the type implements the error or // Stringer interface. However, the reflect package won't give us an // interface on certain things like unexported struct fields in order - // to enforce visibility rules. We use unsafe to bypass these restrictions - // since this package does not mutate the values. + // to enforce visibility rules. We use unsafe, when it's available, + // to bypass these restrictions since this package does not mutate the + // values. if !v.CanInterface() { + if UnsafeDisabled { + return false + } + v = unsafeReflectValue(v) } @@ -206,21 +103,15 @@ func handleMethods(cs *ConfigState, w io.Writer, v reflect.Value) (handled bool) // mutate the value, however, types which choose to satisify an error or // Stringer interface with a pointer receiver should not be mutating their // state inside these interface methods. - var viface interface{} - if !cs.DisablePointerMethods { - if !v.CanAddr() { - v = unsafeReflectValue(v) - } - viface = v.Addr().Interface() - } else { - if v.CanAddr() { - v = v.Addr() - } - viface = v.Interface() + if !cs.DisablePointerMethods && !UnsafeDisabled && !v.CanAddr() { + v = unsafeReflectValue(v) + } + if v.CanAddr() { + v = v.Addr() } // Is it an error or Stringer? - switch iface := viface.(type) { + switch iface := v.Interface().(type) { case error: defer catchPanic(w, v) if cs.ContinueOnMethod { diff --git a/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/config.go b/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/config.go index 9e21b38ca25..ee1ab07b3fd 100644 --- a/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/config.go +++ b/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/config.go @@ -61,7 +61,10 @@ type ConfigState struct { // with a pointer receiver could technically mutate the value, however, // in practice, types which choose to satisify an error or Stringer // interface with a pointer receiver should not be mutating their state - // inside these interface methods. + // inside these interface methods. As a result, this option relies on + // access to the unsafe package, so it will not have any effect when + // running in environments without access to the unsafe package such as + // Google App Engine or with the "disableunsafe" build tag specified. DisablePointerMethods bool // ContinueOnMethod specifies whether or not recursion should continue once diff --git a/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/dump.go b/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/dump.go index 5783145b781..a0ff95e27e5 100644 --- a/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/dump.go +++ b/Godeps/_workspace/src/github.com/davecgh/go-spew/spew/dump.go @@ -181,25 +181,28 @@ func (d *dumpState) dumpSlice(v reflect.Value) { // Try to use existing uint8 slices and fall back to converting // and copying if that fails. case vt.Kind() == reflect.Uint8: - // We need an addressable interface to convert the type back - // into a byte slice. However, the reflect package won't give - // us an interface on certain things like unexported struct - // fields in order to enforce visibility rules. We use unsafe - // to bypass these restrictions since this package does not + // We need an addressable interface to convert the type + // to a byte slice. However, the reflect package won't + // give us an interface on certain things like + // unexported struct fields in order to enforce + // visibility rules. We use unsafe, when available, to + // bypass these restrictions since this package does not // mutate the values. vs := v if !vs.CanInterface() || !vs.CanAddr() { vs = unsafeReflectValue(vs) } - vs = vs.Slice(0, numEntries) + if !UnsafeDisabled { + vs = vs.Slice(0, numEntries) - // Use the existing uint8 slice if it can be type - // asserted. - iface := vs.Interface() - if slice, ok := iface.([]uint8); ok { - buf = slice - doHexDump = true - break + // Use the existing uint8 slice if it can be + // type asserted. + iface := vs.Interface() + if slice, ok := iface.([]uint8); ok { + buf = slice + doHexDump = true + break + } } // The underlying data needs to be converted if it can't From d3e94fcd786b00d79e744a3068c7f1df1a08fa95 Mon Sep 17 00:00:00 2001 From: Joe Finney Date: Mon, 21 Mar 2016 16:14:09 -0700 Subject: [PATCH 4/5] Up unit/integration test on Jenkins to go 1.6. --- hack/jenkins/gotest-dockerized.sh | 2 +- hack/jenkins/test-image/Dockerfile | 2 +- hack/jenkins/test-image/Makefile | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hack/jenkins/gotest-dockerized.sh b/hack/jenkins/gotest-dockerized.sh index f6751ed290d..c1ac1def4cb 100755 --- a/hack/jenkins/gotest-dockerized.sh +++ b/hack/jenkins/gotest-dockerized.sh @@ -42,5 +42,5 @@ docker run --rm=true \ -e "KUBE_FORCE_VERIFY_CHECKS=${KUBE_FORCE_VERIFY_CHECKS:-}" \ -e "KUBE_VERIFY_GIT_BRANCH=${KUBE_VERIFY_GIT_BRANCH:-}" \ -e "REPO_DIR=${REPO_DIR}" \ - -i gcr.io/google_containers/kubekins-test:0.8 \ + -i gcr.io/google_containers/kubekins-test:0.9 \ bash -c "cd kubernetes && ./hack/jenkins/test-dockerized.sh" diff --git a/hack/jenkins/test-image/Dockerfile b/hack/jenkins/test-image/Dockerfile index 4ca833a686c..f930d8b04dc 100644 --- a/hack/jenkins/test-image/Dockerfile +++ b/hack/jenkins/test-image/Dockerfile @@ -15,7 +15,7 @@ # This file creates a build environment for building and running kubernetes # unit and integration tests -FROM golang:1.5.3 +FROM golang:1.6 MAINTAINER Jeff Lowdermilk ENV WORKSPACE /workspace diff --git a/hack/jenkins/test-image/Makefile b/hack/jenkins/test-image/Makefile index f3712715f30..472e9118c91 100644 --- a/hack/jenkins/test-image/Makefile +++ b/hack/jenkins/test-image/Makefile @@ -14,7 +14,7 @@ all: push -TAG = 0.8 +TAG = 0.9 container: docker build -t gcr.io/google_containers/kubekins-test . From 7fb8a8e46c887930c70ba55fbb3070a0eb3baab7 Mon Sep 17 00:00:00 2001 From: Joe Finney Date: Tue, 22 Mar 2016 13:50:15 -0700 Subject: [PATCH 5/5] Disable the vendor experiment in hack/verify-godeps.sh --- hack/verify-godeps.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hack/verify-godeps.sh b/hack/verify-godeps.sh index a9890a6858d..61dddca370a 100755 --- a/hack/verify-godeps.sh +++ b/hack/verify-godeps.sh @@ -18,6 +18,9 @@ set -o errexit set -o nounset set -o pipefail +# As of go 1.6, the vendor experiment is enabled by default. +export GO15VENDOREXPERIMENT=0 + #### HACK #### # Sometimes godep just can't handle things. This lets use manually put # some deps in place first, so godep won't fall over.