Add glide.yaml and vendor deps
This commit is contained in:
parent
db918f12ad
commit
5b3d5e81bd
18880 changed files with 5166045 additions and 1 deletions
67
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/BUILD
generated
vendored
Normal file
67
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/BUILD
generated
vendored
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
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 = [
|
||||
"codec.go",
|
||||
"doc.go",
|
||||
"registry.go",
|
||||
"strategy.go",
|
||||
"util.go",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/meta:go_default_library",
|
||||
"//pkg/api/rest:go_default_library",
|
||||
"//pkg/api/util:go_default_library",
|
||||
"//pkg/api/v1:go_default_library",
|
||||
"//pkg/apimachinery/registered:go_default_library",
|
||||
"//pkg/apis/extensions:go_default_library",
|
||||
"//pkg/apis/extensions/v1beta1:go_default_library",
|
||||
"//pkg/apis/extensions/validation:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/fields:go_default_library",
|
||||
"//pkg/labels:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
"//pkg/runtime/schema:go_default_library",
|
||||
"//pkg/storage:go_default_library",
|
||||
"//pkg/util/validation/field:go_default_library",
|
||||
"//pkg/util/yaml:go_default_library",
|
||||
"//pkg/watch:go_default_library",
|
||||
"//pkg/watch/versioned:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = [
|
||||
"codec_test.go",
|
||||
"strategy_test.go",
|
||||
"util_test.go",
|
||||
],
|
||||
library = "go_default_library",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/testapi:go_default_library",
|
||||
"//pkg/api/testing:go_default_library",
|
||||
"//pkg/api/v1:go_default_library",
|
||||
"//pkg/apimachinery/registered:go_default_library",
|
||||
"//pkg/apis/extensions:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
"//pkg/runtime/schema:go_default_library",
|
||||
"//pkg/watch/versioned:go_default_library",
|
||||
],
|
||||
)
|
||||
597
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/codec.go
generated
vendored
Normal file
597
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/codec.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
296
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/codec_test.go
generated
vendored
Normal file
296
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/codec_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,296 @@
|
|||
/*
|
||||
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 thirdpartyresourcedata
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/api/v1"
|
||||
"k8s.io/kubernetes/pkg/apimachinery/registered"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/runtime/schema"
|
||||
"k8s.io/kubernetes/pkg/watch/versioned"
|
||||
)
|
||||
|
||||
type Foo struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
api.ObjectMeta `json:"metadata,omitempty" description:"standard object metadata"`
|
||||
|
||||
SomeField string `json:"someField"`
|
||||
OtherField int `json:"otherField"`
|
||||
}
|
||||
|
||||
func (*Foo) GetObjectKind() schema.ObjectKind {
|
||||
return schema.EmptyObjectKind
|
||||
}
|
||||
|
||||
type FooList struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ListMeta `json:"metadata,omitempty" description:"standard list metadata; see http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata"`
|
||||
|
||||
Items []Foo `json:"items"`
|
||||
}
|
||||
|
||||
func TestCodec(t *testing.T) {
|
||||
tests := []struct {
|
||||
into runtime.Object
|
||||
obj *Foo
|
||||
expectErr bool
|
||||
name string
|
||||
}{
|
||||
{
|
||||
into: &runtime.VersionedObjects{},
|
||||
obj: &Foo{
|
||||
ObjectMeta: api.ObjectMeta{Name: "bar"},
|
||||
TypeMeta: metav1.TypeMeta{APIVersion: "company.com/v1", Kind: "Foo"},
|
||||
},
|
||||
expectErr: false,
|
||||
name: "versioned objects list",
|
||||
},
|
||||
{
|
||||
obj: &Foo{ObjectMeta: api.ObjectMeta{Name: "bar"}},
|
||||
expectErr: true,
|
||||
name: "missing kind",
|
||||
},
|
||||
{
|
||||
obj: &Foo{
|
||||
ObjectMeta: api.ObjectMeta{Name: "bar"},
|
||||
TypeMeta: metav1.TypeMeta{APIVersion: "company.com/v1", Kind: "Foo"},
|
||||
},
|
||||
name: "basic",
|
||||
},
|
||||
{
|
||||
into: &extensions.ThirdPartyResourceData{},
|
||||
obj: &Foo{
|
||||
ObjectMeta: api.ObjectMeta{Name: "bar"},
|
||||
TypeMeta: metav1.TypeMeta{Kind: "ThirdPartyResourceData"},
|
||||
},
|
||||
expectErr: true,
|
||||
name: "broken kind",
|
||||
},
|
||||
{
|
||||
obj: &Foo{
|
||||
ObjectMeta: api.ObjectMeta{Name: "bar", ResourceVersion: "baz"},
|
||||
TypeMeta: metav1.TypeMeta{APIVersion: "company.com/v1", Kind: "Foo"},
|
||||
},
|
||||
name: "resource version",
|
||||
},
|
||||
{
|
||||
obj: &Foo{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "bar",
|
||||
CreationTimestamp: metav1.Time{Time: time.Unix(100, 0)},
|
||||
},
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
APIVersion: "company.com/v1",
|
||||
Kind: "Foo",
|
||||
},
|
||||
},
|
||||
name: "creation time",
|
||||
},
|
||||
{
|
||||
obj: &Foo{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "bar",
|
||||
ResourceVersion: "baz",
|
||||
Labels: map[string]string{"foo": "bar", "baz": "blah"},
|
||||
},
|
||||
TypeMeta: metav1.TypeMeta{APIVersion: "company.com/v1", Kind: "Foo"},
|
||||
},
|
||||
name: "labels",
|
||||
},
|
||||
}
|
||||
registered.AddThirdPartyAPIGroupVersions(schema.GroupVersion{Group: "company.com", Version: "v1"})
|
||||
for _, test := range tests {
|
||||
d := &thirdPartyResourceDataDecoder{kind: "Foo", delegate: testapi.Extensions.Codec()}
|
||||
e := &thirdPartyResourceDataEncoder{gvk: schema.GroupVersionKind{
|
||||
Group: "company.com",
|
||||
Version: "v1",
|
||||
Kind: "Foo",
|
||||
}, delegate: testapi.Extensions.Codec()}
|
||||
data, err := json.Marshal(test.obj)
|
||||
if err != nil {
|
||||
t.Errorf("[%s] unexpected error: %v", test.name, err)
|
||||
continue
|
||||
}
|
||||
var obj runtime.Object
|
||||
if test.into != nil {
|
||||
err = runtime.DecodeInto(d, data, test.into)
|
||||
obj = test.into
|
||||
} else {
|
||||
obj, err = runtime.Decode(d, data)
|
||||
}
|
||||
if err != nil && !test.expectErr {
|
||||
t.Errorf("[%s] unexpected error: %v", test.name, err)
|
||||
continue
|
||||
}
|
||||
if test.expectErr {
|
||||
if err == nil {
|
||||
t.Errorf("[%s] unexpected non-error", test.name)
|
||||
}
|
||||
continue
|
||||
}
|
||||
var rsrcObj *extensions.ThirdPartyResourceData
|
||||
switch o := obj.(type) {
|
||||
case *extensions.ThirdPartyResourceData:
|
||||
rsrcObj = o
|
||||
case *runtime.VersionedObjects:
|
||||
rsrcObj = o.First().(*extensions.ThirdPartyResourceData)
|
||||
default:
|
||||
t.Errorf("[%s] unexpected object: %v", test.name, obj)
|
||||
continue
|
||||
}
|
||||
if !reflect.DeepEqual(rsrcObj.ObjectMeta, test.obj.ObjectMeta) {
|
||||
t.Errorf("[%s]\nexpected\n%v\nsaw\n%v\n", test.name, rsrcObj.ObjectMeta, test.obj.ObjectMeta)
|
||||
}
|
||||
var output Foo
|
||||
if err := json.Unmarshal(rsrcObj.Data, &output); err != nil {
|
||||
t.Errorf("[%s] unexpected error: %v", test.name, err)
|
||||
continue
|
||||
}
|
||||
if !reflect.DeepEqual(&output, test.obj) {
|
||||
t.Errorf("[%s]\nexpected\n%v\nsaw\n%v\n", test.name, test.obj, &output)
|
||||
}
|
||||
|
||||
data, err = runtime.Encode(e, rsrcObj)
|
||||
if err != nil {
|
||||
t.Errorf("[%s] unexpected error: %v", test.name, err)
|
||||
}
|
||||
|
||||
var output2 Foo
|
||||
if err := json.Unmarshal(data, &output2); err != nil {
|
||||
t.Errorf("[%s] unexpected error: %v", test.name, err)
|
||||
continue
|
||||
}
|
||||
if !reflect.DeepEqual(&output2, test.obj) {
|
||||
t.Errorf("[%s]\nexpected\n%v\nsaw\n%v\n", test.name, test.obj, &output2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreater(t *testing.T) {
|
||||
creater := NewObjectCreator("creater group", "creater version", api.Scheme)
|
||||
tests := []struct {
|
||||
name string
|
||||
kind schema.GroupVersionKind
|
||||
expectedObj runtime.Object
|
||||
expectErr bool
|
||||
}{
|
||||
{
|
||||
name: "valid ThirdPartyResourceData creation",
|
||||
kind: schema.GroupVersionKind{Group: "creater group", Version: "creater version", Kind: "ThirdPartyResourceData"},
|
||||
expectedObj: &extensions.ThirdPartyResourceData{},
|
||||
expectErr: false,
|
||||
},
|
||||
{
|
||||
name: "invalid ThirdPartyResourceData creation",
|
||||
kind: schema.GroupVersionKind{Version: "invalid version", Kind: "ThirdPartyResourceData"},
|
||||
expectedObj: nil,
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "valid ListOptions creation",
|
||||
kind: schema.GroupVersionKind{Version: "v1", Kind: "ListOptions"},
|
||||
expectedObj: &v1.ListOptions{},
|
||||
expectErr: false,
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
out, err := creater.New(test.kind)
|
||||
if err != nil && !test.expectErr {
|
||||
t.Errorf("[%s] unexpected error: %v", test.name, err)
|
||||
}
|
||||
if err == nil && test.expectErr {
|
||||
t.Errorf("[%s] unexpected non-error", test.name)
|
||||
}
|
||||
if !reflect.DeepEqual(test.expectedObj, out) {
|
||||
t.Errorf("[%s] unexpected error: expect: %v, got: %v", test.name, test.expectedObj, out)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodeToStreamForInternalEvent(t *testing.T) {
|
||||
e := &thirdPartyResourceDataEncoder{gvk: schema.GroupVersionKind{
|
||||
Group: "company.com",
|
||||
Version: "v1",
|
||||
Kind: "Foo",
|
||||
}, delegate: testapi.Extensions.Codec()}
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
expected := &versioned.Event{
|
||||
Type: "Added",
|
||||
}
|
||||
err := e.Encode(&versioned.InternalEvent{
|
||||
Type: "Added",
|
||||
}, buf)
|
||||
|
||||
jBytes, _ := json.Marshal(expected)
|
||||
|
||||
if string(jBytes) == buf.String() {
|
||||
t.Errorf("unexpected encoding expected %s got %s", string(jBytes), buf.String())
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error encoding: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestThirdPartyResourceDataListEncoding(t *testing.T) {
|
||||
gv := schema.GroupVersion{Group: "stable.foo.faz", Version: "v1"}
|
||||
gvk := gv.WithKind("Bar")
|
||||
e := &thirdPartyResourceDataEncoder{delegate: testapi.Extensions.Codec(), gvk: gvk}
|
||||
subject := &extensions.ThirdPartyResourceDataList{}
|
||||
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
err := e.Encode(subject, buf)
|
||||
if err != nil {
|
||||
t.Errorf("encoding unexpected error: %v", err)
|
||||
}
|
||||
|
||||
targetOutput := struct {
|
||||
Kind string `json:"kind,omitempty"`
|
||||
Items []json.RawMessage `json:"items"`
|
||||
Metadata metav1.ListMeta `json:"metadata,omitempty"`
|
||||
APIVersion string `json:"apiVersion,omitempty"`
|
||||
}{}
|
||||
err = json.Unmarshal(buf.Bytes(), &targetOutput)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("unmarshal unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if expectedKind := gvk.Kind + "List"; expectedKind != targetOutput.Kind {
|
||||
t.Errorf("unexpected kind on list got %s expected %s", targetOutput.Kind, expectedKind)
|
||||
}
|
||||
|
||||
if targetOutput.Metadata != subject.ListMeta {
|
||||
t.Errorf("metadata mismatch %v != %v", targetOutput.Metadata, subject.ListMeta)
|
||||
}
|
||||
|
||||
if targetOutput.APIVersion != gv.String() {
|
||||
t.Errorf("apiversion mismatch %v != %v", targetOutput.APIVersion, gv.String())
|
||||
}
|
||||
|
||||
}
|
||||
19
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/doc.go
generated
vendored
Normal file
19
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/doc.go
generated
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
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 thirdpartyresourcedata provides Registry interface and its REST
|
||||
// implementation for storing ThirdPartyResourceData api objects.
|
||||
package thirdpartyresourcedata // import "k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata"
|
||||
43
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/etcd/BUILD
generated
vendored
Normal file
43
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/etcd/BUILD
generated
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
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 = ["etcd.go"],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/apis/extensions:go_default_library",
|
||||
"//pkg/registry/extensions/thirdpartyresourcedata:go_default_library",
|
||||
"//pkg/registry/generic:go_default_library",
|
||||
"//pkg/registry/generic/registry:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["etcd_test.go"],
|
||||
library = "go_default_library",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/apis/extensions:go_default_library",
|
||||
"//pkg/apis/extensions/v1beta1:go_default_library",
|
||||
"//pkg/fields:go_default_library",
|
||||
"//pkg/labels:go_default_library",
|
||||
"//pkg/registry/generic:go_default_library",
|
||||
"//pkg/registry/registrytest:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
"//pkg/storage/etcd/testing:go_default_library",
|
||||
],
|
||||
)
|
||||
76
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/etcd/etcd.go
generated
vendored
Normal file
76
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/etcd/etcd.go
generated
vendored
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
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 etcd
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
"k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata"
|
||||
"k8s.io/kubernetes/pkg/registry/generic"
|
||||
genericregistry "k8s.io/kubernetes/pkg/registry/generic/registry"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
||||
// REST implements a RESTStorage for ThirdPartyResourceDatas against etcd
|
||||
type REST struct {
|
||||
*genericregistry.Store
|
||||
kind string
|
||||
}
|
||||
|
||||
// NewREST returns a registry which will store ThirdPartyResourceData in the given helper
|
||||
func NewREST(opts generic.RESTOptions, group, kind string) *REST {
|
||||
prefix := "/ThirdPartyResourceData/" + group + "/" + strings.ToLower(kind) + "s"
|
||||
|
||||
// We explicitly do NOT do any decoration here yet.
|
||||
storageInterface, dFunc := generic.NewRawStorage(opts.StorageConfig)
|
||||
|
||||
store := &genericregistry.Store{
|
||||
NewFunc: func() runtime.Object { return &extensions.ThirdPartyResourceData{} },
|
||||
NewListFunc: func() runtime.Object { return &extensions.ThirdPartyResourceDataList{} },
|
||||
KeyRootFunc: func(ctx api.Context) string {
|
||||
return genericregistry.NamespaceKeyRootFunc(ctx, prefix)
|
||||
},
|
||||
KeyFunc: func(ctx api.Context, id string) (string, error) {
|
||||
return genericregistry.NamespaceKeyFunc(ctx, prefix, id)
|
||||
},
|
||||
ObjectNameFunc: func(obj runtime.Object) (string, error) {
|
||||
return obj.(*extensions.ThirdPartyResourceData).Name, nil
|
||||
},
|
||||
PredicateFunc: thirdpartyresourcedata.Matcher,
|
||||
QualifiedResource: extensions.Resource("thirdpartyresourcedatas"),
|
||||
EnableGarbageCollection: opts.EnableGarbageCollection,
|
||||
DeleteCollectionWorkers: opts.DeleteCollectionWorkers,
|
||||
CreateStrategy: thirdpartyresourcedata.Strategy,
|
||||
UpdateStrategy: thirdpartyresourcedata.Strategy,
|
||||
DeleteStrategy: thirdpartyresourcedata.Strategy,
|
||||
|
||||
Storage: storageInterface,
|
||||
DestroyFunc: dFunc,
|
||||
}
|
||||
|
||||
return &REST{
|
||||
Store: store,
|
||||
kind: kind,
|
||||
}
|
||||
}
|
||||
|
||||
// Implements the rest.KindProvider interface
|
||||
func (r *REST) Kind() string {
|
||||
return r.kind
|
||||
}
|
||||
127
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/etcd/etcd_test.go
generated
vendored
Normal file
127
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/etcd/etcd_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
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 etcd
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
// Ensure that extensions/v1beta1 package is initialized.
|
||||
_ "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
"k8s.io/kubernetes/pkg/registry/generic"
|
||||
"k8s.io/kubernetes/pkg/registry/registrytest"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
etcdtesting "k8s.io/kubernetes/pkg/storage/etcd/testing"
|
||||
)
|
||||
|
||||
func newStorage(t *testing.T) (*REST, *etcdtesting.EtcdTestServer) {
|
||||
etcdStorage, server := registrytest.NewEtcdStorage(t, extensions.GroupName)
|
||||
restOptions := generic.RESTOptions{StorageConfig: etcdStorage, Decorator: generic.UndecoratedStorage, DeleteCollectionWorkers: 1}
|
||||
return NewREST(restOptions, "foo", "bar"), server
|
||||
}
|
||||
|
||||
func validNewThirdPartyResourceData(name string) *extensions.ThirdPartyResourceData {
|
||||
return &extensions.ThirdPartyResourceData{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
Data: []byte("foobarbaz"),
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
storage, server := newStorage(t)
|
||||
defer server.Terminate(t)
|
||||
defer storage.Store.DestroyFunc()
|
||||
test := registrytest.New(t, storage.Store)
|
||||
rsrc := validNewThirdPartyResourceData("foo")
|
||||
rsrc.ObjectMeta = api.ObjectMeta{}
|
||||
test.TestCreate(
|
||||
// valid
|
||||
rsrc,
|
||||
// invalid
|
||||
&extensions.ThirdPartyResourceData{},
|
||||
)
|
||||
}
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
storage, server := newStorage(t)
|
||||
defer server.Terminate(t)
|
||||
defer storage.Store.DestroyFunc()
|
||||
test := registrytest.New(t, storage.Store)
|
||||
test.TestUpdate(
|
||||
// valid
|
||||
validNewThirdPartyResourceData("foo"),
|
||||
// updateFunc
|
||||
func(obj runtime.Object) runtime.Object {
|
||||
object := obj.(*extensions.ThirdPartyResourceData)
|
||||
object.Data = []byte("new description")
|
||||
return object
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
storage, server := newStorage(t)
|
||||
defer server.Terminate(t)
|
||||
defer storage.Store.DestroyFunc()
|
||||
test := registrytest.New(t, storage.Store)
|
||||
test.TestDelete(validNewThirdPartyResourceData("foo"))
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
storage, server := newStorage(t)
|
||||
defer server.Terminate(t)
|
||||
defer storage.Store.DestroyFunc()
|
||||
test := registrytest.New(t, storage.Store)
|
||||
test.TestGet(validNewThirdPartyResourceData("foo"))
|
||||
}
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
storage, server := newStorage(t)
|
||||
defer server.Terminate(t)
|
||||
defer storage.Store.DestroyFunc()
|
||||
test := registrytest.New(t, storage.Store)
|
||||
test.TestList(validNewThirdPartyResourceData("foo"))
|
||||
}
|
||||
|
||||
func TestWatch(t *testing.T) {
|
||||
storage, server := newStorage(t)
|
||||
defer server.Terminate(t)
|
||||
defer storage.Store.DestroyFunc()
|
||||
test := registrytest.New(t, storage.Store)
|
||||
test.TestWatch(
|
||||
validNewThirdPartyResourceData("foo"),
|
||||
// matching labels
|
||||
[]labels.Set{},
|
||||
// not matching labels
|
||||
[]labels.Set{
|
||||
{"foo": "bar"},
|
||||
},
|
||||
// matching fields
|
||||
[]fields.Set{},
|
||||
// not matching fields
|
||||
[]fields.Set{
|
||||
{"metadata.name": "bar"},
|
||||
{"name": "foo"},
|
||||
},
|
||||
)
|
||||
}
|
||||
80
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/registry.go
generated
vendored
Normal file
80
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/registry.go
generated
vendored
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
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 thirdpartyresourcedata
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
"k8s.io/kubernetes/pkg/watch"
|
||||
)
|
||||
|
||||
// Registry is an interface implemented by things that know how to store ThirdPartyResourceData objects.
|
||||
type Registry interface {
|
||||
ListThirdPartyResourceData(ctx api.Context, options *api.ListOptions) (*extensions.ThirdPartyResourceDataList, error)
|
||||
WatchThirdPartyResourceData(ctx api.Context, options *api.ListOptions) (watch.Interface, error)
|
||||
GetThirdPartyResourceData(ctx api.Context, name string) (*extensions.ThirdPartyResourceData, error)
|
||||
CreateThirdPartyResourceData(ctx api.Context, resource *extensions.ThirdPartyResourceData) (*extensions.ThirdPartyResourceData, error)
|
||||
UpdateThirdPartyResourceData(ctx api.Context, resource *extensions.ThirdPartyResourceData) (*extensions.ThirdPartyResourceData, error)
|
||||
DeleteThirdPartyResourceData(ctx api.Context, name string) error
|
||||
}
|
||||
|
||||
// storage puts strong typing around storage calls
|
||||
type storage struct {
|
||||
rest.StandardStorage
|
||||
}
|
||||
|
||||
// NewRegistry returns a new Registry interface for the given Storage. Any mismatched
|
||||
// types will panic.
|
||||
func NewRegistry(s rest.StandardStorage) Registry {
|
||||
return &storage{s}
|
||||
}
|
||||
|
||||
func (s *storage) ListThirdPartyResourceData(ctx api.Context, options *api.ListOptions) (*extensions.ThirdPartyResourceDataList, error) {
|
||||
obj, err := s.List(ctx, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*extensions.ThirdPartyResourceDataList), nil
|
||||
}
|
||||
|
||||
func (s *storage) WatchThirdPartyResourceData(ctx api.Context, options *api.ListOptions) (watch.Interface, error) {
|
||||
return s.Watch(ctx, options)
|
||||
}
|
||||
|
||||
func (s *storage) GetThirdPartyResourceData(ctx api.Context, name string) (*extensions.ThirdPartyResourceData, error) {
|
||||
obj, err := s.Get(ctx, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*extensions.ThirdPartyResourceData), nil
|
||||
}
|
||||
|
||||
func (s *storage) CreateThirdPartyResourceData(ctx api.Context, ThirdPartyResourceData *extensions.ThirdPartyResourceData) (*extensions.ThirdPartyResourceData, error) {
|
||||
obj, err := s.Create(ctx, ThirdPartyResourceData)
|
||||
return obj.(*extensions.ThirdPartyResourceData), err
|
||||
}
|
||||
|
||||
func (s *storage) UpdateThirdPartyResourceData(ctx api.Context, ThirdPartyResourceData *extensions.ThirdPartyResourceData) (*extensions.ThirdPartyResourceData, error) {
|
||||
obj, _, err := s.Update(ctx, ThirdPartyResourceData.Name, rest.DefaultUpdatedObjectInfo(ThirdPartyResourceData, api.Scheme))
|
||||
return obj.(*extensions.ThirdPartyResourceData), err
|
||||
}
|
||||
|
||||
func (s *storage) DeleteThirdPartyResourceData(ctx api.Context, name string) error {
|
||||
_, err := s.Delete(ctx, name, nil)
|
||||
return err
|
||||
}
|
||||
98
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/strategy.go
generated
vendored
Normal file
98
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/strategy.go
generated
vendored
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
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 thirdpartyresourcedata
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions/validation"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
apistorage "k8s.io/kubernetes/pkg/storage"
|
||||
"k8s.io/kubernetes/pkg/util/validation/field"
|
||||
)
|
||||
|
||||
// strategy implements behavior for ThirdPartyResource objects
|
||||
type strategy struct {
|
||||
runtime.ObjectTyper
|
||||
api.NameGenerator
|
||||
}
|
||||
|
||||
// Strategy is the default logic that applies when creating and updating ThirdPartyResource
|
||||
// objects via the REST API.
|
||||
var Strategy = strategy{api.Scheme, api.SimpleNameGenerator}
|
||||
|
||||
var _ = rest.RESTCreateStrategy(Strategy)
|
||||
|
||||
var _ = rest.RESTUpdateStrategy(Strategy)
|
||||
|
||||
func (strategy) NamespaceScoped() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (strategy) PrepareForCreate(ctx api.Context, obj runtime.Object) {
|
||||
}
|
||||
|
||||
func (strategy) Validate(ctx api.Context, obj runtime.Object) field.ErrorList {
|
||||
return validation.ValidateThirdPartyResourceData(obj.(*extensions.ThirdPartyResourceData))
|
||||
}
|
||||
|
||||
// Canonicalize normalizes the object after validation.
|
||||
func (strategy) Canonicalize(obj runtime.Object) {
|
||||
}
|
||||
|
||||
func (strategy) AllowCreateOnUpdate() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (strategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
}
|
||||
|
||||
func (strategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
|
||||
return validation.ValidateThirdPartyResourceDataUpdate(obj.(*extensions.ThirdPartyResourceData), old.(*extensions.ThirdPartyResourceData))
|
||||
}
|
||||
|
||||
func (strategy) AllowUnconditionalUpdate() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// GetAttrs returns labels and fields of a given object for filtering purposes.
|
||||
func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) {
|
||||
tprd, ok := obj.(*extensions.ThirdPartyResourceData)
|
||||
if !ok {
|
||||
return nil, nil, fmt.Errorf("not a ThirdPartyResourceData")
|
||||
}
|
||||
return labels.Set(tprd.Labels), SelectableFields(tprd), nil
|
||||
}
|
||||
|
||||
// Matcher returns a generic matcher for a given label and field selector.
|
||||
func Matcher(label labels.Selector, field fields.Selector) apistorage.SelectionPredicate {
|
||||
return apistorage.SelectionPredicate{
|
||||
Label: label,
|
||||
Field: field,
|
||||
GetAttrs: GetAttrs,
|
||||
}
|
||||
}
|
||||
|
||||
// SelectableFields returns a field set that can be used for filter selection
|
||||
func SelectableFields(obj *extensions.ThirdPartyResourceData) fields.Set {
|
||||
return nil
|
||||
}
|
||||
35
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/strategy_test.go
generated
vendored
Normal file
35
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/strategy_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
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 thirdpartyresourcedata
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
_ "k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
apitesting "k8s.io/kubernetes/pkg/api/testing"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
)
|
||||
|
||||
func TestSelectableFieldLabelConversions(t *testing.T) {
|
||||
apitesting.TestSelectableFieldLabelConversionsOfKind(t,
|
||||
testapi.Extensions.GroupVersion().String(),
|
||||
"ThirdPartyResourceData",
|
||||
SelectableFields(&extensions.ThirdPartyResourceData{}),
|
||||
nil,
|
||||
)
|
||||
}
|
||||
68
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/util.go
generated
vendored
Normal file
68
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/util.go
generated
vendored
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
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 thirdpartyresourcedata
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
"k8s.io/kubernetes/pkg/runtime/schema"
|
||||
)
|
||||
|
||||
func ExtractGroupVersionKind(list *extensions.ThirdPartyResourceList) ([]schema.GroupVersion, []schema.GroupVersionKind, error) {
|
||||
gvs := []schema.GroupVersion{}
|
||||
gvks := []schema.GroupVersionKind{}
|
||||
for ix := range list.Items {
|
||||
rsrc := &list.Items[ix]
|
||||
kind, group, err := ExtractApiGroupAndKind(rsrc)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
for _, version := range rsrc.Versions {
|
||||
gv := schema.GroupVersion{Group: group, Version: version.Name}
|
||||
gvs = append(gvs, gv)
|
||||
gvks = append(gvks, schema.GroupVersionKind{Group: group, Version: version.Name, Kind: kind})
|
||||
}
|
||||
}
|
||||
return gvs, gvks, nil
|
||||
}
|
||||
|
||||
func convertToCamelCase(input string) string {
|
||||
result := ""
|
||||
toUpper := true
|
||||
for ix := range input {
|
||||
char := input[ix]
|
||||
if toUpper {
|
||||
result = result + string([]byte{(char - 32)})
|
||||
toUpper = false
|
||||
} else if char == '-' {
|
||||
toUpper = true
|
||||
} else {
|
||||
result = result + string([]byte{char})
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func ExtractApiGroupAndKind(rsrc *extensions.ThirdPartyResource) (kind string, group string, err error) {
|
||||
parts := strings.Split(rsrc.Name, ".")
|
||||
if len(parts) < 3 {
|
||||
return "", "", fmt.Errorf("unexpectedly short resource name: %s, expected at least <kind>.<domain>.<tld>", rsrc.Name)
|
||||
}
|
||||
return convertToCamelCase(parts[0]), strings.Join(parts[1:], "."), nil
|
||||
}
|
||||
66
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/util_test.go
generated
vendored
Normal file
66
vendor/k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata/util_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
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 thirdpartyresourcedata
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
)
|
||||
|
||||
func TestExtractAPIGroupAndKind(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
expectedKind string
|
||||
expectedGroup string
|
||||
expectErr bool
|
||||
}{
|
||||
{
|
||||
input: "foo.company.com",
|
||||
expectedKind: "Foo",
|
||||
expectedGroup: "company.com",
|
||||
},
|
||||
{
|
||||
input: "cron-tab.company.com",
|
||||
expectedKind: "CronTab",
|
||||
expectedGroup: "company.com",
|
||||
},
|
||||
{
|
||||
input: "foo",
|
||||
expectErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
kind, group, err := ExtractApiGroupAndKind(&extensions.ThirdPartyResource{ObjectMeta: api.ObjectMeta{Name: test.input}})
|
||||
if err != nil && !test.expectErr {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
continue
|
||||
}
|
||||
if err == nil && test.expectErr {
|
||||
t.Errorf("unexpected non-error")
|
||||
continue
|
||||
}
|
||||
if kind != test.expectedKind {
|
||||
t.Errorf("expected: %s, saw: %s", test.expectedKind, kind)
|
||||
}
|
||||
if group != test.expectedGroup {
|
||||
t.Errorf("expected: %s, saw: %s", test.expectedGroup, group)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue