Replace godep with dep
This commit is contained in:
parent
1e7489927c
commit
bf5616c65b
14883 changed files with 3937406 additions and 361781 deletions
61
vendor/k8s.io/kubernetes/pkg/kubelet/util/BUILD
generated
vendored
Normal file
61
vendor/k8s.io/kubernetes/pkg/kubelet/util/BUILD
generated
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
"go_test",
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["util_test.go"],
|
||||
library = ":go_default_library",
|
||||
deps = ["//vendor/github.com/stretchr/testify/assert:go_default_library"],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"doc.go",
|
||||
"util.go",
|
||||
"util_unsupported.go",
|
||||
] + select({
|
||||
"@io_bazel_rules_go//go/platform:linux_amd64": [
|
||||
"util_unix.go",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:windows_amd64": [
|
||||
"util_windows.go",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
deps = [
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
] + select({
|
||||
"@io_bazel_rules_go//go/platform:linux_amd64": [
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [
|
||||
":package-srcs",
|
||||
"//pkg/kubelet/util/cache:all-srcs",
|
||||
"//pkg/kubelet/util/csr:all-srcs",
|
||||
"//pkg/kubelet/util/format:all-srcs",
|
||||
"//pkg/kubelet/util/ioutils:all-srcs",
|
||||
"//pkg/kubelet/util/queue:all-srcs",
|
||||
"//pkg/kubelet/util/sliceutils:all-srcs",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
36
vendor/k8s.io/kubernetes/pkg/kubelet/util/cache/BUILD
generated
vendored
Normal file
36
vendor/k8s.io/kubernetes/pkg/kubelet/util/cache/BUILD
generated
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
"go_test",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["object_cache.go"],
|
||||
deps = ["//vendor/k8s.io/client-go/tools/cache:go_default_library"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["object_cache_test.go"],
|
||||
library = ":go_default_library",
|
||||
deps = [
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/clock:go_default_library",
|
||||
"//vendor/k8s.io/client-go/tools/cache:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
84
vendor/k8s.io/kubernetes/pkg/kubelet/util/cache/object_cache.go
generated
vendored
Normal file
84
vendor/k8s.io/kubernetes/pkg/kubelet/util/cache/object_cache.go
generated
vendored
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
Copyright 2016 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 cache
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
expirationcache "k8s.io/client-go/tools/cache"
|
||||
)
|
||||
|
||||
// ObjectCache is a simple wrapper of expiration cache that
|
||||
// 1. use string type key
|
||||
// 2. has an updater to get value directly if it is expired
|
||||
// 3. then update the cache
|
||||
type ObjectCache struct {
|
||||
cache expirationcache.Store
|
||||
updater func() (interface{}, error)
|
||||
}
|
||||
|
||||
// objectEntry is an object with string type key.
|
||||
type objectEntry struct {
|
||||
key string
|
||||
obj interface{}
|
||||
}
|
||||
|
||||
// NewObjectCache creates ObjectCache with an updater.
|
||||
// updater returns an object to cache.
|
||||
func NewObjectCache(f func() (interface{}, error), ttl time.Duration) *ObjectCache {
|
||||
return &ObjectCache{
|
||||
updater: f,
|
||||
cache: expirationcache.NewTTLStore(stringKeyFunc, ttl),
|
||||
}
|
||||
}
|
||||
|
||||
// stringKeyFunc is a string as cache key function
|
||||
func stringKeyFunc(obj interface{}) (string, error) {
|
||||
key := obj.(objectEntry).key
|
||||
return key, nil
|
||||
}
|
||||
|
||||
// Get gets cached objectEntry by using a unique string as the key.
|
||||
func (c *ObjectCache) Get(key string) (interface{}, error) {
|
||||
value, ok, err := c.cache.Get(objectEntry{key: key})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !ok {
|
||||
obj, err := c.updater()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = c.cache.Add(objectEntry{
|
||||
key: key,
|
||||
obj: obj,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj, nil
|
||||
}
|
||||
return value.(objectEntry).obj, nil
|
||||
}
|
||||
|
||||
func (c *ObjectCache) Add(key string, obj interface{}) error {
|
||||
err := c.cache.Add(objectEntry{key: key, obj: obj})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
96
vendor/k8s.io/kubernetes/pkg/kubelet/util/cache/object_cache_test.go
generated
vendored
Normal file
96
vendor/k8s.io/kubernetes/pkg/kubelet/util/cache/object_cache_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
Copyright 2016 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 cache
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/clock"
|
||||
expirationcache "k8s.io/client-go/tools/cache"
|
||||
)
|
||||
|
||||
type testObject struct {
|
||||
key string
|
||||
val string
|
||||
}
|
||||
|
||||
// A fake objectCache for unit test.
|
||||
func NewFakeObjectCache(f func() (interface{}, error), ttl time.Duration, clock clock.Clock) *ObjectCache {
|
||||
ttlPolicy := &expirationcache.TTLPolicy{Ttl: ttl, Clock: clock}
|
||||
deleteChan := make(chan string, 1)
|
||||
return &ObjectCache{
|
||||
updater: f,
|
||||
cache: expirationcache.NewFakeExpirationStore(stringKeyFunc, deleteChan, ttlPolicy, clock),
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddAndGet(t *testing.T) {
|
||||
testObj := testObject{
|
||||
key: "foo",
|
||||
val: "bar",
|
||||
}
|
||||
objectCache := NewFakeObjectCache(func() (interface{}, error) {
|
||||
return nil, fmt.Errorf("Unexpected Error: updater should never be called in this test!")
|
||||
}, 1*time.Hour, clock.NewFakeClock(time.Now()))
|
||||
|
||||
err := objectCache.Add(testObj.key, testObj.val)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to add obj %#v by key: %s", testObj, testObj.key)
|
||||
}
|
||||
value, err := objectCache.Get(testObj.key)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to get obj %#v by key: %s", testObj, testObj.key)
|
||||
}
|
||||
if value.(string) != testObj.val {
|
||||
t.Errorf("Expected to get cached value: %#v, but got: %s", testObj.val, value.(string))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestExpirationBasic(t *testing.T) {
|
||||
unexpectedVal := "bar"
|
||||
expectedVal := "bar2"
|
||||
|
||||
testObj := testObject{
|
||||
key: "foo",
|
||||
val: unexpectedVal,
|
||||
}
|
||||
|
||||
fakeClock := clock.NewFakeClock(time.Now())
|
||||
|
||||
objectCache := NewFakeObjectCache(func() (interface{}, error) {
|
||||
return expectedVal, nil
|
||||
}, 1*time.Second, fakeClock)
|
||||
|
||||
err := objectCache.Add(testObj.key, testObj.val)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to add obj %#v by key: %s", testObj, testObj.key)
|
||||
}
|
||||
|
||||
// sleep 2s so cache should be expired.
|
||||
fakeClock.Sleep(2 * time.Second)
|
||||
|
||||
value, err := objectCache.Get(testObj.key)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to get obj %#v by key: %s", testObj, testObj.key)
|
||||
}
|
||||
if value.(string) != expectedVal {
|
||||
t.Errorf("Expected to get cached value: %#v, but got: %s", expectedVal, value.(string))
|
||||
}
|
||||
}
|
||||
52
vendor/k8s.io/kubernetes/pkg/kubelet/util/csr/BUILD
generated
vendored
Normal file
52
vendor/k8s.io/kubernetes/pkg/kubelet/util/csr/BUILD
generated
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
"go_test",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["csr.go"],
|
||||
deps = [
|
||||
"//pkg/apis/certificates/v1beta1:go_default_library",
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
"//vendor/k8s.io/api/certificates/v1beta1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/fields:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
|
||||
"//vendor/k8s.io/client-go/kubernetes/typed/certificates/v1beta1:go_default_library",
|
||||
"//vendor/k8s.io/client-go/tools/cache:go_default_library",
|
||||
"//vendor/k8s.io/client-go/util/cert:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["csr_test.go"],
|
||||
library = ":go_default_library",
|
||||
deps = [
|
||||
"//vendor/k8s.io/api/certificates/v1beta1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
|
||||
"//vendor/k8s.io/client-go/kubernetes/typed/certificates/v1beta1:go_default_library",
|
||||
"//vendor/k8s.io/client-go/util/cert:go_default_library",
|
||||
],
|
||||
)
|
||||
207
vendor/k8s.io/kubernetes/pkg/kubelet/util/csr/csr.go
generated
vendored
Normal file
207
vendor/k8s.io/kubernetes/pkg/kubelet/util/csr/csr.go
generated
vendored
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
/*
|
||||
Copyright 2016 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 csr
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
"crypto/sha512"
|
||||
"crypto/x509/pkix"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
certificates "k8s.io/api/certificates/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/fields"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
certificatesclient "k8s.io/client-go/kubernetes/typed/certificates/v1beta1"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
certutil "k8s.io/client-go/util/cert"
|
||||
certhelper "k8s.io/kubernetes/pkg/apis/certificates/v1beta1"
|
||||
)
|
||||
|
||||
// RequestNodeCertificate will create a certificate signing request for a node
|
||||
// (Organization and CommonName for the CSR will be set as expected for node
|
||||
// certificates) and send it to API server, then it will watch the object's
|
||||
// status, once approved by API server, it will return the API server's issued
|
||||
// certificate (pem-encoded). If there is any errors, or the watch timeouts, it
|
||||
// will return an error. This is intended for use on nodes (kubelet and
|
||||
// kubeadm).
|
||||
func RequestNodeCertificate(client certificatesclient.CertificateSigningRequestInterface, privateKeyData []byte, nodeName types.NodeName) (certData []byte, err error) {
|
||||
subject := &pkix.Name{
|
||||
Organization: []string{"system:nodes"},
|
||||
CommonName: "system:node:" + string(nodeName),
|
||||
}
|
||||
|
||||
privateKey, err := certutil.ParsePrivateKeyPEM(privateKeyData)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid private key for certificate request: %v", err)
|
||||
}
|
||||
csrData, err := certutil.MakeCSR(privateKey, subject, nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to generate certificate request: %v", err)
|
||||
}
|
||||
|
||||
usages := []certificates.KeyUsage{
|
||||
certificates.UsageDigitalSignature,
|
||||
certificates.UsageKeyEncipherment,
|
||||
certificates.UsageClientAuth,
|
||||
}
|
||||
name := digestedName(privateKeyData, subject, usages)
|
||||
return requestCertificate(client, csrData, name, usages, privateKey)
|
||||
}
|
||||
|
||||
// requestCertificate will either use an existing (if this process has run
|
||||
// before but not to completion) or create a certificate signing request using the
|
||||
// PEM encoded CSR and send it to API server, then it will watch the object's
|
||||
// status, once approved by API server, it will return the API server's issued
|
||||
// certificate (pem-encoded). If there is any errors, or the watch timeouts, it
|
||||
// will return an error.
|
||||
func requestCertificate(client certificatesclient.CertificateSigningRequestInterface, csrData []byte, name string, usages []certificates.KeyUsage, privateKey interface{}) (certData []byte, err error) {
|
||||
csr := &certificates.CertificateSigningRequest{
|
||||
// Username, UID, Groups will be injected by API server.
|
||||
TypeMeta: metav1.TypeMeta{Kind: "CertificateSigningRequest"},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
},
|
||||
Spec: certificates.CertificateSigningRequestSpec{
|
||||
Request: csrData,
|
||||
Usages: usages,
|
||||
},
|
||||
}
|
||||
|
||||
req, err := client.Create(csr)
|
||||
switch {
|
||||
case err == nil:
|
||||
case errors.IsAlreadyExists(err):
|
||||
glog.Infof("csr for this node already exists, reusing")
|
||||
req, err = client.Get(name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot retrieve certificate signing request: %v", err)
|
||||
}
|
||||
if err := ensureCompatible(req, csr, privateKey); err != nil {
|
||||
return nil, fmt.Errorf("retrieved csr is not compatible: %v", err)
|
||||
}
|
||||
glog.Infof("csr for this node is still valid")
|
||||
default:
|
||||
return nil, fmt.Errorf("cannot create certificate signing request: %v", err)
|
||||
}
|
||||
|
||||
fieldSelector := fields.OneTermEqualSelector("metadata.name", req.Name).String()
|
||||
|
||||
event, err := cache.ListWatchUntil(
|
||||
3600*time.Second,
|
||||
&cache.ListWatch{
|
||||
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
||||
options.FieldSelector = fieldSelector
|
||||
return client.List(options)
|
||||
},
|
||||
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
|
||||
options.FieldSelector = fieldSelector
|
||||
return client.Watch(options)
|
||||
},
|
||||
},
|
||||
func(event watch.Event) (bool, error) {
|
||||
switch event.Type {
|
||||
case watch.Modified, watch.Added:
|
||||
default:
|
||||
return false, nil
|
||||
}
|
||||
csr := event.Object.(*certificates.CertificateSigningRequest)
|
||||
if csr.UID != req.UID {
|
||||
return false, fmt.Errorf("csr %q changed UIDs", csr.Name)
|
||||
}
|
||||
for _, c := range csr.Status.Conditions {
|
||||
if c.Type == certificates.CertificateDenied {
|
||||
return false, fmt.Errorf("certificate signing request is not approved, reason: %v, message: %v", c.Reason, c.Message)
|
||||
}
|
||||
if c.Type == certificates.CertificateApproved && csr.Status.Certificate != nil {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot watch on the certificate signing request: %v", err)
|
||||
}
|
||||
|
||||
return event.Object.(*certificates.CertificateSigningRequest).Status.Certificate, nil
|
||||
|
||||
}
|
||||
|
||||
// This digest should include all the relevant pieces of the CSR we care about.
|
||||
// We can't direcly hash the serialized CSR because of random padding that we
|
||||
// regenerate every loop and we include usages which are not contained in the
|
||||
// CSR. This needs to be kept up to date as we add new fields to the node
|
||||
// certificates and with ensureCompatible.
|
||||
func digestedName(privateKeyData []byte, subject *pkix.Name, usages []certificates.KeyUsage) string {
|
||||
hash := sha512.New512_256()
|
||||
|
||||
// Here we make sure two different inputs can't write the same stream
|
||||
// to the hash. This delimiter is not in the base64.URLEncoding
|
||||
// alphabet so there is no way to have spill over collisions. Without
|
||||
// it 'CN:foo,ORG:bar' hashes to the same value as 'CN:foob,ORG:ar'
|
||||
const delimiter = '|'
|
||||
encode := base64.RawURLEncoding.EncodeToString
|
||||
|
||||
write := func(data []byte) {
|
||||
hash.Write([]byte(encode(data)))
|
||||
hash.Write([]byte{delimiter})
|
||||
}
|
||||
|
||||
write(privateKeyData)
|
||||
write([]byte(subject.CommonName))
|
||||
for _, v := range subject.Organization {
|
||||
write([]byte(v))
|
||||
}
|
||||
for _, v := range usages {
|
||||
write([]byte(v))
|
||||
}
|
||||
|
||||
return "node-csr-" + encode(hash.Sum(nil))
|
||||
}
|
||||
|
||||
// ensureCompatible ensures that a CSR object is compatible with an original CSR
|
||||
func ensureCompatible(new, orig *certificates.CertificateSigningRequest, privateKey interface{}) error {
|
||||
newCsr, err := certhelper.ParseCSR(new)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to parse new csr: %v", err)
|
||||
}
|
||||
origCsr, err := certhelper.ParseCSR(orig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to parse original csr: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(newCsr.Subject, origCsr.Subject) {
|
||||
return fmt.Errorf("csr subjects differ: new: %#v, orig: %#v", newCsr.Subject, origCsr.Subject)
|
||||
}
|
||||
signer, ok := privateKey.(crypto.Signer)
|
||||
if !ok {
|
||||
return fmt.Errorf("privateKey is not a signer")
|
||||
}
|
||||
newCsr.PublicKey = signer.Public()
|
||||
if err := newCsr.CheckSignature(); err != nil {
|
||||
return fmt.Errorf("error validating signature new CSR against old key: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
136
vendor/k8s.io/kubernetes/pkg/kubelet/util/csr/csr_test.go
generated
vendored
Normal file
136
vendor/k8s.io/kubernetes/pkg/kubelet/util/csr/csr_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
/*
|
||||
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 csr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
certificates "k8s.io/api/certificates/v1beta1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
watch "k8s.io/apimachinery/pkg/watch"
|
||||
certificatesclient "k8s.io/client-go/kubernetes/typed/certificates/v1beta1"
|
||||
certutil "k8s.io/client-go/util/cert"
|
||||
)
|
||||
|
||||
func TestRequestNodeCertificateNoKeyData(t *testing.T) {
|
||||
certData, err := RequestNodeCertificate(&fakeClient{}, []byte{}, "fake-node-name")
|
||||
if err == nil {
|
||||
t.Errorf("Got no error, wanted error an error because there was an empty private key passed in.")
|
||||
}
|
||||
if certData != nil {
|
||||
t.Errorf("Got cert data, wanted nothing as there should have been an error.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequestNodeCertificateErrorCreatingCSR(t *testing.T) {
|
||||
client := &fakeClient{
|
||||
failureType: createError,
|
||||
}
|
||||
privateKeyData, err := certutil.MakeEllipticPrivateKeyPEM()
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to generate a new private key: %v", err)
|
||||
}
|
||||
|
||||
certData, err := RequestNodeCertificate(client, privateKeyData, "fake-node-name")
|
||||
if err == nil {
|
||||
t.Errorf("Got no error, wanted error an error because client.Create failed.")
|
||||
}
|
||||
if certData != nil {
|
||||
t.Errorf("Got cert data, wanted nothing as there should have been an error.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequestNodeCertificate(t *testing.T) {
|
||||
privateKeyData, err := certutil.MakeEllipticPrivateKeyPEM()
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to generate a new private key: %v", err)
|
||||
}
|
||||
|
||||
certData, err := RequestNodeCertificate(&fakeClient{}, privateKeyData, "fake-node-name")
|
||||
if err != nil {
|
||||
t.Errorf("Got %v, wanted no error.", err)
|
||||
}
|
||||
if certData == nil {
|
||||
t.Errorf("Got nothing, expected a CSR.")
|
||||
}
|
||||
}
|
||||
|
||||
type FailureType int
|
||||
|
||||
const (
|
||||
noError FailureType = iota
|
||||
createError
|
||||
certificateSigningRequestDenied
|
||||
)
|
||||
|
||||
type fakeClient struct {
|
||||
certificatesclient.CertificateSigningRequestInterface
|
||||
watch *watch.FakeWatcher
|
||||
failureType FailureType
|
||||
}
|
||||
|
||||
func (c *fakeClient) Create(*certificates.CertificateSigningRequest) (*certificates.CertificateSigningRequest, error) {
|
||||
if c.failureType == createError {
|
||||
return nil, fmt.Errorf("fakeClient failed creating request")
|
||||
}
|
||||
csr := certificates.CertificateSigningRequest{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
UID: "fake-uid",
|
||||
Name: "fake-certificate-signing-request-name",
|
||||
},
|
||||
}
|
||||
return &csr, nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) List(opts v1.ListOptions) (*certificates.CertificateSigningRequestList, error) {
|
||||
return &certificates.CertificateSigningRequestList{}, nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) Watch(opts v1.ListOptions) (watch.Interface, error) {
|
||||
c.watch = watch.NewFakeWithChanSize(1, false)
|
||||
c.watch.Add(c.generateCSR())
|
||||
c.watch.Stop()
|
||||
return c.watch, nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) generateCSR() *certificates.CertificateSigningRequest {
|
||||
var condition certificates.CertificateSigningRequestCondition
|
||||
if c.failureType == certificateSigningRequestDenied {
|
||||
condition = certificates.CertificateSigningRequestCondition{
|
||||
Type: certificates.CertificateDenied,
|
||||
}
|
||||
} else {
|
||||
condition = certificates.CertificateSigningRequestCondition{
|
||||
Type: certificates.CertificateApproved,
|
||||
}
|
||||
}
|
||||
|
||||
csr := certificates.CertificateSigningRequest{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
UID: "fake-uid",
|
||||
},
|
||||
Status: certificates.CertificateSigningRequestStatus{
|
||||
Conditions: []certificates.CertificateSigningRequestCondition{
|
||||
condition,
|
||||
},
|
||||
Certificate: []byte{},
|
||||
},
|
||||
}
|
||||
return &csr
|
||||
}
|
||||
18
vendor/k8s.io/kubernetes/pkg/kubelet/util/doc.go
generated
vendored
Normal file
18
vendor/k8s.io/kubernetes/pkg/kubelet/util/doc.go
generated
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
Copyright 2015 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.
|
||||
*/
|
||||
|
||||
// Utility functions.
|
||||
package util // import "k8s.io/kubernetes/pkg/kubelet/util"
|
||||
42
vendor/k8s.io/kubernetes/pkg/kubelet/util/format/BUILD
generated
vendored
Normal file
42
vendor/k8s.io/kubernetes/pkg/kubelet/util/format/BUILD
generated
vendored
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
"go_test",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"pod.go",
|
||||
"resources.go",
|
||||
],
|
||||
deps = [
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["resources_test.go"],
|
||||
library = ":go_default_library",
|
||||
deps = [
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/api/resource:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
72
vendor/k8s.io/kubernetes/pkg/kubelet/util/format/pod.go
generated
vendored
Normal file
72
vendor/k8s.io/kubernetes/pkg/kubelet/util/format/pod.go
generated
vendored
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
Copyright 2015 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 format
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
)
|
||||
|
||||
type podHandler func(*v1.Pod) string
|
||||
|
||||
// Pod returns a string representing a pod in a consistent human readable format,
|
||||
// with pod UID as part of the string.
|
||||
func Pod(pod *v1.Pod) string {
|
||||
return PodDesc(pod.Name, pod.Namespace, pod.UID)
|
||||
}
|
||||
|
||||
// PodDesc returns a string representing a pod in a consistent human readable format,
|
||||
// with pod UID as part of the string.
|
||||
func PodDesc(podName, podNamespace string, podUID types.UID) string {
|
||||
// Use underscore as the delimiter because it is not allowed in pod name
|
||||
// (DNS subdomain format), while allowed in the container name format.
|
||||
return fmt.Sprintf("%s_%s(%s)", podName, podNamespace, podUID)
|
||||
}
|
||||
|
||||
// PodWithDeletionTimestamp is the same as Pod. In addition, it prints the
|
||||
// deletion timestamp of the pod if it's not nil.
|
||||
func PodWithDeletionTimestamp(pod *v1.Pod) string {
|
||||
var deletionTimestamp string
|
||||
if pod.DeletionTimestamp != nil {
|
||||
deletionTimestamp = ":DeletionTimestamp=" + pod.DeletionTimestamp.UTC().Format(time.RFC3339)
|
||||
}
|
||||
return Pod(pod) + deletionTimestamp
|
||||
}
|
||||
|
||||
// Pods returns a string representating a list of pods in a human
|
||||
// readable format.
|
||||
func Pods(pods []*v1.Pod) string {
|
||||
return aggregatePods(pods, Pod)
|
||||
}
|
||||
|
||||
// PodsWithDeletiontimestamps is the same as Pods. In addition, it prints the
|
||||
// deletion timestamps of the pods if they are not nil.
|
||||
func PodsWithDeletiontimestamps(pods []*v1.Pod) string {
|
||||
return aggregatePods(pods, PodWithDeletionTimestamp)
|
||||
}
|
||||
|
||||
func aggregatePods(pods []*v1.Pod, handler podHandler) string {
|
||||
podStrings := make([]string, 0, len(pods))
|
||||
for _, pod := range pods {
|
||||
podStrings = append(podStrings, handler(pod))
|
||||
}
|
||||
return fmt.Sprintf(strings.Join(podStrings, ", "))
|
||||
}
|
||||
36
vendor/k8s.io/kubernetes/pkg/kubelet/util/format/resources.go
generated
vendored
Normal file
36
vendor/k8s.io/kubernetes/pkg/kubelet/util/format/resources.go
generated
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
Copyright 2016 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 format
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
// ResourceList returns a string representation of a resource list in a human readable format.
|
||||
func ResourceList(resources v1.ResourceList) string {
|
||||
resourceStrings := make([]string, 0, len(resources))
|
||||
for key, value := range resources {
|
||||
resourceStrings = append(resourceStrings, fmt.Sprintf("%v=%v", key, value.String()))
|
||||
}
|
||||
// sort the results for consistent log output
|
||||
sort.Strings(resourceStrings)
|
||||
return strings.Join(resourceStrings, ",")
|
||||
}
|
||||
35
vendor/k8s.io/kubernetes/pkg/kubelet/util/format/resources_test.go
generated
vendored
Normal file
35
vendor/k8s.io/kubernetes/pkg/kubelet/util/format/resources_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
Copyright 2016 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 format
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
)
|
||||
|
||||
func TestResourceList(t *testing.T) {
|
||||
resourceList := v1.ResourceList{}
|
||||
resourceList[v1.ResourceCPU] = resource.MustParse("100m")
|
||||
resourceList[v1.ResourceMemory] = resource.MustParse("5Gi")
|
||||
actual := ResourceList(resourceList)
|
||||
expected := "cpu=100m,memory=5Gi"
|
||||
if actual != expected {
|
||||
t.Errorf("Unexpected result, actual: %v, expected: %v", actual, expected)
|
||||
}
|
||||
}
|
||||
24
vendor/k8s.io/kubernetes/pkg/kubelet/util/ioutils/BUILD
generated
vendored
Normal file
24
vendor/k8s.io/kubernetes/pkg/kubelet/util/ioutils/BUILD
generated
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["ioutils.go"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
37
vendor/k8s.io/kubernetes/pkg/kubelet/util/ioutils/ioutils.go
generated
vendored
Normal file
37
vendor/k8s.io/kubernetes/pkg/kubelet/util/ioutils/ioutils.go
generated
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
Copyright 2016 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 ioutils
|
||||
|
||||
import "io"
|
||||
|
||||
// writeCloserWrapper represents a WriteCloser whose closer operation is noop.
|
||||
type writeCloserWrapper struct {
|
||||
Writer io.Writer
|
||||
}
|
||||
|
||||
func (w *writeCloserWrapper) Write(buf []byte) (int, error) {
|
||||
return w.Writer.Write(buf)
|
||||
}
|
||||
|
||||
func (w *writeCloserWrapper) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// WriteCloserWrapper returns a writeCloserWrapper.
|
||||
func WriteCloserWrapper(w io.Writer) io.WriteCloser {
|
||||
return &writeCloserWrapper{w}
|
||||
}
|
||||
40
vendor/k8s.io/kubernetes/pkg/kubelet/util/queue/BUILD
generated
vendored
Normal file
40
vendor/k8s.io/kubernetes/pkg/kubelet/util/queue/BUILD
generated
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
"go_test",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["work_queue.go"],
|
||||
deps = [
|
||||
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/clock:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["work_queue_test.go"],
|
||||
library = ":go_default_library",
|
||||
deps = [
|
||||
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/clock:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
67
vendor/k8s.io/kubernetes/pkg/kubelet/util/queue/work_queue.go
generated
vendored
Normal file
67
vendor/k8s.io/kubernetes/pkg/kubelet/util/queue/work_queue.go
generated
vendored
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
Copyright 2015 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 queue
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/clock"
|
||||
)
|
||||
|
||||
// WorkQueue allows queuing items with a timestamp. An item is
|
||||
// considered ready to process if the timestamp has expired.
|
||||
type WorkQueue interface {
|
||||
// GetWork dequeues and returns all ready items.
|
||||
GetWork() []types.UID
|
||||
// Enqueue inserts a new item or overwrites an existing item.
|
||||
Enqueue(item types.UID, delay time.Duration)
|
||||
}
|
||||
|
||||
type basicWorkQueue struct {
|
||||
clock clock.Clock
|
||||
lock sync.Mutex
|
||||
queue map[types.UID]time.Time
|
||||
}
|
||||
|
||||
var _ WorkQueue = &basicWorkQueue{}
|
||||
|
||||
func NewBasicWorkQueue(clock clock.Clock) WorkQueue {
|
||||
queue := make(map[types.UID]time.Time)
|
||||
return &basicWorkQueue{queue: queue, clock: clock}
|
||||
}
|
||||
|
||||
func (q *basicWorkQueue) GetWork() []types.UID {
|
||||
q.lock.Lock()
|
||||
defer q.lock.Unlock()
|
||||
now := q.clock.Now()
|
||||
var items []types.UID
|
||||
for k, v := range q.queue {
|
||||
if v.Before(now) {
|
||||
items = append(items, k)
|
||||
delete(q.queue, k)
|
||||
}
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func (q *basicWorkQueue) Enqueue(item types.UID, delay time.Duration) {
|
||||
q.lock.Lock()
|
||||
defer q.lock.Unlock()
|
||||
q.queue[item] = q.clock.Now().Add(delay)
|
||||
}
|
||||
65
vendor/k8s.io/kubernetes/pkg/kubelet/util/queue/work_queue_test.go
generated
vendored
Normal file
65
vendor/k8s.io/kubernetes/pkg/kubelet/util/queue/work_queue_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
Copyright 2015 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 queue
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/clock"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
)
|
||||
|
||||
func newTestBasicWorkQueue() (*basicWorkQueue, *clock.FakeClock) {
|
||||
fakeClock := clock.NewFakeClock(time.Now())
|
||||
wq := &basicWorkQueue{
|
||||
clock: fakeClock,
|
||||
queue: make(map[types.UID]time.Time),
|
||||
}
|
||||
return wq, fakeClock
|
||||
}
|
||||
|
||||
func compareResults(t *testing.T, expected, actual []types.UID) {
|
||||
expectedSet := sets.NewString()
|
||||
for _, u := range expected {
|
||||
expectedSet.Insert(string(u))
|
||||
}
|
||||
actualSet := sets.NewString()
|
||||
for _, u := range actual {
|
||||
actualSet.Insert(string(u))
|
||||
}
|
||||
if !expectedSet.Equal(actualSet) {
|
||||
t.Errorf("Expected %#v, got %#v", expectedSet.List(), actualSet.List())
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetWork(t *testing.T) {
|
||||
q, clock := newTestBasicWorkQueue()
|
||||
q.Enqueue(types.UID("foo1"), -1*time.Minute)
|
||||
q.Enqueue(types.UID("foo2"), -1*time.Minute)
|
||||
q.Enqueue(types.UID("foo3"), 1*time.Minute)
|
||||
q.Enqueue(types.UID("foo4"), 1*time.Minute)
|
||||
expected := []types.UID{types.UID("foo1"), types.UID("foo2")}
|
||||
compareResults(t, expected, q.GetWork())
|
||||
compareResults(t, []types.UID{}, q.GetWork())
|
||||
// Dial the time to 1 hour ahead.
|
||||
clock.Step(time.Hour)
|
||||
expected = []types.UID{types.UID("foo3"), types.UID("foo4")}
|
||||
compareResults(t, expected, q.GetWork())
|
||||
compareResults(t, []types.UID{}, q.GetWork())
|
||||
}
|
||||
40
vendor/k8s.io/kubernetes/pkg/kubelet/util/sliceutils/BUILD
generated
vendored
Normal file
40
vendor/k8s.io/kubernetes/pkg/kubelet/util/sliceutils/BUILD
generated
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
"go_test",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["sliceutils.go"],
|
||||
deps = [
|
||||
"//pkg/kubelet/container:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["sliceutils_test.go"],
|
||||
library = ":go_default_library",
|
||||
deps = [
|
||||
"//pkg/kubelet/container:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
],
|
||||
)
|
||||
58
vendor/k8s.io/kubernetes/pkg/kubelet/util/sliceutils/sliceutils.go
generated
vendored
Normal file
58
vendor/k8s.io/kubernetes/pkg/kubelet/util/sliceutils/sliceutils.go
generated
vendored
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
Copyright 2015 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 sliceutils
|
||||
|
||||
import (
|
||||
"k8s.io/api/core/v1"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
)
|
||||
|
||||
func StringInSlice(s string, list []string) bool {
|
||||
for _, v := range list {
|
||||
if v == s {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// PodsByCreationTime makes an array of pods sortable by their creation
|
||||
// timestamps in ascending order.
|
||||
type PodsByCreationTime []*v1.Pod
|
||||
|
||||
func (s PodsByCreationTime) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func (s PodsByCreationTime) Swap(i, j int) {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
|
||||
func (s PodsByCreationTime) Less(i, j int) bool {
|
||||
return s[i].CreationTimestamp.Before(&s[j].CreationTimestamp)
|
||||
}
|
||||
|
||||
// ByImageSize makes an array of images sortable by their size in descending
|
||||
// order.
|
||||
type ByImageSize []kubecontainer.Image
|
||||
|
||||
func (a ByImageSize) Less(i, j int) bool {
|
||||
return a[i].Size > a[j].Size
|
||||
}
|
||||
func (a ByImageSize) Len() int { return len(a) }
|
||||
func (a ByImageSize) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
222
vendor/k8s.io/kubernetes/pkg/kubelet/util/sliceutils/sliceutils_test.go
generated
vendored
Normal file
222
vendor/k8s.io/kubernetes/pkg/kubelet/util/sliceutils/sliceutils_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,222 @@
|
|||
/*
|
||||
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 sliceutils
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestStringInSlice(t *testing.T) {
|
||||
fooTests := []struct {
|
||||
s string
|
||||
list []string
|
||||
er bool
|
||||
}{
|
||||
{"first", []string{"first", "second"}, true},
|
||||
{"FIRST", []string{"first", "second"}, false},
|
||||
{"third", []string{"first", "second"}, false},
|
||||
{"first", nil, false},
|
||||
|
||||
{"", []string{"first", "second"}, false},
|
||||
{"", []string{"first", "second", ""}, true},
|
||||
{"", nil, false},
|
||||
}
|
||||
|
||||
for _, fooTest := range fooTests {
|
||||
r := StringInSlice(fooTest.s, fooTest.list)
|
||||
if r != fooTest.er {
|
||||
t.Errorf("returned %t but expected %t for s=%s & list=%s", r, fooTest.er, fooTest.s, fooTest.list)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func buildPodsByCreationTime() PodsByCreationTime {
|
||||
return []*v1.Pod{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "foo1",
|
||||
Namespace: v1.NamespaceDefault,
|
||||
CreationTimestamp: metav1.Time{
|
||||
Time: time.Now(),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "foo2",
|
||||
Namespace: v1.NamespaceDefault,
|
||||
CreationTimestamp: metav1.Time{
|
||||
Time: time.Now().Add(time.Hour * 1),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "foo3",
|
||||
Namespace: v1.NamespaceDefault,
|
||||
CreationTimestamp: metav1.Time{
|
||||
Time: time.Now().Add(time.Hour * 2),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func TestPodsByCreationTimeLen(t *testing.T) {
|
||||
fooTests := []struct {
|
||||
pods PodsByCreationTime
|
||||
el int
|
||||
}{
|
||||
{[]*v1.Pod{}, 0},
|
||||
{buildPodsByCreationTime(), 3},
|
||||
{[]*v1.Pod{nil, {}}, 2},
|
||||
{nil, 0},
|
||||
}
|
||||
|
||||
for _, fooTest := range fooTests {
|
||||
r := fooTest.pods.Len()
|
||||
if r != fooTest.el {
|
||||
t.Errorf("returned %d but expected %d for the len of PodsByCreationTime=%s", r, fooTest.el, fooTest.pods)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPodsByCreationTimeSwap(t *testing.T) {
|
||||
fooTests := []struct {
|
||||
pods PodsByCreationTime
|
||||
i int
|
||||
j int
|
||||
}{
|
||||
{buildPodsByCreationTime(), 0, 1},
|
||||
{buildPodsByCreationTime(), 2, 1},
|
||||
}
|
||||
|
||||
for _, fooTest := range fooTests {
|
||||
fooi := fooTest.pods[fooTest.i]
|
||||
fooj := fooTest.pods[fooTest.j]
|
||||
fooTest.pods.Swap(fooTest.i, fooTest.j)
|
||||
if fooi.GetName() != fooTest.pods[fooTest.j].GetName() || fooj.GetName() != fooTest.pods[fooTest.i].GetName() {
|
||||
t.Errorf("failed to swap for %v", fooTest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPodsByCreationTimeLess(t *testing.T) {
|
||||
fooTests := []struct {
|
||||
pods PodsByCreationTime
|
||||
i int
|
||||
j int
|
||||
er bool
|
||||
}{
|
||||
// ascending order
|
||||
{buildPodsByCreationTime(), 0, 2, true},
|
||||
{buildPodsByCreationTime(), 1, 0, false},
|
||||
}
|
||||
|
||||
for _, fooTest := range fooTests {
|
||||
r := fooTest.pods.Less(fooTest.i, fooTest.j)
|
||||
if r != fooTest.er {
|
||||
t.Errorf("returned %t but expected %t for the foo=%s", r, fooTest.er, fooTest.pods)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func buildByImageSize() ByImageSize {
|
||||
return []kubecontainer.Image{
|
||||
{
|
||||
ID: "1",
|
||||
RepoTags: []string{"foo-tag11", "foo-tag12"},
|
||||
RepoDigests: []string{"foo-rd11", "foo-rd12"},
|
||||
Size: 1,
|
||||
},
|
||||
{
|
||||
ID: "2",
|
||||
RepoTags: []string{"foo-tag21", "foo-tag22"},
|
||||
RepoDigests: []string{"foo-rd21", "foo-rd22"},
|
||||
Size: 2,
|
||||
},
|
||||
{
|
||||
ID: "3",
|
||||
RepoTags: []string{"foo-tag31", "foo-tag32"},
|
||||
RepoDigests: []string{"foo-rd31", "foo-rd32"},
|
||||
Size: 3,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func TestByImageSizeLen(t *testing.T) {
|
||||
fooTests := []struct {
|
||||
images ByImageSize
|
||||
el int
|
||||
}{
|
||||
{[]kubecontainer.Image{}, 0},
|
||||
{buildByImageSize(), 3},
|
||||
{nil, 0},
|
||||
}
|
||||
|
||||
for _, fooTest := range fooTests {
|
||||
r := fooTest.images.Len()
|
||||
if r != fooTest.el {
|
||||
t.Errorf("returned %d but expected %d for the len of ByImageSize=%v", r, fooTest.el, fooTest.images)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestByImageSizeSwap(t *testing.T) {
|
||||
fooTests := []struct {
|
||||
images ByImageSize
|
||||
i int
|
||||
j int
|
||||
}{
|
||||
{buildByImageSize(), 0, 1},
|
||||
{buildByImageSize(), 2, 1},
|
||||
}
|
||||
|
||||
for _, fooTest := range fooTests {
|
||||
fooi := fooTest.images[fooTest.i]
|
||||
fooj := fooTest.images[fooTest.j]
|
||||
fooTest.images.Swap(fooTest.i, fooTest.j)
|
||||
if fooi.ID != fooTest.images[fooTest.j].ID || fooj.ID != fooTest.images[fooTest.i].ID {
|
||||
t.Errorf("failed to swap for %v", fooTest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestByImageSizeLess(t *testing.T) {
|
||||
fooTests := []struct {
|
||||
images ByImageSize
|
||||
i int
|
||||
j int
|
||||
er bool
|
||||
}{
|
||||
// descending order
|
||||
{buildByImageSize(), 0, 2, false},
|
||||
{buildByImageSize(), 1, 0, true},
|
||||
}
|
||||
|
||||
for _, fooTest := range fooTests {
|
||||
r := fooTest.images.Less(fooTest.i, fooTest.j)
|
||||
if r != fooTest.er {
|
||||
t.Errorf("returned %t but expected %t for the foo=%v", r, fooTest.er, fooTest.images)
|
||||
}
|
||||
}
|
||||
}
|
||||
47
vendor/k8s.io/kubernetes/pkg/kubelet/util/util.go
generated
vendored
Normal file
47
vendor/k8s.io/kubernetes/pkg/kubelet/util/util.go
generated
vendored
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
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 util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
// FromApiserverCache modifies <opts> so that the GET request will
|
||||
// be served from apiserver cache instead of from etcd.
|
||||
func FromApiserverCache(opts *metav1.GetOptions) {
|
||||
opts.ResourceVersion = "0"
|
||||
}
|
||||
|
||||
func parseEndpoint(endpoint string) (string, string, error) {
|
||||
u, err := url.Parse(endpoint)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
if u.Scheme == "tcp" {
|
||||
return "tcp", u.Host, nil
|
||||
} else if u.Scheme == "unix" {
|
||||
return "unix", u.Path, nil
|
||||
} else if u.Scheme == "" {
|
||||
return "", "", fmt.Errorf("Using %q as endpoint is deprecated, please consider using full url format", endpoint)
|
||||
} else {
|
||||
return u.Scheme, "", fmt.Errorf("protocol %q not supported", u.Scheme)
|
||||
}
|
||||
}
|
||||
64
vendor/k8s.io/kubernetes/pkg/kubelet/util/util_test.go
generated
vendored
Normal file
64
vendor/k8s.io/kubernetes/pkg/kubelet/util/util_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
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 util
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestParseEndpoint(t *testing.T) {
|
||||
tests := []struct {
|
||||
endpoint string
|
||||
expectError bool
|
||||
expectedProtocol string
|
||||
expectedAddr string
|
||||
}{
|
||||
{
|
||||
endpoint: "unix:///tmp/s1.sock",
|
||||
expectedProtocol: "unix",
|
||||
expectedAddr: "/tmp/s1.sock",
|
||||
},
|
||||
{
|
||||
endpoint: "tcp://localhost:15880",
|
||||
expectedProtocol: "tcp",
|
||||
expectedAddr: "localhost:15880",
|
||||
},
|
||||
{
|
||||
endpoint: "tcp1://abc",
|
||||
expectedProtocol: "tcp1",
|
||||
expectError: true,
|
||||
},
|
||||
{
|
||||
endpoint: "a b c",
|
||||
expectError: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
protocol, addr, err := parseEndpoint(test.endpoint)
|
||||
assert.Equal(t, test.expectedProtocol, protocol)
|
||||
if test.expectError {
|
||||
assert.NotNil(t, err, "Expect error during parsing %q", test.endpoint)
|
||||
continue
|
||||
}
|
||||
assert.Nil(t, err, "Expect no error during parsing %q", test.endpoint)
|
||||
assert.Equal(t, test.expectedAddr, addr)
|
||||
}
|
||||
|
||||
}
|
||||
79
vendor/k8s.io/kubernetes/pkg/kubelet/util/util_unix.go
generated
vendored
Normal file
79
vendor/k8s.io/kubernetes/pkg/kubelet/util/util_unix.go
generated
vendored
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
// +build freebsd linux
|
||||
|
||||
/*
|
||||
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 util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
const (
|
||||
// unixProtocol is the network protocol of unix socket.
|
||||
unixProtocol = "unix"
|
||||
)
|
||||
|
||||
func CreateListener(endpoint string) (net.Listener, error) {
|
||||
protocol, addr, err := parseEndpointWithFallbackProtocol(endpoint, unixProtocol)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if protocol != unixProtocol {
|
||||
return nil, fmt.Errorf("only support unix socket endpoint")
|
||||
}
|
||||
|
||||
// Unlink to cleanup the previous socket file.
|
||||
err = unix.Unlink(addr)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return nil, fmt.Errorf("failed to unlink socket file %q: %v", addr, err)
|
||||
}
|
||||
|
||||
return net.Listen(protocol, addr)
|
||||
}
|
||||
|
||||
func GetAddressAndDialer(endpoint string) (string, func(addr string, timeout time.Duration) (net.Conn, error), error) {
|
||||
protocol, addr, err := parseEndpointWithFallbackProtocol(endpoint, unixProtocol)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if protocol != unixProtocol {
|
||||
return "", nil, fmt.Errorf("only support unix socket endpoint")
|
||||
}
|
||||
|
||||
return addr, dial, nil
|
||||
}
|
||||
|
||||
func dial(addr string, timeout time.Duration) (net.Conn, error) {
|
||||
return net.DialTimeout(unixProtocol, addr, timeout)
|
||||
}
|
||||
|
||||
func parseEndpointWithFallbackProtocol(endpoint string, fallbackProtocol string) (protocol string, addr string, err error) {
|
||||
if protocol, addr, err = parseEndpoint(endpoint); err != nil && protocol == "" {
|
||||
fallbackEndpoint := fallbackProtocol + "://" + endpoint
|
||||
protocol, addr, err = parseEndpoint(fallbackEndpoint)
|
||||
if err == nil {
|
||||
glog.Warningf("Using %q as endpoint is deprecated, please consider using full url format %q.", endpoint, fallbackEndpoint)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
33
vendor/k8s.io/kubernetes/pkg/kubelet/util/util_unsupported.go
generated
vendored
Normal file
33
vendor/k8s.io/kubernetes/pkg/kubelet/util/util_unsupported.go
generated
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// +build !freebsd,!linux,!windows
|
||||
|
||||
/*
|
||||
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 util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
func CreateListener(endpoint string) (net.Listener, error) {
|
||||
return nil, fmt.Errorf("CreateListener is unsupported in this build")
|
||||
}
|
||||
|
||||
func GetAddressAndDialer(endpoint string) (string, func(addr string, timeout time.Duration) (net.Conn, error), error) {
|
||||
return "", nil, fmt.Errorf("GetAddressAndDialer is unsupported in this build")
|
||||
}
|
||||
57
vendor/k8s.io/kubernetes/pkg/kubelet/util/util_windows.go
generated
vendored
Normal file
57
vendor/k8s.io/kubernetes/pkg/kubelet/util/util_windows.go
generated
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
// +build windows
|
||||
|
||||
/*
|
||||
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 util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
tcpProtocol = "tcp"
|
||||
)
|
||||
|
||||
func CreateListener(endpoint string) (net.Listener, error) {
|
||||
protocol, addr, err := parseEndpoint(endpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if protocol != tcpProtocol {
|
||||
return nil, fmt.Errorf("only support tcp endpoint")
|
||||
}
|
||||
|
||||
return net.Listen(protocol, addr)
|
||||
}
|
||||
|
||||
func GetAddressAndDialer(endpoint string) (string, func(addr string, timeout time.Duration) (net.Conn, error), error) {
|
||||
protocol, addr, err := parseEndpoint(endpoint)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if protocol != tcpProtocol {
|
||||
return "", nil, fmt.Errorf("only support tcp endpoint")
|
||||
}
|
||||
|
||||
return addr, dial, nil
|
||||
}
|
||||
|
||||
func dial(addr string, timeout time.Duration) (net.Conn, error) {
|
||||
return net.DialTimeout(tcpProtocol, addr, timeout)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue