Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
bd268c99
Commit
bd268c99
authored
Nov 19, 2018
by
João Taveira Araújo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix duped watch in client-go/testing.
This commit fixes a bug in the client-go/testing fixture whereby a watcher would fire twice for objects with no namespace.
parent
8848740f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
14 deletions
+41
-14
fixture.go
staging/src/k8s.io/client-go/testing/fixture.go
+4
-2
fixture_test.go
staging/src/k8s.io/client-go/testing/fixture_test.go
+37
-12
No files found.
staging/src/k8s.io/client-go/testing/fixture.go
View file @
bd268c99
...
...
@@ -339,8 +339,10 @@ func (t *tracker) getWatches(gvr schema.GroupVersionResource, ns string) []*watc
if
w
:=
t
.
watchers
[
gvr
][
ns
];
w
!=
nil
{
watches
=
append
(
watches
,
w
...
)
}
if
w
:=
t
.
watchers
[
gvr
][
""
];
w
!=
nil
{
watches
=
append
(
watches
,
w
...
)
if
ns
!=
metav1
.
NamespaceAll
{
if
w
:=
t
.
watchers
[
gvr
][
metav1
.
NamespaceAll
];
w
!=
nil
{
watches
=
append
(
watches
,
w
...
)
}
}
}
return
watches
...
...
staging/src/k8s.io/client-go/testing/fixture_test.go
View file @
bd268c99
...
...
@@ -131,26 +131,47 @@ func TestWatchCallMultipleInvocation(t *testing.T) {
cases
:=
[]
struct
{
name
string
op
watch
.
EventType
ns
string
}{
{
"foo"
,
watch
.
Added
,
"test_namespace"
,
},
{
"bar"
,
watch
.
Added
,
"test_namespace"
,
},
{
"baz"
,
watch
.
Added
,
""
,
},
{
"bar"
,
watch
.
Modified
,
"test_namespace"
,
},
{
"baz"
,
watch
.
Modified
,
""
,
},
{
"foo"
,
watch
.
Deleted
,
"test_namespace"
,
},
{
"bar"
,
watch
.
Deleted
,
"test_namespace"
,
},
{
"baz"
,
watch
.
Deleted
,
""
,
},
}
...
...
@@ -169,6 +190,7 @@ func TestWatchCallMultipleInvocation(t *testing.T) {
wg
.
Add
(
len
(
watchNamespaces
))
for
idx
,
watchNamespace
:=
range
watchNamespaces
{
i
:=
idx
watchNamespace
:=
watchNamespace
w
,
err
:=
o
.
Watch
(
testResource
,
watchNamespace
)
if
err
!=
nil
{
t
.
Fatalf
(
"test resource watch failed in %s: %v"
,
watchNamespace
,
err
)
...
...
@@ -176,14 +198,17 @@ func TestWatchCallMultipleInvocation(t *testing.T) {
go
func
()
{
assert
.
NoError
(
t
,
err
,
"watch invocation failed"
)
for
_
,
c
:=
range
cases
{
fmt
.
Printf
(
"%#v %#v
\n
"
,
c
,
i
)
event
:=
<-
w
.
ResultChan
()
accessor
,
err
:=
meta
.
Accessor
(
event
.
Object
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
if
watchNamespace
==
""
||
c
.
ns
==
watchNamespace
{
fmt
.
Printf
(
"%#v %#v
\n
"
,
c
,
i
)
event
:=
<-
w
.
ResultChan
()
accessor
,
err
:=
meta
.
Accessor
(
event
.
Object
)
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
()
}()
...
...
@@ -191,13 +216,13 @@ func TestWatchCallMultipleInvocation(t *testing.T) {
for
_
,
c
:=
range
cases
{
switch
c
.
op
{
case
watch
.
Added
:
obj
:=
getArbitraryResource
(
testResource
,
c
.
name
,
"test_namespace"
)
o
.
Create
(
testResource
,
obj
,
"test_namespace"
)
obj
:=
getArbitraryResource
(
testResource
,
c
.
name
,
c
.
ns
)
o
.
Create
(
testResource
,
obj
,
c
.
ns
)
case
watch
.
Modified
:
obj
:=
getArbitraryResource
(
testResource
,
c
.
name
,
"test_namespace"
)
o
.
Update
(
testResource
,
obj
,
"test_namespace"
)
obj
:=
getArbitraryResource
(
testResource
,
c
.
name
,
c
.
ns
)
o
.
Update
(
testResource
,
obj
,
c
.
ns
)
case
watch
.
Deleted
:
o
.
Delete
(
testResource
,
"test_namespace"
,
c
.
name
)
o
.
Delete
(
testResource
,
c
.
ns
,
c
.
name
)
}
}
wg
.
Wait
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment