1
0
Fork 0
forked from barak/tarpoon

Add glide.yaml and vendor deps

This commit is contained in:
Dalton Hubble 2016-12-03 22:43:32 -08:00
parent db918f12ad
commit 5b3d5e81bd
18880 changed files with 5166045 additions and 1 deletions

View file

@ -0,0 +1,41 @@
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_binary",
"go_library",
"go_test",
"cgo_library",
)
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"endpoint.go",
"etcd.go",
"node.go",
"service.go",
],
tags = ["automanaged"],
deps = [
"//pkg/api:go_default_library",
"//pkg/api/errors:go_default_library",
"//pkg/api/meta:go_default_library",
"//pkg/api/rest/resttest:go_default_library",
"//pkg/api/testapi:go_default_library",
"//pkg/apimachinery/registered:go_default_library",
"//pkg/apis/meta/v1:go_default_library",
"//pkg/fields:go_default_library",
"//pkg/labels:go_default_library",
"//pkg/registry/generic/registry:go_default_library",
"//pkg/runtime:go_default_library",
"//pkg/storage/etcd:go_default_library",
"//pkg/storage/etcd/testing:go_default_library",
"//pkg/storage/storagebackend:go_default_library",
"//pkg/storage/testing:go_default_library",
"//pkg/watch:go_default_library",
],
)

View file

@ -0,0 +1,19 @@
/*
Copyright 2014 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 registrytest provides tests for Registry implementations
// for storing Nodes, Pods, Schedulers and Services.
package registrytest // import "k8s.io/kubernetes/pkg/registry/registrytest"

View file

@ -0,0 +1,110 @@
/*
Copyright 2014 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 registrytest
import (
"fmt"
"sync"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/watch"
)
// Registry is an interface for things that know how to store endpoints.
type EndpointRegistry struct {
Endpoints *api.EndpointsList
Updates []api.Endpoints
Err error
lock sync.Mutex
}
func (e *EndpointRegistry) ListEndpoints(ctx api.Context, options *api.ListOptions) (*api.EndpointsList, error) {
// TODO: support namespaces in this mock
e.lock.Lock()
defer e.lock.Unlock()
return e.Endpoints, e.Err
}
func (e *EndpointRegistry) GetEndpoints(ctx api.Context, name string) (*api.Endpoints, error) {
// TODO: support namespaces in this mock
e.lock.Lock()
defer e.lock.Unlock()
if e.Err != nil {
return nil, e.Err
}
if e.Endpoints != nil {
for _, endpoint := range e.Endpoints.Items {
if endpoint.Name == name {
return &endpoint, nil
}
}
}
return nil, errors.NewNotFound(api.Resource("endpoints"), name)
}
func (e *EndpointRegistry) WatchEndpoints(ctx api.Context, options *api.ListOptions) (watch.Interface, error) {
return nil, fmt.Errorf("unimplemented!")
}
func (e *EndpointRegistry) UpdateEndpoints(ctx api.Context, endpoints *api.Endpoints) error {
// TODO: support namespaces in this mock
e.lock.Lock()
defer e.lock.Unlock()
e.Updates = append(e.Updates, *endpoints)
if e.Err != nil {
return e.Err
}
if e.Endpoints == nil {
e.Endpoints = &api.EndpointsList{
Items: []api.Endpoints{
*endpoints,
},
}
return nil
}
for ix := range e.Endpoints.Items {
if e.Endpoints.Items[ix].Name == endpoints.Name {
e.Endpoints.Items[ix] = *endpoints
}
}
e.Endpoints.Items = append(e.Endpoints.Items, *endpoints)
return nil
}
func (e *EndpointRegistry) DeleteEndpoints(ctx api.Context, name string) error {
// TODO: support namespaces in this mock
e.lock.Lock()
defer e.lock.Unlock()
if e.Err != nil {
return e.Err
}
if e.Endpoints != nil {
var newList []api.Endpoints
for _, endpoint := range e.Endpoints.Items {
if endpoint.Name != name {
newList = append(newList, endpoint)
}
}
e.Endpoints.Items = newList
}
return nil
}

View file

@ -0,0 +1,229 @@
/*
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 registrytest
import (
"fmt"
"testing"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/rest/resttest"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/apimachinery/registered"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
genericregistry "k8s.io/kubernetes/pkg/registry/generic/registry"
"k8s.io/kubernetes/pkg/runtime"
etcdstorage "k8s.io/kubernetes/pkg/storage/etcd"
etcdtesting "k8s.io/kubernetes/pkg/storage/etcd/testing"
"k8s.io/kubernetes/pkg/storage/storagebackend"
storagetesting "k8s.io/kubernetes/pkg/storage/testing"
)
func NewEtcdStorage(t *testing.T, group string) (*storagebackend.Config, *etcdtesting.EtcdTestServer) {
server, config := etcdtesting.NewUnsecuredEtcd3TestClientServer(t)
config.Codec = testapi.Groups[group].StorageCodec()
return config, server
}
type Tester struct {
tester *resttest.Tester
storage *genericregistry.Store
}
type UpdateFunc func(runtime.Object) runtime.Object
func New(t *testing.T, storage *genericregistry.Store) *Tester {
return &Tester{
tester: resttest.New(t, storage),
storage: storage,
}
}
func (t *Tester) TestNamespace() string {
return t.tester.TestNamespace()
}
func (t *Tester) ClusterScope() *Tester {
t.tester = t.tester.ClusterScope()
return t
}
func (t *Tester) Namer(namer func(int) string) *Tester {
t.tester = t.tester.Namer(namer)
return t
}
func (t *Tester) AllowCreateOnUpdate() *Tester {
t.tester = t.tester.AllowCreateOnUpdate()
return t
}
func (t *Tester) GeneratesName() *Tester {
t.tester = t.tester.GeneratesName()
return t
}
func (t *Tester) ReturnDeletedObject() *Tester {
t.tester = t.tester.ReturnDeletedObject()
return t
}
func (t *Tester) TestCreate(valid runtime.Object, invalid ...runtime.Object) {
t.tester.TestCreate(
valid,
t.createObject,
t.getObject,
invalid...,
)
}
func (t *Tester) TestUpdate(valid runtime.Object, validUpdateFunc UpdateFunc, invalidUpdateFunc ...UpdateFunc) {
var invalidFuncs []resttest.UpdateFunc
for _, f := range invalidUpdateFunc {
invalidFuncs = append(invalidFuncs, resttest.UpdateFunc(f))
}
t.tester.TestUpdate(
valid,
t.createObject,
t.getObject,
resttest.UpdateFunc(validUpdateFunc),
invalidFuncs...,
)
}
func (t *Tester) TestDelete(valid runtime.Object) {
t.tester.TestDelete(
valid,
t.createObject,
t.getObject,
errors.IsNotFound,
)
}
func (t *Tester) TestDeleteGraceful(valid runtime.Object, expectedGrace int64) {
t.tester.TestDeleteGraceful(
valid,
t.createObject,
t.getObject,
expectedGrace,
)
}
func (t *Tester) TestGet(valid runtime.Object) {
t.tester.TestGet(valid)
}
func (t *Tester) TestList(valid runtime.Object) {
t.tester.TestList(
valid,
t.setObjectsForList,
)
}
func (t *Tester) TestWatch(valid runtime.Object, labelsPass, labelsFail []labels.Set, fieldsPass, fieldsFail []fields.Set) {
t.tester.TestWatch(
valid,
t.emitObject,
labelsPass,
labelsFail,
fieldsPass,
fieldsFail,
// TODO: This should be filtered, the registry should not be aware of this level of detail
[]string{etcdstorage.EtcdCreate, etcdstorage.EtcdDelete},
)
}
// =============================================================================
// get codec based on runtime.Object
func getCodec(obj runtime.Object) (runtime.Codec, error) {
fqKinds, _, err := api.Scheme.ObjectKinds(obj)
if err != nil {
return nil, fmt.Errorf("unexpected encoding error: %v", err)
}
fqKind := fqKinds[0]
// TODO: caesarxuchao: we should detect which group an object belongs to
// by using the version returned by Schem.ObjectVersionAndKind() once we
// split the schemes for internal objects.
// TODO: caesarxuchao: we should add a map from kind to group in Scheme.
var codec runtime.Codec
if api.Scheme.Recognizes(registered.GroupOrDie(api.GroupName).GroupVersion.WithKind(fqKind.Kind)) {
codec = testapi.Default.Codec()
} else if api.Scheme.Recognizes(testapi.Extensions.GroupVersion().WithKind(fqKind.Kind)) {
codec = testapi.Extensions.Codec()
} else {
return nil, fmt.Errorf("unexpected kind: %v", fqKind)
}
return codec, nil
}
// Helper functions
func (t *Tester) getObject(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
accessor, err := meta.Accessor(obj)
if err != nil {
return nil, err
}
result, err := t.storage.Get(ctx, accessor.GetName())
if err != nil {
return nil, err
}
return result, nil
}
func (t *Tester) createObject(ctx api.Context, obj runtime.Object) error {
accessor, err := meta.Accessor(obj)
if err != nil {
return err
}
key, err := t.storage.KeyFunc(ctx, accessor.GetName())
if err != nil {
return err
}
return t.storage.Storage.Create(ctx, key, obj, nil, 0)
}
func (t *Tester) setObjectsForList(objects []runtime.Object) []runtime.Object {
key := t.storage.KeyRootFunc(t.tester.TestContext())
if err := storagetesting.CreateObjList(key, t.storage.Storage, objects); err != nil {
t.tester.Errorf("unexpected error: %v", err)
return nil
}
return objects
}
func (t *Tester) emitObject(obj runtime.Object, action string) error {
ctx := t.tester.TestContext()
var err error
switch action {
case etcdstorage.EtcdCreate:
err = t.createObject(ctx, obj)
case etcdstorage.EtcdDelete:
accessor, err := meta.Accessor(obj)
if err != nil {
return err
}
_, err = t.storage.Delete(ctx, accessor.GetName(), nil)
default:
err = fmt.Errorf("unexpected action: %v", action)
}
return err
}

View file

@ -0,0 +1,115 @@
/*
Copyright 2014 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 registrytest
import (
"sync"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/watch"
)
// NodeRegistry implements node.Registry interface.
type NodeRegistry struct {
Err error
Node string
Nodes api.NodeList
sync.Mutex
}
// MakeNodeList constructs api.NodeList from list of node names and a NodeResource.
func MakeNodeList(nodes []string, nodeResources api.NodeResources) *api.NodeList {
list := api.NodeList{
Items: make([]api.Node, len(nodes)),
}
for i := range nodes {
list.Items[i].Name = nodes[i]
list.Items[i].Status.Capacity = nodeResources.Capacity
}
return &list
}
func NewNodeRegistry(nodes []string, nodeResources api.NodeResources) *NodeRegistry {
return &NodeRegistry{
Nodes: *MakeNodeList(nodes, nodeResources),
}
}
func (r *NodeRegistry) SetError(err error) {
r.Lock()
defer r.Unlock()
r.Err = err
}
func (r *NodeRegistry) ListNodes(ctx api.Context, options *api.ListOptions) (*api.NodeList, error) {
r.Lock()
defer r.Unlock()
return &r.Nodes, r.Err
}
func (r *NodeRegistry) CreateNode(ctx api.Context, node *api.Node) error {
r.Lock()
defer r.Unlock()
r.Node = node.Name
r.Nodes.Items = append(r.Nodes.Items, *node)
return r.Err
}
func (r *NodeRegistry) UpdateNode(ctx api.Context, node *api.Node) error {
r.Lock()
defer r.Unlock()
for i, item := range r.Nodes.Items {
if item.Name == node.Name {
r.Nodes.Items[i] = *node
return r.Err
}
}
return r.Err
}
func (r *NodeRegistry) GetNode(ctx api.Context, nodeID string) (*api.Node, error) {
r.Lock()
defer r.Unlock()
if r.Err != nil {
return nil, r.Err
}
for _, node := range r.Nodes.Items {
if node.Name == nodeID {
return &node, nil
}
}
return nil, errors.NewNotFound(api.Resource("nodes"), nodeID)
}
func (r *NodeRegistry) DeleteNode(ctx api.Context, nodeID string) error {
r.Lock()
defer r.Unlock()
var newList []api.Node
for _, node := range r.Nodes.Items {
if node.Name != nodeID {
newList = append(newList, api.Node{ObjectMeta: api.ObjectMeta{Name: node.Name}})
}
}
r.Nodes.Items = newList
return r.Err
}
func (r *NodeRegistry) WatchNodes(ctx api.Context, options *api.ListOptions) (watch.Interface, error) {
return nil, r.Err
}

View file

@ -0,0 +1,127 @@
/*
Copyright 2014 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 registrytest
import (
"sync"
"k8s.io/kubernetes/pkg/api"
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/watch"
)
func NewServiceRegistry() *ServiceRegistry {
return &ServiceRegistry{}
}
type ServiceRegistry struct {
mu sync.Mutex
List api.ServiceList
Service *api.Service
Updates []api.Service
Err error
DeletedID string
GottenID string
UpdatedID string
}
func (r *ServiceRegistry) SetError(err error) {
r.mu.Lock()
defer r.mu.Unlock()
r.Err = err
}
func (r *ServiceRegistry) ListServices(ctx api.Context, options *api.ListOptions) (*api.ServiceList, error) {
r.mu.Lock()
defer r.mu.Unlock()
ns, _ := api.NamespaceFrom(ctx)
// Copy metadata from internal list into result
res := new(api.ServiceList)
res.TypeMeta = r.List.TypeMeta
res.ListMeta = r.List.ListMeta
if ns != api.NamespaceAll {
for _, service := range r.List.Items {
if ns == service.Namespace {
res.Items = append(res.Items, service)
}
}
} else {
res.Items = append([]api.Service{}, r.List.Items...)
}
return res, r.Err
}
func (r *ServiceRegistry) CreateService(ctx api.Context, svc *api.Service) (*api.Service, error) {
r.mu.Lock()
defer r.mu.Unlock()
r.Service = new(api.Service)
clone, err := api.Scheme.DeepCopy(svc)
if err != nil {
return nil, err
}
r.Service = clone.(*api.Service)
r.List.Items = append(r.List.Items, *svc)
return svc, r.Err
}
func (r *ServiceRegistry) GetService(ctx api.Context, id string) (*api.Service, error) {
r.mu.Lock()
defer r.mu.Unlock()
r.GottenID = id
return r.Service, r.Err
}
func (r *ServiceRegistry) DeleteService(ctx api.Context, id string) error {
r.mu.Lock()
defer r.mu.Unlock()
r.DeletedID = id
r.Service = nil
return r.Err
}
func (r *ServiceRegistry) UpdateService(ctx api.Context, svc *api.Service) (*api.Service, error) {
r.mu.Lock()
defer r.mu.Unlock()
r.UpdatedID = svc.Name
*r.Service = *svc
r.Updates = append(r.Updates, *svc)
return svc, r.Err
}
func (r *ServiceRegistry) WatchServices(ctx api.Context, options *api.ListOptions) (watch.Interface, error) {
r.mu.Lock()
defer r.mu.Unlock()
return nil, r.Err
}
func (r *ServiceRegistry) ExportService(ctx api.Context, name string, options metav1.ExportOptions) (*api.Service, error) {
r.mu.Lock()
defer r.mu.Unlock()
return r.Service, r.Err
}