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
34db128a
Commit
34db128a
authored
Dec 04, 2016
by
Hongchao Deng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
etcd2: watch on 0 to return ADDED always
parent
2c61d2f8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
8 deletions
+19
-8
etcd_watcher.go
pkg/storage/etcd/etcd_watcher.go
+2
-3
etcd_watcher_test.go
pkg/storage/etcd/etcd_watcher_test.go
+17
-5
No files found.
pkg/storage/etcd/etcd_watcher.go
View file @
34db128a
...
@@ -359,9 +359,6 @@ func (w *etcdWatcher) sendAdd(res *etcd.Response) {
...
@@ -359,9 +359,6 @@ func (w *etcdWatcher) sendAdd(res *etcd.Response) {
return
return
}
}
action
:=
watch
.
Added
action
:=
watch
.
Added
if
res
.
Node
.
ModifiedIndex
!=
res
.
Node
.
CreatedIndex
{
action
=
watch
.
Modified
}
w
.
emit
(
watch
.
Event
{
w
.
emit
(
watch
.
Event
{
Type
:
action
,
Type
:
action
,
Object
:
obj
,
Object
:
obj
,
...
@@ -454,6 +451,8 @@ func (w *etcdWatcher) sendDelete(res *etcd.Response) {
...
@@ -454,6 +451,8 @@ func (w *etcdWatcher) sendDelete(res *etcd.Response) {
func
(
w
*
etcdWatcher
)
sendResult
(
res
*
etcd
.
Response
)
{
func
(
w
*
etcdWatcher
)
sendResult
(
res
*
etcd
.
Response
)
{
switch
res
.
Action
{
switch
res
.
Action
{
case
EtcdCreate
,
EtcdGet
:
case
EtcdCreate
,
EtcdGet
:
// "Get" will only happen in watch 0 case, where we explicitly want ADDED event
// for initial state.
w
.
sendAdd
(
res
)
w
.
sendAdd
(
res
)
case
EtcdSet
,
EtcdCAS
:
case
EtcdSet
,
EtcdCAS
:
w
.
sendModify
(
res
)
w
.
sendModify
(
res
)
...
...
pkg/storage/etcd/etcd_watcher_test.go
View file @
34db128a
...
@@ -412,6 +412,18 @@ func TestWatchFromZeroIndex(t *testing.T) {
...
@@ -412,6 +412,18 @@ func TestWatchFromZeroIndex(t *testing.T) {
}
}
pod
.
ResourceVersion
=
""
pod
.
ResourceVersion
=
""
watching
,
err
:=
h
.
Watch
(
context
.
TODO
(),
key
,
"0"
,
storage
.
Everything
)
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
// The create trigger ADDED event when watching from 0
event
:=
<-
watching
.
ResultChan
()
watching
.
Stop
()
if
event
.
Type
!=
watch
.
Added
{
t
.
Errorf
(
"Unexpected event %#v"
,
event
)
}
// check for concatenation on watch event with CAS
// check for concatenation on watch event with CAS
updateFn
:=
func
(
input
runtime
.
Object
,
res
storage
.
ResponseMeta
)
(
runtime
.
Object
,
*
uint64
,
error
)
{
updateFn
:=
func
(
input
runtime
.
Object
,
res
storage
.
ResponseMeta
)
(
runtime
.
Object
,
*
uint64
,
error
)
{
pod
:=
input
.
(
*
api
.
Pod
)
pod
:=
input
.
(
*
api
.
Pod
)
...
@@ -423,15 +435,15 @@ func TestWatchFromZeroIndex(t *testing.T) {
...
@@ -423,15 +435,15 @@ func TestWatchFromZeroIndex(t *testing.T) {
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
watching
,
err
:
=
h
.
Watch
(
context
.
TODO
(),
key
,
"0"
,
storage
.
Everything
)
watching
,
err
=
h
.
Watch
(
context
.
TODO
(),
key
,
"0"
,
storage
.
Everything
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
defer
watching
.
Stop
()
defer
watching
.
Stop
()
//
marked as modified b/c of concatenation
//
because we watch from 0, first event that we receive will always be ADDED
event
:
=
<-
watching
.
ResultChan
()
event
=
<-
watching
.
ResultChan
()
if
event
.
Type
!=
watch
.
Modifi
ed
{
if
event
.
Type
!=
watch
.
Add
ed
{
t
.
Errorf
(
"Unexpected event %#v"
,
event
)
t
.
Errorf
(
"Unexpected event %#v"
,
event
)
}
}
...
@@ -451,7 +463,7 @@ func TestWatchFromZeroIndex(t *testing.T) {
...
@@ -451,7 +463,7 @@ func TestWatchFromZeroIndex(t *testing.T) {
t
.
Errorf
(
"Unexpected event %#v"
,
event
)
t
.
Errorf
(
"Unexpected event %#v"
,
event
)
}
}
if
e
,
a
:=
pod
,
event
.
Object
;
!
api
.
Semantic
.
DeepDerivative
(
e
,
a
)
{
if
e
,
a
:=
pod
,
event
.
Object
;
a
==
nil
||
!
api
.
Semantic
.
DeepDerivative
(
e
,
a
)
{
t
.
Errorf
(
"Unexpected error: expected %#v, got %#v"
,
e
,
a
)
t
.
Errorf
(
"Unexpected error: expected %#v, got %#v"
,
e
,
a
)
}
}
}
}
...
...
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