mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-14 13:45:06 +00:00
use Watch for single object instead of WatchList
This commit is contained in:
@@ -429,18 +429,7 @@ func (e *Etcd) WatchPredicate(ctx api.Context, m generic.Matcher, resourceVersio
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var watchKey string
|
||||
if name, ok := m.MatchesSingle(); ok {
|
||||
key, err := e.KeyFunc(ctx, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
watchKey = key
|
||||
} else {
|
||||
watchKey = e.KeyRootFunc(ctx)
|
||||
}
|
||||
|
||||
return e.Helper.WatchList(watchKey, version, func(obj runtime.Object) bool {
|
||||
filterFunc := func(obj runtime.Object) bool {
|
||||
matches, err := m.Matches(obj)
|
||||
if err != nil {
|
||||
glog.Errorf("unable to match watch: %v", err)
|
||||
@@ -453,5 +442,15 @@ func (e *Etcd) WatchPredicate(ctx api.Context, m generic.Matcher, resourceVersio
|
||||
}
|
||||
}
|
||||
return matches
|
||||
})
|
||||
}
|
||||
|
||||
if name, ok := m.MatchesSingle(); ok {
|
||||
key, err := e.KeyFunc(ctx, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return e.Helper.Watch(key, version, filterFunc)
|
||||
}
|
||||
|
||||
return e.Helper.WatchList(e.KeyRootFunc(ctx), version, filterFunc)
|
||||
}
|
||||
|
@@ -690,11 +690,16 @@ func TestEtcdWatch(t *testing.T) {
|
||||
|
||||
for name, m := range table {
|
||||
podA := &api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"},
|
||||
Spec: api.PodSpec{Host: "machine"},
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
Namespace: api.NamespaceDefault,
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Spec: api.PodSpec{Host: "machine"},
|
||||
}
|
||||
respWithPodA := &etcd.Response{
|
||||
Node: &etcd.Node{
|
||||
Key: "/registry/pods/default/foo",
|
||||
Value: runtime.EncodeOrDie(testapi.Codec(), podA),
|
||||
ModifiedIndex: 1,
|
||||
CreatedIndex: 1,
|
||||
|
Reference in New Issue
Block a user