mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Remove unused registry infrastructure
This commit is contained in:
parent
5de0f11b1d
commit
2ced08358f
@ -174,30 +174,6 @@ func (e *Etcd) ListPredicate(ctx api.Context, m generic.Matcher) (runtime.Object
|
|||||||
return generic.FilterList(list, m, generic.DecoratorFunc(e.Decorator))
|
return generic.FilterList(list, m, generic.DecoratorFunc(e.Decorator))
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateWithName inserts a new item with the provided name
|
|
||||||
// DEPRECATED: use Create instead
|
|
||||||
func (e *Etcd) CreateWithName(ctx api.Context, name string, obj runtime.Object) error {
|
|
||||||
key, err := e.KeyFunc(ctx, name)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if e.CreateStrategy != nil {
|
|
||||||
if err := rest.BeforeCreate(e.CreateStrategy, ctx, obj); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ttl, err := e.calculateTTL(obj, 0, false)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = e.Storage.Create(key, obj, nil, ttl)
|
|
||||||
err = etcderr.InterpretCreateError(err, e.EndpointName, name)
|
|
||||||
if err == nil && e.Decorator != nil {
|
|
||||||
err = e.Decorator(obj)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create inserts a new item according to the unique key from the object.
|
// Create inserts a new item according to the unique key from the object.
|
||||||
func (e *Etcd) Create(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
func (e *Etcd) Create(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
||||||
trace := util.NewTrace("Create " + reflect.TypeOf(obj).String())
|
trace := util.NewTrace("Create " + reflect.TypeOf(obj).String())
|
||||||
@ -238,25 +214,6 @@ func (e *Etcd) Create(ctx api.Context, obj runtime.Object) (runtime.Object, erro
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateWithName updates the item with the provided name
|
|
||||||
// DEPRECATED: use Update instead
|
|
||||||
func (e *Etcd) UpdateWithName(ctx api.Context, name string, obj runtime.Object) error {
|
|
||||||
key, err := e.KeyFunc(ctx, name)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
ttl, err := e.calculateTTL(obj, 0, true)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = e.Storage.Set(key, obj, nil, ttl)
|
|
||||||
err = etcderr.InterpretUpdateError(err, e.EndpointName, name)
|
|
||||||
if err == nil && e.Decorator != nil {
|
|
||||||
err = e.Decorator(obj)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update performs an atomic update and set of the object. Returns the result of the update
|
// Update performs an atomic update and set of the object. Returns the result of the update
|
||||||
// or an error. If the registry allows create-on-update, the create flow will be executed.
|
// or an error. If the registry allows create-on-update, the create flow will be executed.
|
||||||
// A bool is returned along with the object and any errors, to indicate object creation.
|
// A bool is returned along with the object and any errors, to indicate object creation.
|
||||||
|
@ -307,83 +307,6 @@ func TestEtcdCreate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DEPRECATED
|
|
||||||
func TestEtcdCreateWithName(t *testing.T) {
|
|
||||||
podA := &api.Pod{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: api.NamespaceDefault},
|
|
||||||
Spec: api.PodSpec{NodeName: "machine"},
|
|
||||||
}
|
|
||||||
podB := &api.Pod{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: api.NamespaceDefault},
|
|
||||||
Spec: api.PodSpec{NodeName: "machine2"},
|
|
||||||
}
|
|
||||||
|
|
||||||
nodeWithPodA := tools.EtcdResponseWithError{
|
|
||||||
R: &etcd.Response{
|
|
||||||
Node: &etcd.Node{
|
|
||||||
Value: runtime.EncodeOrDie(testapi.Codec(), podA),
|
|
||||||
ModifiedIndex: 1,
|
|
||||||
CreatedIndex: 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
E: nil,
|
|
||||||
}
|
|
||||||
|
|
||||||
emptyNode := tools.EtcdResponseWithError{
|
|
||||||
R: &etcd.Response{},
|
|
||||||
E: tools.EtcdErrorNotFound,
|
|
||||||
}
|
|
||||||
|
|
||||||
key := "foo"
|
|
||||||
|
|
||||||
table := map[string]struct {
|
|
||||||
existing tools.EtcdResponseWithError
|
|
||||||
expect tools.EtcdResponseWithError
|
|
||||||
toCreate runtime.Object
|
|
||||||
objOK func(obj runtime.Object) bool
|
|
||||||
errOK func(error) bool
|
|
||||||
}{
|
|
||||||
"normal": {
|
|
||||||
existing: emptyNode,
|
|
||||||
toCreate: podA,
|
|
||||||
objOK: hasCreated(t, podA),
|
|
||||||
errOK: func(err error) bool { return err == nil },
|
|
||||||
},
|
|
||||||
"preExisting": {
|
|
||||||
existing: nodeWithPodA,
|
|
||||||
expect: nodeWithPodA,
|
|
||||||
toCreate: podB,
|
|
||||||
errOK: errors.IsAlreadyExists,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for name, item := range table {
|
|
||||||
fakeClient, registry := NewTestGenericEtcdRegistry(t)
|
|
||||||
path := etcdtest.AddPrefix("pods/foo")
|
|
||||||
fakeClient.Data[path] = item.existing
|
|
||||||
err := registry.CreateWithName(api.NewDefaultContext(), key, item.toCreate)
|
|
||||||
if !item.errOK(err) {
|
|
||||||
t.Errorf("%v: unexpected error: %v", name, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
actual := fakeClient.Data[path]
|
|
||||||
if item.objOK != nil {
|
|
||||||
obj, err := api.Scheme.Decode([]byte(actual.R.Node.Value))
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("unable to decode stored value for %#v", actual)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if !item.objOK(obj) {
|
|
||||||
t.Errorf("%v: unexpected response: %v", name, actual)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if e, a := item.expect, actual; !api.Semantic.DeepDerivative(e, a) {
|
|
||||||
t.Errorf("%v:\n%s", name, util.ObjectDiff(e, a))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEtcdUpdate(t *testing.T) {
|
func TestEtcdUpdate(t *testing.T) {
|
||||||
podA := &api.Pod{
|
podA := &api.Pod{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: api.NamespaceDefault},
|
ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: api.NamespaceDefault},
|
||||||
@ -520,82 +443,6 @@ func TestEtcdUpdate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DEPRECATED
|
|
||||||
func TestEtcdUpdateWithName(t *testing.T) {
|
|
||||||
podA := &api.Pod{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
|
||||||
Spec: api.PodSpec{NodeName: "machine"},
|
|
||||||
}
|
|
||||||
podB := &api.Pod{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"},
|
|
||||||
Spec: api.PodSpec{NodeName: "machine2"},
|
|
||||||
}
|
|
||||||
|
|
||||||
nodeWithPodA := tools.EtcdResponseWithError{
|
|
||||||
R: &etcd.Response{
|
|
||||||
Node: &etcd.Node{
|
|
||||||
Value: runtime.EncodeOrDie(testapi.Codec(), podA),
|
|
||||||
ModifiedIndex: 1,
|
|
||||||
CreatedIndex: 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
E: nil,
|
|
||||||
}
|
|
||||||
|
|
||||||
nodeWithPodB := tools.EtcdResponseWithError{
|
|
||||||
R: &etcd.Response{
|
|
||||||
Node: &etcd.Node{
|
|
||||||
Value: runtime.EncodeOrDie(testapi.Codec(), podB),
|
|
||||||
ModifiedIndex: 1,
|
|
||||||
CreatedIndex: 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
E: nil,
|
|
||||||
}
|
|
||||||
|
|
||||||
emptyNode := tools.EtcdResponseWithError{
|
|
||||||
R: &etcd.Response{},
|
|
||||||
E: tools.EtcdErrorNotFound,
|
|
||||||
}
|
|
||||||
|
|
||||||
key := "foo"
|
|
||||||
|
|
||||||
table := map[string]struct {
|
|
||||||
existing tools.EtcdResponseWithError
|
|
||||||
expect tools.EtcdResponseWithError
|
|
||||||
toUpdate runtime.Object
|
|
||||||
errOK func(error) bool
|
|
||||||
}{
|
|
||||||
"normal": {
|
|
||||||
existing: nodeWithPodA,
|
|
||||||
expect: nodeWithPodB,
|
|
||||||
toUpdate: podB,
|
|
||||||
errOK: func(err error) bool { return err == nil },
|
|
||||||
},
|
|
||||||
"notExisting": {
|
|
||||||
existing: emptyNode,
|
|
||||||
expect: nodeWithPodA,
|
|
||||||
toUpdate: podA,
|
|
||||||
// TODO: Should updating a non-existing thing fail?
|
|
||||||
errOK: func(err error) bool { return err == nil },
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for name, item := range table {
|
|
||||||
fakeClient, registry := NewTestGenericEtcdRegistry(t)
|
|
||||||
path := etcdtest.AddPrefix("pods/foo")
|
|
||||||
fakeClient.Data[path] = item.existing
|
|
||||||
err := registry.UpdateWithName(api.NewContext(), key, item.toUpdate)
|
|
||||||
if !item.errOK(err) {
|
|
||||||
t.Errorf("%v: unexpected error: %v", name, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if e, a := item.expect, fakeClient.Data[path]; !api.Semantic.DeepDerivative(e, a) {
|
|
||||||
t.Errorf("%v:\n%s", name, util.ObjectDiff(e, a))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEtcdGet(t *testing.T) {
|
func TestEtcdGet(t *testing.T) {
|
||||||
podA := &api.Pod{
|
podA := &api.Pod{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"},
|
ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"},
|
||||||
|
@ -17,11 +17,9 @@ limitations under the License.
|
|||||||
package generic
|
package generic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"k8s.io/kubernetes/pkg/api"
|
|
||||||
"k8s.io/kubernetes/pkg/fields"
|
"k8s.io/kubernetes/pkg/fields"
|
||||||
"k8s.io/kubernetes/pkg/labels"
|
"k8s.io/kubernetes/pkg/labels"
|
||||||
"k8s.io/kubernetes/pkg/runtime"
|
"k8s.io/kubernetes/pkg/runtime"
|
||||||
"k8s.io/kubernetes/pkg/watch"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// AttrFunc returns label and field sets for List or Watch to compare against, or an error.
|
// AttrFunc returns label and field sets for List or Watch to compare against, or an error.
|
||||||
@ -124,19 +122,6 @@ var (
|
|||||||
// DecoratorFunc can mutate the provided object prior to being returned.
|
// DecoratorFunc can mutate the provided object prior to being returned.
|
||||||
type DecoratorFunc func(obj runtime.Object) error
|
type DecoratorFunc func(obj runtime.Object) error
|
||||||
|
|
||||||
// Registry knows how to store & list any runtime.Object. Can be used for
|
|
||||||
// any object types which don't require special features from the storage
|
|
||||||
// layer.
|
|
||||||
// DEPRECATED: replace with direct implementation of RESTStorage
|
|
||||||
type Registry interface {
|
|
||||||
ListPredicate(api.Context, Matcher) (runtime.Object, error)
|
|
||||||
CreateWithName(ctx api.Context, id string, obj runtime.Object) error
|
|
||||||
UpdateWithName(ctx api.Context, id string, obj runtime.Object) error
|
|
||||||
Get(ctx api.Context, id string) (runtime.Object, error)
|
|
||||||
Delete(ctx api.Context, id string, options *api.DeleteOptions) (runtime.Object, error)
|
|
||||||
WatchPredicate(ctx api.Context, m Matcher, resourceVersion string) (watch.Interface, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FilterList filters any list object that conforms to the api conventions,
|
// FilterList filters any list object that conforms to the api conventions,
|
||||||
// provided that 'm' works with the concrete type of list. d is an optional
|
// provided that 'm' works with the concrete type of list. d is an optional
|
||||||
// decorator for the returned functions. Only matching items are decorated.
|
// decorator for the returned functions. Only matching items are decorated.
|
@ -1,92 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2014 The Kubernetes Authors All rights reserved.
|
|
||||||
|
|
||||||
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/registry/generic"
|
|
||||||
"k8s.io/kubernetes/pkg/runtime"
|
|
||||||
"k8s.io/kubernetes/pkg/watch"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GenericRegistry knows how to store & list any runtime.Object.
|
|
||||||
type GenericRegistry struct {
|
|
||||||
Err error
|
|
||||||
Object runtime.Object
|
|
||||||
ObjectList runtime.Object
|
|
||||||
sync.Mutex
|
|
||||||
|
|
||||||
Broadcaster *watch.Broadcaster
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewGeneric(list runtime.Object) *GenericRegistry {
|
|
||||||
return &GenericRegistry{
|
|
||||||
ObjectList: list,
|
|
||||||
Broadcaster: watch.NewBroadcaster(0, watch.WaitIfChannelFull),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *GenericRegistry) ListPredicate(ctx api.Context, m generic.Matcher) (runtime.Object, error) {
|
|
||||||
r.Lock()
|
|
||||||
defer r.Unlock()
|
|
||||||
if r.Err != nil {
|
|
||||||
return nil, r.Err
|
|
||||||
}
|
|
||||||
return generic.FilterList(r.ObjectList, m, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *GenericRegistry) WatchPredicate(ctx api.Context, m generic.Matcher, resourceVersion string) (watch.Interface, error) {
|
|
||||||
// TODO: wire filter down into the mux; it needs access to current and previous state :(
|
|
||||||
return r.Broadcaster.Watch(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *GenericRegistry) Get(ctx api.Context, id string) (runtime.Object, error) {
|
|
||||||
r.Lock()
|
|
||||||
defer r.Unlock()
|
|
||||||
if r.Err != nil {
|
|
||||||
return nil, r.Err
|
|
||||||
}
|
|
||||||
if r.Object != nil {
|
|
||||||
return r.Object, nil
|
|
||||||
}
|
|
||||||
panic("generic registry should either have an object or an error for Get")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *GenericRegistry) CreateWithName(ctx api.Context, id string, obj runtime.Object) error {
|
|
||||||
r.Lock()
|
|
||||||
defer r.Unlock()
|
|
||||||
r.Object = obj
|
|
||||||
r.Broadcaster.Action(watch.Added, obj)
|
|
||||||
return r.Err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *GenericRegistry) UpdateWithName(ctx api.Context, id string, obj runtime.Object) error {
|
|
||||||
r.Lock()
|
|
||||||
defer r.Unlock()
|
|
||||||
r.Object = obj
|
|
||||||
r.Broadcaster.Action(watch.Modified, obj)
|
|
||||||
return r.Err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *GenericRegistry) Delete(ctx api.Context, id string, options *api.DeleteOptions) (runtime.Object, error) {
|
|
||||||
r.Lock()
|
|
||||||
defer r.Unlock()
|
|
||||||
r.Broadcaster.Action(watch.Deleted, r.Object)
|
|
||||||
return &api.Status{Status: api.StatusSuccess}, r.Err
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user