mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +00:00
Namespace scope events in storage
This commit is contained in:
parent
36cfc02c6c
commit
b47cde2465
@ -17,8 +17,6 @@ limitations under the License.
|
|||||||
package event
|
package event
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path"
|
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
etcderr "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors/etcd"
|
etcderr "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors/etcd"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
|
||||||
@ -52,11 +50,10 @@ func NewEtcdRegistry(h tools.EtcdHelper, ttl uint64) generic.Registry {
|
|||||||
NewListFunc: func() runtime.Object { return &api.EventList{} },
|
NewListFunc: func() runtime.Object { return &api.EventList{} },
|
||||||
EndpointName: "events",
|
EndpointName: "events",
|
||||||
KeyRootFunc: func(ctx api.Context) string {
|
KeyRootFunc: func(ctx api.Context) string {
|
||||||
return "/registry/events"
|
return etcdgeneric.NamespaceKeyRootFunc(ctx, "/registry/events")
|
||||||
},
|
},
|
||||||
KeyFunc: func(ctx api.Context, id string) (string, error) {
|
KeyFunc: func(ctx api.Context, id string) (string, error) {
|
||||||
// TODO - we need to store this in a namespace relative path
|
return etcdgeneric.NamespaceKeyFunc(ctx, "/registry/events", id)
|
||||||
return path.Join("/registry/events", id), nil
|
|
||||||
},
|
},
|
||||||
Helper: h,
|
Helper: h,
|
||||||
},
|
},
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
|
||||||
|
etcdgeneric "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic/etcd"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
@ -42,11 +43,11 @@ func NewTestEventEtcdRegistry(t *testing.T) (*tools.FakeEtcdClient, generic.Regi
|
|||||||
|
|
||||||
func TestEventCreate(t *testing.T) {
|
func TestEventCreate(t *testing.T) {
|
||||||
eventA := &api.Event{
|
eventA := &api.Event{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: api.NamespaceDefault},
|
||||||
Reason: "forTesting",
|
Reason: "forTesting",
|
||||||
}
|
}
|
||||||
eventB := &api.Event{
|
eventB := &api.Event{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: api.NamespaceDefault},
|
||||||
Reason: "forTesting",
|
Reason: "forTesting",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,8 +68,12 @@ func TestEventCreate(t *testing.T) {
|
|||||||
E: tools.EtcdErrorNotFound,
|
E: tools.EtcdErrorNotFound,
|
||||||
}
|
}
|
||||||
|
|
||||||
path := "/registry/events/foo"
|
ctx := api.NewDefaultContext()
|
||||||
key := "foo"
|
key := "foo"
|
||||||
|
path, err := etcdgeneric.NamespaceKeyFunc(ctx, "/registry/events", key)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
table := map[string]struct {
|
table := map[string]struct {
|
||||||
existing tools.EtcdResponseWithError
|
existing tools.EtcdResponseWithError
|
||||||
@ -93,7 +98,7 @@ func TestEventCreate(t *testing.T) {
|
|||||||
for name, item := range table {
|
for name, item := range table {
|
||||||
fakeClient, registry := NewTestEventEtcdRegistry(t)
|
fakeClient, registry := NewTestEventEtcdRegistry(t)
|
||||||
fakeClient.Data[path] = item.existing
|
fakeClient.Data[path] = item.existing
|
||||||
err := registry.Create(api.NewContext(), key, item.toCreate)
|
err := registry.Create(ctx, key, item.toCreate)
|
||||||
if !item.errOK(err) {
|
if !item.errOK(err) {
|
||||||
t.Errorf("%v: unexpected error: %v", name, err)
|
t.Errorf("%v: unexpected error: %v", name, err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user