Switch to github.com/golang/dep for vendoring
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
d6ab91be27
commit
8e5b17cf13
15431 changed files with 3971413 additions and 8881 deletions
51
vendor/k8s.io/kubernetes/pkg/registry/registrytest/BUILD
generated
vendored
Normal file
51
vendor/k8s.io/kubernetes/pkg/registry/registrytest/BUILD
generated
vendored
Normal file
|
@ -0,0 +1,51 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_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/testapi:go_default_library",
|
||||
"//pkg/fields:go_default_library",
|
||||
"//pkg/genericapiserver/api/rest/resttest:go_default_library",
|
||||
"//pkg/registry/generic/registry: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",
|
||||
"//vendor:k8s.io/apimachinery/pkg/api/errors",
|
||||
"//vendor:k8s.io/apimachinery/pkg/api/meta",
|
||||
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1",
|
||||
"//vendor:k8s.io/apimachinery/pkg/labels",
|
||||
"//vendor:k8s.io/apimachinery/pkg/runtime",
|
||||
"//vendor:k8s.io/apimachinery/pkg/watch",
|
||||
"//vendor:k8s.io/apiserver/pkg/request",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
25
vendor/k8s.io/kubernetes/pkg/registry/registrytest/OWNERS
generated
vendored
Executable file
25
vendor/k8s.io/kubernetes/pkg/registry/registrytest/OWNERS
generated
vendored
Executable file
|
@ -0,0 +1,25 @@
|
|||
reviewers:
|
||||
- thockin
|
||||
- lavalamp
|
||||
- smarterclayton
|
||||
- wojtek-t
|
||||
- deads2k
|
||||
- brendandburns
|
||||
- derekwaynecarr
|
||||
- caesarxuchao
|
||||
- mikedanese
|
||||
- liggitt
|
||||
- nikhiljindal
|
||||
- bprashanth
|
||||
- gmarek
|
||||
- erictune
|
||||
- pmorie
|
||||
- eparis
|
||||
- timothysc
|
||||
- dims
|
||||
- hongchaodeng
|
||||
- krousey
|
||||
- a-robinson
|
||||
- ddysher
|
||||
- mqliang
|
||||
- sdminonne
|
19
vendor/k8s.io/kubernetes/pkg/registry/registrytest/doc.go
generated
vendored
Normal file
19
vendor/k8s.io/kubernetes/pkg/registry/registrytest/doc.go
generated
vendored
Normal 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"
|
112
vendor/k8s.io/kubernetes/pkg/registry/registrytest/endpoint.go
generated
vendored
Normal file
112
vendor/k8s.io/kubernetes/pkg/registry/registrytest/endpoint.go
generated
vendored
Normal file
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
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/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
genericapirequest "k8s.io/apiserver/pkg/request"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
)
|
||||
|
||||
// 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 genericapirequest.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 genericapirequest.Context, name string, options *metav1.GetOptions) (*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 genericapirequest.Context, options *api.ListOptions) (watch.Interface, error) {
|
||||
return nil, fmt.Errorf("unimplemented!")
|
||||
}
|
||||
|
||||
func (e *EndpointRegistry) UpdateEndpoints(ctx genericapirequest.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 genericapirequest.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
|
||||
}
|
230
vendor/k8s.io/kubernetes/pkg/registry/registrytest/etcd.go
generated
vendored
Normal file
230
vendor/k8s.io/kubernetes/pkg/registry/registrytest/etcd.go
generated
vendored
Normal file
|
@ -0,0 +1,230 @@
|
|||
/*
|
||||
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/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
genericapirequest "k8s.io/apiserver/pkg/request"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/api/rest/resttest"
|
||||
genericregistry "k8s.io/kubernetes/pkg/registry/generic/registry"
|
||||
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(api.Registry.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 genericapirequest.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(), &metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (t *Tester) createObject(ctx genericapirequest.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
|
||||
}
|
117
vendor/k8s.io/kubernetes/pkg/registry/registrytest/node.go
generated
vendored
Normal file
117
vendor/k8s.io/kubernetes/pkg/registry/registrytest/node.go
generated
vendored
Normal file
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
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/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
genericapirequest "k8s.io/apiserver/pkg/request"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
)
|
||||
|
||||
// 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 genericapirequest.Context, options *api.ListOptions) (*api.NodeList, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
return &r.Nodes, r.Err
|
||||
}
|
||||
|
||||
func (r *NodeRegistry) CreateNode(ctx genericapirequest.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 genericapirequest.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 genericapirequest.Context, nodeID string, options *metav1.GetOptions) (*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 genericapirequest.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 genericapirequest.Context, options *api.ListOptions) (watch.Interface, error) {
|
||||
return nil, r.Err
|
||||
}
|
128
vendor/k8s.io/kubernetes/pkg/registry/registrytest/service.go
generated
vendored
Normal file
128
vendor/k8s.io/kubernetes/pkg/registry/registrytest/service.go
generated
vendored
Normal file
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
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"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
genericapirequest "k8s.io/apiserver/pkg/request"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
)
|
||||
|
||||
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 genericapirequest.Context, options *api.ListOptions) (*api.ServiceList, error) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
ns, _ := genericapirequest.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 genericapirequest.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 genericapirequest.Context, id string, options *metav1.GetOptions) (*api.Service, error) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
r.GottenID = id
|
||||
return r.Service, r.Err
|
||||
}
|
||||
|
||||
func (r *ServiceRegistry) DeleteService(ctx genericapirequest.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 genericapirequest.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 genericapirequest.Context, options *api.ListOptions) (watch.Interface, error) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
return nil, r.Err
|
||||
}
|
||||
|
||||
func (r *ServiceRegistry) ExportService(ctx genericapirequest.Context, name string, options metav1.ExportOptions) (*api.Service, error) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
return r.Service, r.Err
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue