mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Adapt to changes to generic etcd/registry
This commit is contained in:
parent
23d199ded9
commit
8440310ea0
@ -18,7 +18,6 @@ package event
|
||||
|
||||
import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
etcderr "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors/etcd"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
|
||||
etcdgeneric "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic/etcd"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
@ -28,28 +27,6 @@ import (
|
||||
// registry implements custom changes to generic.Etcd.
|
||||
type registry struct {
|
||||
*etcdgeneric.Etcd
|
||||
ttl uint64
|
||||
}
|
||||
|
||||
// Create stores the object with a ttl, so that events don't stay in the system forever.
|
||||
func (r registry) Create(ctx api.Context, id string, obj runtime.Object) error {
|
||||
key, err := r.Etcd.KeyFunc(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = r.Etcd.Helper.CreateObj(key, obj, r.ttl)
|
||||
return etcderr.InterpretCreateError(err, r.Etcd.EndpointName, id)
|
||||
}
|
||||
|
||||
// Update replaces an existing instance of the object, and sets a ttl so that the event
|
||||
// doesn't stay in the system forever.
|
||||
func (r registry) Update(ctx api.Context, id string, obj runtime.Object) error {
|
||||
key, err := r.Etcd.KeyFunc(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = r.Etcd.Helper.SetObj(key, obj, r.ttl)
|
||||
return etcderr.InterpretUpdateError(err, r.Etcd.EndpointName, id)
|
||||
}
|
||||
|
||||
// NewEtcdRegistry returns a registry which will store Events in the given
|
||||
@ -66,8 +43,10 @@ func NewEtcdRegistry(h tools.EtcdHelper, ttl uint64) generic.Registry {
|
||||
KeyFunc: func(ctx api.Context, id string) (string, error) {
|
||||
return etcdgeneric.NamespaceKeyFunc(ctx, "/registry/events", id)
|
||||
},
|
||||
TTLFunc: func(runtime.Object, bool) (uint64, error) {
|
||||
return ttl, nil
|
||||
},
|
||||
Helper: h,
|
||||
},
|
||||
ttl: ttl,
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ func TestEventCreate(t *testing.T) {
|
||||
for name, item := range table {
|
||||
fakeClient, registry := NewTestEventEtcdRegistry(t)
|
||||
fakeClient.Data[path] = item.existing
|
||||
err := registry.Create(ctx, key, item.toCreate)
|
||||
err := registry.CreateWithName(ctx, key, item.toCreate)
|
||||
if !item.errOK(err) {
|
||||
t.Errorf("%v: unexpected error: %v", name, err)
|
||||
}
|
||||
@ -200,7 +200,7 @@ func TestEventUpdate(t *testing.T) {
|
||||
for name, item := range table {
|
||||
fakeClient, registry := NewTestEventEtcdRegistry(t)
|
||||
fakeClient.Data[path] = item.existing
|
||||
err := registry.Update(ctx, key, item.toUpdate)
|
||||
err := registry.UpdateWithName(ctx, key, item.toUpdate)
|
||||
if !item.errOK(err) {
|
||||
t.Errorf("%v: unexpected error: %v", name, err)
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
|
||||
}
|
||||
api.FillObjectMetaSystemFields(ctx, &event.ObjectMeta)
|
||||
|
||||
err := rs.registry.Create(ctx, event.Name, event)
|
||||
err := rs.registry.CreateWithName(ctx, event.Name, event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -79,7 +79,7 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
|
||||
}
|
||||
api.FillObjectMetaSystemFields(ctx, &event.ObjectMeta)
|
||||
|
||||
err := rs.registry.Update(ctx, event.Name, event)
|
||||
err := rs.registry.UpdateWithName(ctx, event.Name, event)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
@ -87,8 +87,8 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
|
||||
return out, false, err
|
||||
}
|
||||
|
||||
func (rs *REST) Delete(ctx api.Context, id string) (runtime.Object, error) {
|
||||
obj, err := rs.registry.Get(ctx, id)
|
||||
func (rs *REST) Delete(ctx api.Context, name string) (runtime.Object, error) {
|
||||
obj, err := rs.registry.Get(ctx, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -96,7 +96,7 @@ func (rs *REST) Delete(ctx api.Context, id string) (runtime.Object, error) {
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid object type")
|
||||
}
|
||||
return &api.Status{Status: api.StatusSuccess}, rs.registry.Delete(ctx, id)
|
||||
return rs.registry.Delete(ctx, name)
|
||||
}
|
||||
|
||||
func (rs *REST) Get(ctx api.Context, id string) (runtime.Object, error) {
|
||||
|
@ -109,7 +109,7 @@ func TestLimitRangeCreate(t *testing.T) {
|
||||
for name, item := range table {
|
||||
fakeClient, registry := NewTestLimitRangeEtcdRegistry(t)
|
||||
fakeClient.Data[path] = item.existing
|
||||
err := registry.Create(ctx, key, item.toCreate)
|
||||
err := registry.CreateWithName(ctx, key, item.toCreate)
|
||||
if !item.errOK(err) {
|
||||
t.Errorf("%v: unexpected error: %v", name, err)
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
|
||||
}
|
||||
api.FillObjectMetaSystemFields(ctx, &limitRange.ObjectMeta)
|
||||
|
||||
err := rs.registry.Create(ctx, limitRange.Name, limitRange)
|
||||
err := rs.registry.CreateWithName(ctx, limitRange.Name, limitRange)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -97,7 +97,7 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
|
||||
return nil, false, errors.NewInvalid("limitRange", editLimitRange.Name, errs)
|
||||
}
|
||||
|
||||
if err := rs.registry.Update(ctx, editLimitRange.Name, editLimitRange); err != nil {
|
||||
if err := rs.registry.UpdateWithName(ctx, editLimitRange.Name, editLimitRange); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
out, err := rs.registry.Get(ctx, editLimitRange.Name)
|
||||
@ -114,7 +114,7 @@ func (rs *REST) Delete(ctx api.Context, name string) (runtime.Object, error) {
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid object type")
|
||||
}
|
||||
return &api.Status{Status: api.StatusSuccess}, rs.registry.Delete(ctx, name)
|
||||
return rs.registry.Delete(ctx, name)
|
||||
}
|
||||
|
||||
// Get gets a LimitRange with the specified name
|
||||
|
@ -48,7 +48,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
|
||||
if err := rest.BeforeCreate(rest.Namespaces, ctx, obj); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rs.registry.Create(ctx, namespace.Name, namespace); err != nil {
|
||||
if err := rs.registry.CreateWithName(ctx, namespace.Name, namespace); err != nil {
|
||||
err = rest.CheckGeneratedNameError(rest.Namespaces, err, namespace)
|
||||
return nil, err
|
||||
}
|
||||
@ -72,7 +72,7 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
|
||||
return nil, false, kerrors.NewInvalid("namespace", namespace.Name, errs)
|
||||
}
|
||||
|
||||
if err := rs.registry.Update(ctx, oldNamespace.Name, oldNamespace); err != nil {
|
||||
if err := rs.registry.UpdateWithName(ctx, oldNamespace.Name, oldNamespace); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
out, err := rs.registry.Get(ctx, oldNamespace.Name)
|
||||
@ -80,8 +80,8 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
|
||||
}
|
||||
|
||||
// Delete deletes the Namespace with the specified name
|
||||
func (rs *REST) Delete(ctx api.Context, id string) (runtime.Object, error) {
|
||||
obj, err := rs.registry.Get(ctx, id)
|
||||
func (rs *REST) Delete(ctx api.Context, name string) (runtime.Object, error) {
|
||||
obj, err := rs.registry.Get(ctx, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -89,7 +89,7 @@ func (rs *REST) Delete(ctx api.Context, id string) (runtime.Object, error) {
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid object type")
|
||||
}
|
||||
return &api.Status{Status: api.StatusSuccess}, rs.registry.Delete(ctx, id)
|
||||
return rs.registry.Delete(ctx, name)
|
||||
}
|
||||
|
||||
func (rs *REST) Get(ctx api.Context, id string) (runtime.Object, error) {
|
||||
|
@ -53,7 +53,7 @@ func (r *registry) ApplyStatus(ctx api.Context, usage *api.ResourceQuotaUsage) e
|
||||
resourceQuota := obj.(*api.ResourceQuota)
|
||||
resourceQuota.ResourceVersion = usage.ResourceVersion
|
||||
resourceQuota.Status = usage.Status
|
||||
return r.Update(ctx, resourceQuota.Name, resourceQuota)
|
||||
return r.UpdateWithName(ctx, resourceQuota.Name, resourceQuota)
|
||||
}
|
||||
|
||||
// NewEtcdRegistry returns a registry which will store ResourceQuota in the given helper
|
||||
|
@ -104,7 +104,7 @@ func TestResourceQuotaCreate(t *testing.T) {
|
||||
for name, item := range table {
|
||||
fakeClient, registry := NewTestLimitRangeEtcdRegistry(t)
|
||||
fakeClient.Data[path] = item.existing
|
||||
err := registry.Create(ctx, key, item.toCreate)
|
||||
err := registry.CreateWithName(ctx, key, item.toCreate)
|
||||
if !item.errOK(err) {
|
||||
t.Errorf("%v: unexpected error: %v, %v", name, err, path)
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
|
||||
}
|
||||
api.FillObjectMetaSystemFields(ctx, &resourceQuota.ObjectMeta)
|
||||
|
||||
err := rs.registry.Create(ctx, resourceQuota.Name, resourceQuota)
|
||||
err := rs.registry.CreateWithName(ctx, resourceQuota.Name, resourceQuota)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -100,7 +100,7 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
|
||||
return nil, false, errors.NewInvalid("resourceQuota", editResourceQuota.Name, errs)
|
||||
}
|
||||
|
||||
if err := rs.registry.Update(ctx, editResourceQuota.Name, editResourceQuota); err != nil {
|
||||
if err := rs.registry.UpdateWithName(ctx, editResourceQuota.Name, editResourceQuota); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
out, err := rs.registry.Get(ctx, editResourceQuota.Name)
|
||||
@ -117,7 +117,7 @@ func (rs *REST) Delete(ctx api.Context, name string) (runtime.Object, error) {
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid object type")
|
||||
}
|
||||
return &api.Status{Status: api.StatusSuccess}, rs.registry.Delete(ctx, name)
|
||||
return rs.registry.Delete(ctx, name)
|
||||
}
|
||||
|
||||
// Get gets a ResourceQuota with the specified name
|
||||
|
Loading…
Reference in New Issue
Block a user