vendor files

This commit is contained in:
Serguei Bezverkhi
2018-01-09 13:57:14 -05:00
parent 558bc6c02a
commit 7b24313bd6
16547 changed files with 4527373 additions and 0 deletions

View File

@ -0,0 +1,48 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"categoriesProvider.go",
"doc.go",
"endpoint.go",
"etcd.go",
"node.go",
"service.go",
"shortNamesProvider.go",
"validate.go",
],
importpath = "k8s.io/kubernetes/pkg/registry/registrytest",
deps = [
"//pkg/api/testapi:go_default_library",
"//pkg/apis/core:go_default_library",
"//pkg/util/slice:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/internalversion: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/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/etcd/testing:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/storagebackend:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)

24
vendor/k8s.io/kubernetes/pkg/registry/registrytest/OWNERS generated vendored Executable file
View File

@ -0,0 +1,24 @@
reviewers:
- thockin
- lavalamp
- smarterclayton
- wojtek-t
- deads2k
- brendandburns
- derekwaynecarr
- caesarxuchao
- mikedanese
- liggitt
- nikhiljindal
- gmarek
- erictune
- pmorie
- eparis
- timothysc
- dims
- hongchaodeng
- a-robinson
- ddysher
- mqliang
- sdminonne
- enj

View File

@ -0,0 +1,32 @@
/*
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 registrytest
import (
"reflect"
"testing"
"k8s.io/apiserver/pkg/registry/rest"
)
func AssertCategories(t *testing.T, storage rest.CategoriesProvider, expected []string) {
actual := storage.Categories()
ok := reflect.DeepEqual(actual, expected)
if !ok {
t.Errorf("categories are not equal. expected = %v actual = %v", expected, actual)
}
}

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,114 @@
/*
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"
metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
api "k8s.io/kubernetes/pkg/apis/core"
)
// 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 *metainternalversion.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 *metainternalversion.ListOptions) (watch.Interface, error) {
return nil, fmt.Errorf("unimplemented!")
}
func (e *EndpointRegistry) UpdateEndpoints(ctx genericapirequest.Context, endpoints *api.Endpoints, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) 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
}

View File

@ -0,0 +1,31 @@
/*
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 (
"testing"
etcdtesting "k8s.io/apiserver/pkg/storage/etcd/testing"
"k8s.io/apiserver/pkg/storage/storagebackend"
"k8s.io/kubernetes/pkg/api/testapi"
)
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
}

View File

@ -0,0 +1,118 @@
/*
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"
metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
api "k8s.io/kubernetes/pkg/apis/core"
)
// 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 *metainternalversion.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: metav1.ObjectMeta{Name: node.Name}})
}
}
r.Nodes.Items = newList
return r.Err
}
func (r *NodeRegistry) WatchNodes(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (watch.Interface, error) {
return nil, r.Err
}

View File

@ -0,0 +1,125 @@
/*
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"
metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
api "k8s.io/kubernetes/pkg/apis/core"
)
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 *metainternalversion.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 != metav1.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, createValidation rest.ValidateObjectFunc) (*api.Service, error) {
r.mu.Lock()
defer r.mu.Unlock()
r.Service = svc.DeepCopy()
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, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc) (*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 *metainternalversion.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
}

View File

@ -0,0 +1,32 @@
/*
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 (
"reflect"
"testing"
"k8s.io/apiserver/pkg/registry/rest"
)
func AssertShortNames(t *testing.T, storage rest.ShortNamesProvider, expected []string) {
actual := storage.ShortNames()
ok := reflect.DeepEqual(actual, expected)
if !ok {
t.Errorf("short names not equal. expected = %v actual = %v", expected, actual)
}
}

View File

@ -0,0 +1,80 @@
/*
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 registrytest
import (
"fmt"
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/kubernetes/pkg/util/slice"
)
// ValidateStorageStrategies ensures any instances of the generic registry.Store in the given storage map
// have expected strategies defined.
func ValidateStorageStrategies(storageMap map[string]rest.Storage, exceptions StrategyExceptions) []error {
errs := []error{}
// Used to ensure we saw all the expected exceptions:
hasExportExceptionsSeen := []string{}
for k, storage := range storageMap {
switch t := storage.(type) {
case registry.GenericStore:
// At this point it appears all uses of the generic registry store should have a create, update, and
// delete strategy set:
if t.GetCreateStrategy() == nil {
errs = append(errs, fmt.Errorf("store for type [%v] does not have a CreateStrategy", k))
}
if t.GetUpdateStrategy() == nil {
errs = append(errs, fmt.Errorf("store for type [%v] does not have an UpdateStrategy", k))
}
if t.GetDeleteStrategy() == nil {
errs = append(errs, fmt.Errorf("store for type [%v] does not have a DeleteStrategy", k))
}
// Check that ExportStrategy is set if applicable:
if slice.ContainsString(exceptions.HasExportStrategy, k, nil) {
hasExportExceptionsSeen = append(hasExportExceptionsSeen, k)
if t.GetExportStrategy() == nil {
errs = append(errs, fmt.Errorf("store for type [%v] does not have an ExportStrategy", k))
}
} else {
// By default we expect Stores to not have additional export logic:
if t.GetExportStrategy() != nil {
errs = append(errs, fmt.Errorf("store for type [%v] has an unexpected ExportStrategy", k))
}
}
}
}
// Ensure that we saw all our expected exceptions:
for _, expKey := range exceptions.HasExportStrategy {
if !slice.ContainsString(hasExportExceptionsSeen, expKey, nil) {
errs = append(errs, fmt.Errorf("no generic store seen for expected ExportStrategy: %v", expKey))
}
}
return errs
}
// StrategyExceptions carries information on what exceptions to default strategy expectations are expected.
type StrategyExceptions struct {
// HasExportStrategy is a list of the resource keys whose store should have a custom export strategy.
HasExportStrategy []string
}