mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-15 06:01:50 +00:00
Support List() single-matchers
This commit is contained in:
@@ -145,9 +145,20 @@ func (e *Etcd) List(ctx api.Context, label labels.Selector, field fields.Selecto
|
||||
// ListPredicate returns a list of all the items matching m.
|
||||
func (e *Etcd) ListPredicate(ctx api.Context, m generic.Matcher) (runtime.Object, error) {
|
||||
list := e.NewListFunc()
|
||||
err := e.Helper.ExtractToList(e.KeyRootFunc(ctx), list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if name, ok := m.MatchesSingle(); ok {
|
||||
key, err := e.KeyFunc(ctx, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = e.Helper.ExtractObjToList(key, list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
err := e.Helper.ExtractToList(e.KeyRootFunc(ctx), list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return generic.FilterList(list, m, generic.DecoratorFunc(e.Decorator))
|
||||
}
|
||||
|
@@ -126,6 +126,11 @@ func TestEtcdList(t *testing.T) {
|
||||
Spec: api.PodSpec{Host: "machine"},
|
||||
}
|
||||
|
||||
singleElemListResp := &etcd.Response{
|
||||
Node: &etcd.Node{
|
||||
Value: runtime.EncodeOrDie(testapi.Codec(), podA),
|
||||
},
|
||||
}
|
||||
normalListResp := &etcd.Response{
|
||||
Node: &etcd.Node{
|
||||
Nodes: []*etcd.Node{
|
||||
@@ -174,7 +179,7 @@ func TestEtcdList(t *testing.T) {
|
||||
},
|
||||
"normalFiltered": {
|
||||
in: tools.EtcdResponseWithError{
|
||||
R: normalListResp,
|
||||
R: singleElemListResp,
|
||||
E: nil,
|
||||
},
|
||||
m: setMatcher{util.NewStringSet("foo")},
|
||||
@@ -194,7 +199,16 @@ func TestEtcdList(t *testing.T) {
|
||||
|
||||
for name, item := range table {
|
||||
fakeClient, registry := NewTestGenericEtcdRegistry(t)
|
||||
fakeClient.Data[registry.KeyRootFunc(api.NewContext())] = item.in
|
||||
if name, ok := item.m.MatchesSingle(); ok {
|
||||
key, err := registry.KeyFunc(api.NewContext(), name)
|
||||
if err != nil {
|
||||
t.Errorf("Couldn't create key for %v", name)
|
||||
continue
|
||||
}
|
||||
fakeClient.Data[key] = item.in
|
||||
} else {
|
||||
fakeClient.Data[registry.KeyRootFunc(api.NewContext())] = item.in
|
||||
}
|
||||
list, err := registry.ListPredicate(api.NewContext(), item.m)
|
||||
if e, a := item.succeed, err == nil; e != a {
|
||||
t.Errorf("%v: expected %v, got %v", name, e, a)
|
||||
|
Reference in New Issue
Block a user