mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
Updated default function names, keyroot to keyrootfunc
This commit is contained in:
parent
6353612f40
commit
92e2c2b302
@ -51,7 +51,7 @@ func NewEtcdRegistry(h tools.EtcdHelper, ttl uint64) generic.Registry {
|
|||||||
NewFunc: func() runtime.Object { return &api.Event{} },
|
NewFunc: func() runtime.Object { return &api.Event{} },
|
||||||
NewListFunc: func() runtime.Object { return &api.EventList{} },
|
NewListFunc: func() runtime.Object { return &api.EventList{} },
|
||||||
EndpointName: "events",
|
EndpointName: "events",
|
||||||
KeyRoot: func(ctx api.Context) string {
|
KeyRootFunc: func(ctx api.Context) string {
|
||||||
return "/registry/events"
|
return "/registry/events"
|
||||||
},
|
},
|
||||||
KeyFunc: func(ctx api.Context, id string) (string, error) {
|
KeyFunc: func(ctx api.Context, id string) (string, error) {
|
||||||
|
@ -42,7 +42,7 @@ type Etcd struct {
|
|||||||
EndpointName string
|
EndpointName string
|
||||||
|
|
||||||
// Used for listing/watching; should not include trailing "/"
|
// Used for listing/watching; should not include trailing "/"
|
||||||
KeyRoot func(ctx api.Context) string
|
KeyRootFunc func(ctx api.Context) string
|
||||||
|
|
||||||
// Called for Create/Update/Get/Delete
|
// Called for Create/Update/Get/Delete
|
||||||
KeyFunc func(ctx api.Context, id string) (string, error)
|
KeyFunc func(ctx api.Context, id string) (string, error)
|
||||||
@ -51,8 +51,8 @@ type Etcd struct {
|
|||||||
Helper tools.EtcdHelper
|
Helper tools.EtcdHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeEtcdListKey constructs etcd paths to resource directories enforcing namespace rules
|
// NamespaceKeyRootFunc is the default function for constructing etcd paths to resource directories enforcing namespace rules.
|
||||||
func MakeEtcdListKey(ctx api.Context, prefix string) string {
|
func NamespaceKeyRootFunc(ctx api.Context, prefix string) string {
|
||||||
key := prefix
|
key := prefix
|
||||||
ns, ok := api.NamespaceFrom(ctx)
|
ns, ok := api.NamespaceFrom(ctx)
|
||||||
if ok && len(ns) > 0 {
|
if ok && len(ns) > 0 {
|
||||||
@ -61,9 +61,10 @@ func MakeEtcdListKey(ctx api.Context, prefix string) string {
|
|||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeEtcdItemKey constructs etcd paths to a resource relative to prefix enforcing namespace rules. If no namespace is on context, it errors.
|
// NamespaceKeyFunc is the default function for constructing etcd paths to a resource relative to prefix enforcing namespace rules.
|
||||||
func MakeEtcdItemKey(ctx api.Context, prefix string, id string) (string, error) {
|
// If no namespace is on context, it errors.
|
||||||
key := MakeEtcdListKey(ctx, prefix)
|
func NamespaceKeyFunc(ctx api.Context, prefix string, id string) (string, error) {
|
||||||
|
key := NamespaceKeyRootFunc(ctx, prefix)
|
||||||
ns, ok := api.NamespaceFrom(ctx)
|
ns, ok := api.NamespaceFrom(ctx)
|
||||||
if !ok || len(ns) == 0 {
|
if !ok || len(ns) == 0 {
|
||||||
return "", kubeerr.NewBadRequest("Namespace parameter required.")
|
return "", kubeerr.NewBadRequest("Namespace parameter required.")
|
||||||
@ -78,7 +79,7 @@ func MakeEtcdItemKey(ctx api.Context, prefix string, id string) (string, error)
|
|||||||
// List returns a list of all the items matching m.
|
// List returns a list of all the items matching m.
|
||||||
func (e *Etcd) List(ctx api.Context, m generic.Matcher) (runtime.Object, error) {
|
func (e *Etcd) List(ctx api.Context, m generic.Matcher) (runtime.Object, error) {
|
||||||
list := e.NewListFunc()
|
list := e.NewListFunc()
|
||||||
err := e.Helper.ExtractToList(e.KeyRoot(ctx), list)
|
err := e.Helper.ExtractToList(e.KeyRootFunc(ctx), list)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -137,7 +138,7 @@ func (e *Etcd) Watch(ctx api.Context, m generic.Matcher, resourceVersion string)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return e.Helper.WatchList(e.KeyRoot(ctx), version, func(obj runtime.Object) bool {
|
return e.Helper.WatchList(e.KeyRootFunc(ctx), version, func(obj runtime.Object) bool {
|
||||||
matches, err := m.Matches(obj)
|
matches, err := m.Matches(obj)
|
||||||
return err == nil && matches
|
return err == nil && matches
|
||||||
})
|
})
|
||||||
|
@ -41,7 +41,7 @@ func NewTestGenericEtcdRegistry(t *testing.T) (*tools.FakeEtcdClient, *Etcd) {
|
|||||||
NewFunc: func() runtime.Object { return &api.Pod{} },
|
NewFunc: func() runtime.Object { return &api.Pod{} },
|
||||||
NewListFunc: func() runtime.Object { return &api.PodList{} },
|
NewListFunc: func() runtime.Object { return &api.PodList{} },
|
||||||
EndpointName: "pods",
|
EndpointName: "pods",
|
||||||
KeyRoot: func(ctx api.Context) string { return "/registry/pods" },
|
KeyRootFunc: func(ctx api.Context) string { return "/registry/pods" },
|
||||||
KeyFunc: func(ctx api.Context, id string) (string, error) {
|
KeyFunc: func(ctx api.Context, id string) (string, error) {
|
||||||
return path.Join("/registry/pods", id), nil
|
return path.Join("/registry/pods", id), nil
|
||||||
},
|
},
|
||||||
@ -139,7 +139,7 @@ func TestEtcdList(t *testing.T) {
|
|||||||
|
|
||||||
for name, item := range table {
|
for name, item := range table {
|
||||||
fakeClient, registry := NewTestGenericEtcdRegistry(t)
|
fakeClient, registry := NewTestGenericEtcdRegistry(t)
|
||||||
fakeClient.Data[registry.KeyRoot(api.NewContext())] = item.in
|
fakeClient.Data[registry.KeyRootFunc(api.NewContext())] = item.in
|
||||||
list, err := registry.List(api.NewContext(), item.m)
|
list, err := registry.List(api.NewContext(), item.m)
|
||||||
if e, a := item.succeed, err == nil; e != a {
|
if e, a := item.succeed, err == nil; e != a {
|
||||||
t.Errorf("%v: expected %v, got %v", name, e, a)
|
t.Errorf("%v: expected %v, got %v", name, e, a)
|
||||||
|
Loading…
Reference in New Issue
Block a user