Merge pull request #71225 from jta/master

Fix duped watch in client-go/testing.

Kubernetes-commit: cab34050e7710993a2d30559599456dfa3ac489d
This commit is contained in:
Kubernetes Publisher 2018-12-13 14:17:55 -08:00
commit 6924ba6dfc
3 changed files with 92 additions and 65 deletions

102
Godeps/Godeps.json generated
View File

@ -404,207 +404,207 @@
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/apitesting", "ImportPath": "k8s.io/apimachinery/pkg/api/apitesting",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/apitesting/fuzzer", "ImportPath": "k8s.io/apimachinery/pkg/api/apitesting/fuzzer",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/apitesting/roundtrip", "ImportPath": "k8s.io/apimachinery/pkg/api/apitesting/roundtrip",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/equality", "ImportPath": "k8s.io/apimachinery/pkg/api/equality",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/errors", "ImportPath": "k8s.io/apimachinery/pkg/api/errors",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/meta", "ImportPath": "k8s.io/apimachinery/pkg/api/meta",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/resource", "ImportPath": "k8s.io/apimachinery/pkg/api/resource",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/fuzzer", "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/fuzzer",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/internalversion", "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/internalversion",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1", "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured", "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1beta1", "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1beta1",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/conversion", "ImportPath": "k8s.io/apimachinery/pkg/conversion",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/conversion/queryparams", "ImportPath": "k8s.io/apimachinery/pkg/conversion/queryparams",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/fields", "ImportPath": "k8s.io/apimachinery/pkg/fields",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/labels", "ImportPath": "k8s.io/apimachinery/pkg/labels",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime", "ImportPath": "k8s.io/apimachinery/pkg/runtime",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/schema", "ImportPath": "k8s.io/apimachinery/pkg/runtime/schema",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/json", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/json",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/protobuf", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/protobuf",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/recognizer", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/recognizer",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/streaming", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/streaming",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/versioning", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/versioning",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/selection", "ImportPath": "k8s.io/apimachinery/pkg/selection",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/types", "ImportPath": "k8s.io/apimachinery/pkg/types",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/cache", "ImportPath": "k8s.io/apimachinery/pkg/util/cache",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/clock", "ImportPath": "k8s.io/apimachinery/pkg/util/clock",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/diff", "ImportPath": "k8s.io/apimachinery/pkg/util/diff",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/errors", "ImportPath": "k8s.io/apimachinery/pkg/util/errors",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/framer", "ImportPath": "k8s.io/apimachinery/pkg/util/framer",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/httpstream", "ImportPath": "k8s.io/apimachinery/pkg/util/httpstream",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/httpstream/spdy", "ImportPath": "k8s.io/apimachinery/pkg/util/httpstream/spdy",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/intstr", "ImportPath": "k8s.io/apimachinery/pkg/util/intstr",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/json", "ImportPath": "k8s.io/apimachinery/pkg/util/json",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/mergepatch", "ImportPath": "k8s.io/apimachinery/pkg/util/mergepatch",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/naming", "ImportPath": "k8s.io/apimachinery/pkg/util/naming",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/net", "ImportPath": "k8s.io/apimachinery/pkg/util/net",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/remotecommand", "ImportPath": "k8s.io/apimachinery/pkg/util/remotecommand",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/runtime", "ImportPath": "k8s.io/apimachinery/pkg/util/runtime",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/sets", "ImportPath": "k8s.io/apimachinery/pkg/util/sets",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/strategicpatch", "ImportPath": "k8s.io/apimachinery/pkg/util/strategicpatch",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/validation", "ImportPath": "k8s.io/apimachinery/pkg/util/validation",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/validation/field", "ImportPath": "k8s.io/apimachinery/pkg/util/validation/field",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/wait", "ImportPath": "k8s.io/apimachinery/pkg/util/wait",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/yaml", "ImportPath": "k8s.io/apimachinery/pkg/util/yaml",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/version", "ImportPath": "k8s.io/apimachinery/pkg/version",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/watch", "ImportPath": "k8s.io/apimachinery/pkg/watch",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/json", "ImportPath": "k8s.io/apimachinery/third_party/forked/golang/json",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/netutil", "ImportPath": "k8s.io/apimachinery/third_party/forked/golang/netutil",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/reflect", "ImportPath": "k8s.io/apimachinery/third_party/forked/golang/reflect",
"Rev": "f1a02064268befe9cb07b02128ff1b6c24041bec" "Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22"
}, },
{ {
"ImportPath": "k8s.io/klog", "ImportPath": "k8s.io/klog",

View File

@ -339,8 +339,10 @@ func (t *tracker) getWatches(gvr schema.GroupVersionResource, ns string) []*watc
if w := t.watchers[gvr][ns]; w != nil { if w := t.watchers[gvr][ns]; w != nil {
watches = append(watches, w...) watches = append(watches, w...)
} }
if w := t.watchers[gvr][""]; w != nil { if ns != metav1.NamespaceAll {
watches = append(watches, w...) if w := t.watchers[gvr][metav1.NamespaceAll]; w != nil {
watches = append(watches, w...)
}
} }
} }
return watches return watches

View File

@ -131,26 +131,47 @@ func TestWatchCallMultipleInvocation(t *testing.T) {
cases := []struct { cases := []struct {
name string name string
op watch.EventType op watch.EventType
ns string
}{ }{
{ {
"foo", "foo",
watch.Added, watch.Added,
"test_namespace",
}, },
{ {
"bar", "bar",
watch.Added, watch.Added,
"test_namespace",
},
{
"baz",
watch.Added,
"",
}, },
{ {
"bar", "bar",
watch.Modified, watch.Modified,
"test_namespace",
},
{
"baz",
watch.Modified,
"",
}, },
{ {
"foo", "foo",
watch.Deleted, watch.Deleted,
"test_namespace",
}, },
{ {
"bar", "bar",
watch.Deleted, watch.Deleted,
"test_namespace",
},
{
"baz",
watch.Deleted,
"",
}, },
} }
@ -169,6 +190,7 @@ func TestWatchCallMultipleInvocation(t *testing.T) {
wg.Add(len(watchNamespaces)) wg.Add(len(watchNamespaces))
for idx, watchNamespace := range watchNamespaces { for idx, watchNamespace := range watchNamespaces {
i := idx i := idx
watchNamespace := watchNamespace
w, err := o.Watch(testResource, watchNamespace) w, err := o.Watch(testResource, watchNamespace)
if err != nil { if err != nil {
t.Fatalf("test resource watch failed in %s: %v", watchNamespace, err) t.Fatalf("test resource watch failed in %s: %v", watchNamespace, err)
@ -176,14 +198,17 @@ func TestWatchCallMultipleInvocation(t *testing.T) {
go func() { go func() {
assert.NoError(t, err, "watch invocation failed") assert.NoError(t, err, "watch invocation failed")
for _, c := range cases { for _, c := range cases {
fmt.Printf("%#v %#v\n", c, i) if watchNamespace == "" || c.ns == watchNamespace {
event := <-w.ResultChan() fmt.Printf("%#v %#v\n", c, i)
accessor, err := meta.Accessor(event.Object) event := <-w.ResultChan()
if err != nil { accessor, err := meta.Accessor(event.Object)
t.Fatalf("unexpected error: %v", err) if err != nil {
t.Fatalf("unexpected error: %v", err)
}
assert.Equal(t, c.op, event.Type, "watch event mismatched")
assert.Equal(t, c.name, accessor.GetName(), "watched object mismatch")
assert.Equal(t, c.ns, accessor.GetNamespace(), "watched object mismatch")
} }
assert.Equal(t, c.op, event.Type, "watch event mismatched")
assert.Equal(t, c.name, accessor.GetName(), "watched object mismatch")
} }
wg.Done() wg.Done()
}() }()
@ -191,13 +216,13 @@ func TestWatchCallMultipleInvocation(t *testing.T) {
for _, c := range cases { for _, c := range cases {
switch c.op { switch c.op {
case watch.Added: case watch.Added:
obj := getArbitraryResource(testResource, c.name, "test_namespace") obj := getArbitraryResource(testResource, c.name, c.ns)
o.Create(testResource, obj, "test_namespace") o.Create(testResource, obj, c.ns)
case watch.Modified: case watch.Modified:
obj := getArbitraryResource(testResource, c.name, "test_namespace") obj := getArbitraryResource(testResource, c.name, c.ns)
o.Update(testResource, obj, "test_namespace") o.Update(testResource, obj, c.ns)
case watch.Deleted: case watch.Deleted:
o.Delete(testResource, "test_namespace", c.name) o.Delete(testResource, c.ns, c.name)
} }
} }
wg.Wait() wg.Wait()