vendor updates

This commit is contained in:
Serguei Bezverkhi
2018-03-06 17:33:18 -05:00
parent 4b3ebc171b
commit e9033989a0
5854 changed files with 248382 additions and 119809 deletions

View File

@ -7,10 +7,40 @@ load(
go_library(
name = "go_default_library",
srcs = [
"umask.go",
"service_port.go",
"util.go",
] + select({
"@io_bazel_rules_go//go/platform:windows_amd64": [
"@io_bazel_rules_go//go/platform:android": [
"umask.go",
],
"@io_bazel_rules_go//go/platform:darwin": [
"umask.go",
],
"@io_bazel_rules_go//go/platform:dragonfly": [
"umask.go",
],
"@io_bazel_rules_go//go/platform:freebsd": [
"umask.go",
],
"@io_bazel_rules_go//go/platform:linux": [
"umask.go",
],
"@io_bazel_rules_go//go/platform:nacl": [
"umask.go",
],
"@io_bazel_rules_go//go/platform:netbsd": [
"umask.go",
],
"@io_bazel_rules_go//go/platform:openbsd": [
"umask.go",
],
"@io_bazel_rules_go//go/platform:plan9": [
"umask.go",
],
"@io_bazel_rules_go//go/platform:solaris": [
"umask.go",
],
"@io_bazel_rules_go//go/platform:windows": [
"umask_windows.go",
],
"//conditions:default": [],
@ -18,10 +48,43 @@ go_library(
importpath = "k8s.io/kubernetes/pkg/kubectl/util",
visibility = ["//build/visible_to:pkg_kubectl_util_CONSUMERS"],
deps = [
"//vendor/golang.org/x/sys/unix:go_default_library",
"//pkg/apis/core:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
],
"//vendor/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
] + select({
"@io_bazel_rules_go//go/platform:android": [
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"@io_bazel_rules_go//go/platform:darwin": [
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"@io_bazel_rules_go//go/platform:dragonfly": [
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"@io_bazel_rules_go//go/platform:freebsd": [
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"@io_bazel_rules_go//go/platform:linux": [
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"@io_bazel_rules_go//go/platform:nacl": [
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"@io_bazel_rules_go//go/platform:netbsd": [
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"@io_bazel_rules_go//go/platform:openbsd": [
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"@io_bazel_rules_go//go/platform:plan9": [
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"@io_bazel_rules_go//go/platform:solaris": [
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"//conditions:default": [],
}),
)
filegroup(
@ -41,6 +104,7 @@ filegroup(
"//pkg/kubectl/util/logs:all-srcs",
"//pkg/kubectl/util/slice:all-srcs",
"//pkg/kubectl/util/term:all-srcs",
"//pkg/kubectl/util/transport:all-srcs",
],
tags = ["automanaged"],
visibility = ["//build/visible_to:pkg_kubectl_util_CONSUMERS"],
@ -48,7 +112,13 @@ filegroup(
go_test(
name = "go_default_test",
srcs = ["util_test.go"],
importpath = "k8s.io/kubernetes/pkg/kubectl/util",
library = ":go_default_library",
srcs = [
"service_port_test.go",
"util_test.go",
],
embed = [":go_default_library"],
deps = [
"//pkg/apis/core:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
],
)

View File

@ -9,8 +9,7 @@ load(
go_test(
name = "go_default_test",
srcs = ["hash_test.go"],
importpath = "k8s.io/kubernetes/pkg/kubectl/util/hash",
library = ":go_default_library",
embed = [":go_default_library"],
deps = ["//vendor/k8s.io/api/core/v1:go_default_library"],
)

View File

@ -148,7 +148,7 @@ not their metadata (e.g. the Data of a ConfigMap, but nothing in ObjectMeta).
obj interface{}
expect int
}{
{"ConfigMap", v1.ConfigMap{}, 3},
{"ConfigMap", v1.ConfigMap{}, 4},
{"Secret", v1.Secret{}, 5},
}
for _, c := range cases {

View File

@ -20,8 +20,7 @@ go_library(
go_test(
name = "go_default_test",
srcs = ["i18n_test.go"],
importpath = "k8s.io/kubernetes/pkg/kubectl/util/i18n",
library = ":go_default_library",
embed = [":go_default_library"],
)
filegroup(

View File

@ -0,0 +1,63 @@
/*
Copyright 2018 The Kubernetes Authors.
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.
*/
package util
import (
"fmt"
"k8s.io/apimachinery/pkg/util/intstr"
api "k8s.io/kubernetes/pkg/apis/core"
)
// Lookup containerPort number by its named port name
func LookupContainerPortNumberByName(pod api.Pod, name string) (int32, error) {
for _, ctr := range pod.Spec.Containers {
for _, ctrportspec := range ctr.Ports {
if ctrportspec.Name == name {
return ctrportspec.ContainerPort, nil
}
}
}
return int32(-1), fmt.Errorf("Pod '%s' does not have a named port '%s'", pod.Name, name)
}
// Lookup containerPort number from Service port number
// It implements the handling of resolving container named port, as well as ignoring targetPort when clusterIP=None
// It returns an error when a named port can't find a match (with -1 returned), or when the service does not
// declare such port (with the input port number returned).
func LookupContainerPortNumberByServicePort(svc api.Service, pod api.Pod, port int32) (int32, error) {
for _, svcportspec := range svc.Spec.Ports {
if svcportspec.Port != port {
continue
}
if svc.Spec.ClusterIP == api.ClusterIPNone {
return port, nil
}
if svcportspec.TargetPort.Type == intstr.Int {
if svcportspec.TargetPort.IntValue() == 0 {
// targetPort is omitted, and the IntValue() would be zero
return svcportspec.Port, nil
} else {
return int32(svcportspec.TargetPort.IntValue()), nil
}
} else {
return LookupContainerPortNumberByName(pod, svcportspec.TargetPort.String())
}
}
return port, fmt.Errorf("Service %s does not have a service port %d", svc.Name, port)
}

View File

@ -0,0 +1,337 @@
/*
Copyright 2018 The Kubernetes Authors.
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.
*/
package util
import (
"testing"
"k8s.io/apimachinery/pkg/util/intstr"
api "k8s.io/kubernetes/pkg/apis/core"
)
func TestLookupContainerPortNumberByName(t *testing.T) {
cases := []struct {
name string
pod api.Pod
portname string
portnum int32
err bool
}{
{
name: "test success 1",
pod: api.Pod{
Spec: api.PodSpec{
Containers: []api.Container{
{
Ports: []api.ContainerPort{
{
Name: "https",
ContainerPort: int32(443)},
{
Name: "http",
ContainerPort: int32(80)},
},
},
},
},
},
portname: "http",
portnum: int32(80),
err: false,
},
{
name: "test faulure 1",
pod: api.Pod{
Spec: api.PodSpec{
Containers: []api.Container{
{
Ports: []api.ContainerPort{
{
Name: "https",
ContainerPort: int32(443)},
},
},
},
},
},
portname: "www",
portnum: int32(0),
err: true,
},
}
for _, tc := range cases {
portnum, err := LookupContainerPortNumberByName(tc.pod, tc.portname)
if err != nil {
if tc.err {
continue
}
t.Errorf("%v: unexpected error: %v", tc.name, err)
continue
}
if tc.err {
t.Errorf("%v: unexpected success", tc.name)
continue
}
if portnum != tc.portnum {
t.Errorf("%v: expected port number %v; got %v", tc.name, tc.portnum, portnum)
}
}
}
func TestLookupContainerPortNumberByServicePort(t *testing.T) {
cases := []struct {
name string
svc api.Service
pod api.Pod
port int32
containerPort int32
err bool
}{
{
name: "test success 1 (int port)",
svc: api.Service{
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{
Port: 80,
TargetPort: intstr.FromInt(8080),
},
},
},
},
pod: api.Pod{
Spec: api.PodSpec{
Containers: []api.Container{
{
Ports: []api.ContainerPort{
{
Name: "http",
ContainerPort: int32(8080)},
},
},
},
},
},
port: 80,
containerPort: 8080,
err: false,
},
{
name: "test success 2 (clusterIP: None)",
svc: api.Service{
Spec: api.ServiceSpec{
ClusterIP: api.ClusterIPNone,
Ports: []api.ServicePort{
{
Port: 80,
TargetPort: intstr.FromInt(8080),
},
},
},
},
pod: api.Pod{
Spec: api.PodSpec{
Containers: []api.Container{
{
Ports: []api.ContainerPort{
{
Name: "http",
ContainerPort: int32(8080)},
},
},
},
},
},
port: 80,
containerPort: 80,
err: false,
},
{
name: "test success 3 (named port)",
svc: api.Service{
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{
Port: 80,
TargetPort: intstr.FromString("http"),
},
},
},
},
pod: api.Pod{
Spec: api.PodSpec{
Containers: []api.Container{
{
Ports: []api.ContainerPort{
{
Name: "http",
ContainerPort: int32(8080)},
},
},
},
},
},
port: 80,
containerPort: 8080,
err: false,
},
{
name: "test success (targetPort omitted)",
svc: api.Service{
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{
Port: 80,
},
},
},
},
pod: api.Pod{
Spec: api.PodSpec{
Containers: []api.Container{
{
Ports: []api.ContainerPort{
{
Name: "http",
ContainerPort: int32(80)},
},
},
},
},
},
port: 80,
containerPort: 80,
err: false,
},
{
name: "test failure 1 (cannot find a matching named port)",
svc: api.Service{
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{
Port: 80,
TargetPort: intstr.FromString("http"),
},
},
},
},
pod: api.Pod{
Spec: api.PodSpec{
Containers: []api.Container{
{
Ports: []api.ContainerPort{
{
Name: "https",
ContainerPort: int32(443)},
},
},
},
},
},
port: 80,
containerPort: -1,
err: true,
},
{
name: "test failure 2 (cannot find a matching service port)",
svc: api.Service{
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{
Port: 80,
TargetPort: intstr.FromString("http"),
},
},
},
},
pod: api.Pod{
Spec: api.PodSpec{
Containers: []api.Container{
{
Ports: []api.ContainerPort{
{
Name: "https",
ContainerPort: int32(443)},
},
},
},
},
},
port: 443,
containerPort: 443,
err: true,
},
{
name: "test failure 2 (cannot find a matching service port, but ClusterIP: None)",
svc: api.Service{
Spec: api.ServiceSpec{
ClusterIP: api.ClusterIPNone,
Ports: []api.ServicePort{
{
Port: 80,
TargetPort: intstr.FromString("http"),
},
},
},
},
pod: api.Pod{
Spec: api.PodSpec{
Containers: []api.Container{
{
Ports: []api.ContainerPort{
{
Name: "http",
ContainerPort: int32(80)},
},
},
},
},
},
port: 443,
containerPort: 443,
err: true,
},
}
for _, tc := range cases {
containerPort, err := LookupContainerPortNumberByServicePort(tc.svc, tc.pod, tc.port)
if err != nil {
if tc.err {
if containerPort != tc.containerPort {
t.Errorf("%v: expected port %v; got %v", tc.name, tc.containerPort, containerPort)
}
continue
}
t.Errorf("%v: unexpected error: %v", tc.name, err)
continue
}
if tc.err {
t.Errorf("%v: unexpected success", tc.name)
continue
}
if containerPort != tc.containerPort {
t.Errorf("%v: expected port %v; got %v", tc.name, tc.containerPort, containerPort)
}
}
}

View File

@ -15,8 +15,7 @@ go_library(
go_test(
name = "go_default_test",
srcs = ["slice_test.go"],
importpath = "k8s.io/kubernetes/pkg/kubectl/util/slice",
library = ":go_default_library",
embed = [":go_default_library"],
)
filegroup(

View File

@ -20,13 +20,5 @@ import (
"sort"
)
// Int64Slice attaches the methods of Interface to []int64,
// sorting in increasing order.
type Int64Slice []int64
func (p Int64Slice) Len() int { return len(p) }
func (p Int64Slice) Less(i, j int) bool { return p[i] < p[j] }
func (p Int64Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
// Sorts []int64 in increasing order
func SortInts64(a []int64) { sort.Sort(Int64Slice(a)) }
func SortInts64(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }

View File

@ -10,11 +10,40 @@ go_library(
name = "go_default_library",
srcs = [
"resize.go",
"resizeevents.go",
"term.go",
"term_writer.go",
] + select({
"@io_bazel_rules_go//go/platform:windows_amd64": [
"@io_bazel_rules_go//go/platform:android": [
"resizeevents.go",
],
"@io_bazel_rules_go//go/platform:darwin": [
"resizeevents.go",
],
"@io_bazel_rules_go//go/platform:dragonfly": [
"resizeevents.go",
],
"@io_bazel_rules_go//go/platform:freebsd": [
"resizeevents.go",
],
"@io_bazel_rules_go//go/platform:linux": [
"resizeevents.go",
],
"@io_bazel_rules_go//go/platform:nacl": [
"resizeevents.go",
],
"@io_bazel_rules_go//go/platform:netbsd": [
"resizeevents.go",
],
"@io_bazel_rules_go//go/platform:openbsd": [
"resizeevents.go",
],
"@io_bazel_rules_go//go/platform:plan9": [
"resizeevents.go",
],
"@io_bazel_rules_go//go/platform:solaris": [
"resizeevents.go",
],
"@io_bazel_rules_go//go/platform:windows": [
"resizeevents_windows.go",
],
"//conditions:default": [],
@ -24,17 +53,47 @@ go_library(
"//pkg/util/interrupt:go_default_library",
"//vendor/github.com/docker/docker/pkg/term:go_default_library",
"//vendor/github.com/mitchellh/go-wordwrap:go_default_library",
"//vendor/golang.org/x/sys/unix:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
"//vendor/k8s.io/client-go/tools/remotecommand:go_default_library",
],
] + select({
"@io_bazel_rules_go//go/platform:android": [
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"@io_bazel_rules_go//go/platform:darwin": [
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"@io_bazel_rules_go//go/platform:dragonfly": [
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"@io_bazel_rules_go//go/platform:freebsd": [
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"@io_bazel_rules_go//go/platform:linux": [
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"@io_bazel_rules_go//go/platform:nacl": [
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"@io_bazel_rules_go//go/platform:netbsd": [
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"@io_bazel_rules_go//go/platform:openbsd": [
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"@io_bazel_rules_go//go/platform:plan9": [
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"@io_bazel_rules_go//go/platform:solaris": [
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"//conditions:default": [],
}),
)
go_test(
name = "go_default_test",
srcs = ["term_writer_test.go"],
importpath = "k8s.io/kubernetes/pkg/kubectl/util/term",
library = ":go_default_library",
embed = [":go_default_library"],
)
filegroup(

View File

@ -0,0 +1,33 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = ["round_tripper.go"],
importpath = "k8s.io/kubernetes/pkg/kubectl/util/transport",
visibility = ["//visibility:public"],
deps = [
"//vendor/github.com/gregjones/httpcache:go_default_library",
"//vendor/github.com/gregjones/httpcache/diskcache:go_default_library",
"//vendor/github.com/peterbourgon/diskv:go_default_library",
],
)
go_test(
name = "go_default_test",
srcs = ["round_tripper_test.go"],
embed = [":go_default_library"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@ -0,0 +1,51 @@
/*
Copyright 2017 The Kubernetes Authors.
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.
*/
// Package transport provides a round tripper capable of caching HTTP responses.
package transport
import (
"net/http"
"path/filepath"
"github.com/gregjones/httpcache"
"github.com/gregjones/httpcache/diskcache"
"github.com/peterbourgon/diskv"
)
type cacheRoundTripper struct {
rt *httpcache.Transport
}
// NewCacheRoundTripper creates a roundtripper that reads the ETag on
// response headers and send the If-None-Match header on subsequent
// corresponding requests.
func NewCacheRoundTripper(cacheDir string, rt http.RoundTripper) http.RoundTripper {
d := diskv.New(diskv.Options{
BasePath: cacheDir,
TempDir: filepath.Join(cacheDir, ".diskv-temp"),
})
t := httpcache.NewTransport(diskcache.NewWithDiskv(d))
t.Transport = rt
return &cacheRoundTripper{rt: t}
}
func (rt *cacheRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
return rt.rt.RoundTrip(req)
}
func (rt *cacheRoundTripper) WrappedRoundTripper() http.RoundTripper { return rt.rt.Transport }

View File

@ -0,0 +1,95 @@
/*
Copyright 2017 The Kubernetes Authors.
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.
*/
package transport
import (
"bytes"
"io/ioutil"
"net/http"
"net/url"
"os"
"testing"
)
// copied from k8s.io/client-go/transport/round_trippers_test.go
type testRoundTripper struct {
Request *http.Request
Response *http.Response
Err error
}
func (rt *testRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
rt.Request = req
return rt.Response, rt.Err
}
func TestCacheRoundTripper(t *testing.T) {
rt := &testRoundTripper{}
cacheDir, err := ioutil.TempDir("", "cache-rt")
defer os.RemoveAll(cacheDir)
if err != nil {
t.Fatal(err)
}
cache := NewCacheRoundTripper(cacheDir, rt)
// First call, caches the response
req := &http.Request{
Method: http.MethodGet,
URL: &url.URL{Host: "localhost"},
}
rt.Response = &http.Response{
Header: http.Header{"ETag": []string{`"123456"`}},
Body: ioutil.NopCloser(bytes.NewReader([]byte("Content"))),
StatusCode: http.StatusOK,
}
resp, err := cache.RoundTrip(req)
if err != nil {
t.Fatal(err)
}
content, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
if string(content) != "Content" {
t.Errorf(`Expected Body to be "Content", got %q`, string(content))
}
// Second call, returns cached response
req = &http.Request{
Method: http.MethodGet,
URL: &url.URL{Host: "localhost"},
}
rt.Response = &http.Response{
StatusCode: http.StatusNotModified,
Body: ioutil.NopCloser(bytes.NewReader([]byte("Other Content"))),
}
resp, err = cache.RoundTrip(req)
if err != nil {
t.Fatal(err)
}
// Read body and make sure we have the initial content
content, err = ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
t.Fatal(err)
}
if string(content) != "Content" {
t.Errorf("Invalid content read from cache %q", string(content))
}
}