From 44d41a0f1ba26bb02eb9fe2b022a0713221af17d Mon Sep 17 00:00:00 2001 From: Andy Goldstein Date: Fri, 20 Feb 2015 20:00:31 -0500 Subject: [PATCH] Move golang code to third_party --- pkg/apiserver/proxy.go | 3 ++- pkg/util/httpstream/spdy/roundtripper.go | 4 ++-- pkg/util/net.go | 22 ------------------- third_party/golang/LICENSE | 27 ++++++++++++++++++++++++ third_party/golang/PATENTS | 22 +++++++++++++++++++ third_party/golang/netutil/addr.go | 27 ++++++++++++++++++++++++ 6 files changed, 80 insertions(+), 25 deletions(-) create mode 100644 third_party/golang/LICENSE create mode 100644 third_party/golang/PATENTS create mode 100644 third_party/golang/netutil/addr.go diff --git a/pkg/apiserver/proxy.go b/pkg/apiserver/proxy.go index a2e0dc88a8e..bfea64eea93 100644 --- a/pkg/apiserver/proxy.go +++ b/pkg/apiserver/proxy.go @@ -37,6 +37,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util/httpstream" + "github.com/GoogleCloudPlatform/kubernetes/third_party/golang/netutil" "github.com/golang/glog" "golang.org/x/net/html" ) @@ -184,7 +185,7 @@ func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { connectionHeader := strings.ToLower(req.Header.Get(httpstream.HeaderConnection)) if strings.Contains(connectionHeader, strings.ToLower(httpstream.HeaderUpgrade)) && len(req.Header.Get(httpstream.HeaderUpgrade)) > 0 { //TODO support TLS? Doesn't look like proxyTransport does anything special ... - dialAddr := util.CanonicalAddr(destURL) + dialAddr := netutil.CanonicalAddr(destURL) backendConn, err := net.Dial("tcp", dialAddr) if err != nil { status := errToAPIStatus(err) diff --git a/pkg/util/httpstream/spdy/roundtripper.go b/pkg/util/httpstream/spdy/roundtripper.go index acbcc879fe6..3d96570f2f6 100644 --- a/pkg/util/httpstream/spdy/roundtripper.go +++ b/pkg/util/httpstream/spdy/roundtripper.go @@ -25,8 +25,8 @@ import ( "net/http" "strings" - "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util/httpstream" + "github.com/GoogleCloudPlatform/kubernetes/third_party/golang/netutil" ) // SpdyRoundTripper knows how to upgrade an HTTP request to one that supports @@ -55,7 +55,7 @@ func NewRoundTripper(tlsConfig *tls.Config) httpstream.UpgradeRoundTripper { // dial dials the host specified by req, using TLS if appropriate. func (s *SpdyRoundTripper) dial(req *http.Request) (net.Conn, error) { - dialAddr := util.CanonicalAddr(req.URL) + dialAddr := netutil.CanonicalAddr(req.URL) if req.URL.Scheme == "http" { return net.Dial("tcp", dialAddr) diff --git a/pkg/util/net.go b/pkg/util/net.go index b35274ceaad..f36b1cae3fd 100644 --- a/pkg/util/net.go +++ b/pkg/util/net.go @@ -19,7 +19,6 @@ package util import ( "fmt" "net" - "net/url" "strings" ) @@ -62,24 +61,3 @@ func (ipnet *IPNet) Set(value string) error { func (*IPNet) Type() string { return "ipNet" } - -// FROM: http://golang.org/src/net/http/client.go -// Given a string of the form "host", "host:port", or "[ipv6::address]:port", -// return true if the string includes a port. -func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastIndex(s, "]") } - -// FROM: http://golang.org/src/net/http/transport.go -var portMap = map[string]string{ - "http": "80", - "https": "443", -} - -// FROM: http://golang.org/src/net/http/transport.go -// canonicalAddr returns url.Host but always with a ":port" suffix -func CanonicalAddr(url *url.URL) string { - addr := url.Host - if !hasPort(addr) { - return addr + ":" + portMap[url.Scheme] - } - return addr -} diff --git a/third_party/golang/LICENSE b/third_party/golang/LICENSE new file mode 100644 index 00000000000..74487567632 --- /dev/null +++ b/third_party/golang/LICENSE @@ -0,0 +1,27 @@ +Copyright (c) 2012 The Go Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/third_party/golang/PATENTS b/third_party/golang/PATENTS new file mode 100644 index 00000000000..733099041f8 --- /dev/null +++ b/third_party/golang/PATENTS @@ -0,0 +1,22 @@ +Additional IP Rights Grant (Patents) + +"This implementation" means the copyrightable works distributed by +Google as part of the Go project. + +Google hereby grants to You a perpetual, worldwide, non-exclusive, +no-charge, royalty-free, irrevocable (except as stated in this section) +patent license to make, have made, use, offer to sell, sell, import, +transfer and otherwise run, modify and propagate the contents of this +implementation of Go, where such license applies only to those patent +claims, both currently owned or controlled by Google and acquired in +the future, licensable by Google that are necessarily infringed by this +implementation of Go. This grant does not include claims that would be +infringed only as a consequence of further modification of this +implementation. If you or your agent or exclusive licensee institute or +order or agree to the institution of patent litigation against any +entity (including a cross-claim or counterclaim in a lawsuit) alleging +that this implementation of Go or any code incorporated within this +implementation of Go constitutes direct or contributory patent +infringement, or inducement of patent infringement, then any patent +rights granted to you under this License for this implementation of Go +shall terminate as of the date such litigation is filed. diff --git a/third_party/golang/netutil/addr.go b/third_party/golang/netutil/addr.go new file mode 100644 index 00000000000..c70f431c272 --- /dev/null +++ b/third_party/golang/netutil/addr.go @@ -0,0 +1,27 @@ +package netutil + +import ( + "net/url" + "strings" +) + +// FROM: http://golang.org/src/net/http/client.go +// Given a string of the form "host", "host:port", or "[ipv6::address]:port", +// return true if the string includes a port. +func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastIndex(s, "]") } + +// FROM: http://golang.org/src/net/http/transport.go +var portMap = map[string]string{ + "http": "80", + "https": "443", +} + +// FROM: http://golang.org/src/net/http/transport.go +// canonicalAddr returns url.Host but always with a ":port" suffix +func CanonicalAddr(url *url.URL) string { + addr := url.Host + if !hasPort(addr) { + return addr + ":" + portMap[url.Scheme] + } + return addr +}