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
0df769f5
Unverified
Commit
0df769f5
authored
Aug 01, 2017
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correctly handle empty watch event cache
parent
5ce3b359
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
1 deletion
+67
-1
cacher_test.go
...ing/src/k8s.io/apiserver/pkg/storage/tests/cacher_test.go
+64
-0
watch_cache.go
staging/src/k8s.io/apiserver/pkg/storage/watch_cache.go
+3
-1
No files found.
staging/src/k8s.io/apiserver/pkg/storage/tests/cacher_test.go
View file @
0df769f5
...
@@ -537,6 +537,70 @@ func TestStartingResourceVersion(t *testing.T) {
...
@@ -537,6 +537,70 @@ func TestStartingResourceVersion(t *testing.T) {
}
}
}
}
func
TestEmptyWatchEventCache
(
t
*
testing
.
T
)
{
server
,
etcdStorage
:=
newEtcdTestStorage
(
t
,
etcdtest
.
PathPrefix
())
defer
server
.
Terminate
(
t
)
// add a few objects
updatePod
(
t
,
etcdStorage
,
makeTestPod
(
"pod1"
),
nil
)
updatePod
(
t
,
etcdStorage
,
makeTestPod
(
"pod2"
),
nil
)
updatePod
(
t
,
etcdStorage
,
makeTestPod
(
"pod3"
),
nil
)
updatePod
(
t
,
etcdStorage
,
makeTestPod
(
"pod4"
),
nil
)
updatePod
(
t
,
etcdStorage
,
makeTestPod
(
"pod5"
),
nil
)
fooCreated
:=
updatePod
(
t
,
etcdStorage
,
makeTestPod
(
"foo"
),
nil
)
// get rv of last pod created
rv
,
err
:=
storage
.
ParseWatchResourceVersion
(
fooCreated
.
ResourceVersion
)
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
cacher
:=
newTestCacher
(
etcdStorage
,
10
)
defer
cacher
.
Stop
()
// We now have a cacher with an empty cache of watch events and a resourceVersion of rv.
// It should support establishing watches from rv and higher, but not older.
{
watcher
,
err
:=
cacher
.
Watch
(
context
.
TODO
(),
"pods/ns"
,
strconv
.
Itoa
(
int
(
rv
-
1
)),
storage
.
Everything
)
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
defer
watcher
.
Stop
()
expectedGoneError
:=
errors
.
NewGone
(
""
)
.
ErrStatus
verifyWatchEvent
(
t
,
watcher
,
watch
.
Error
,
&
expectedGoneError
)
}
{
watcher
,
err
:=
cacher
.
Watch
(
context
.
TODO
(),
"pods/ns"
,
strconv
.
Itoa
(
int
(
rv
+
1
)),
storage
.
Everything
)
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
defer
watcher
.
Stop
()
select
{
case
e
:=
<-
watcher
.
ResultChan
()
:
t
.
Errorf
(
"unexpected event %#v"
,
e
)
case
<-
time
.
After
(
3
*
time
.
Second
)
:
// watch from rv+1 remained established successfully
}
}
{
watcher
,
err
:=
cacher
.
Watch
(
context
.
TODO
(),
"pods/ns"
,
strconv
.
Itoa
(
int
(
rv
)),
storage
.
Everything
)
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
defer
watcher
.
Stop
()
select
{
case
e
:=
<-
watcher
.
ResultChan
()
:
t
.
Errorf
(
"unexpected event %#v"
,
e
)
case
<-
time
.
After
(
3
*
time
.
Second
)
:
// watch from rv remained established successfully
}
}
}
func
TestRandomWatchDeliver
(
t
*
testing
.
T
)
{
func
TestRandomWatchDeliver
(
t
*
testing
.
T
)
{
server
,
etcdStorage
:=
newEtcdTestStorage
(
t
,
etcdtest
.
PathPrefix
())
server
,
etcdStorage
:=
newEtcdTestStorage
(
t
,
etcdtest
.
PathPrefix
())
defer
server
.
Terminate
(
t
)
defer
server
.
Terminate
(
t
)
...
...
staging/src/k8s.io/apiserver/pkg/storage/watch_cache.go
View file @
0df769f5
...
@@ -412,7 +412,9 @@ func (w *watchCache) SetOnEvent(onEvent func(*watchCacheEvent)) {
...
@@ -412,7 +412,9 @@ func (w *watchCache) SetOnEvent(onEvent func(*watchCacheEvent)) {
func
(
w
*
watchCache
)
GetAllEventsSinceThreadUnsafe
(
resourceVersion
uint64
)
([]
*
watchCacheEvent
,
error
)
{
func
(
w
*
watchCache
)
GetAllEventsSinceThreadUnsafe
(
resourceVersion
uint64
)
([]
*
watchCacheEvent
,
error
)
{
size
:=
w
.
endIndex
-
w
.
startIndex
size
:=
w
.
endIndex
-
w
.
startIndex
oldest
:=
w
.
resourceVersion
// if we have no watch events in our cache, the oldest one we can successfully deliver to a watcher
// is the *next* event we'll receive, which will be at least one greater than our current resourceVersion
oldest
:=
w
.
resourceVersion
+
1
if
size
>
0
{
if
size
>
0
{
oldest
=
w
.
cache
[
w
.
startIndex
%
w
.
capacity
]
.
resourceVersion
oldest
=
w
.
cache
[
w
.
startIndex
%
w
.
capacity
]
.
resourceVersion
}
}
...
...
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