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
da7e9783
Commit
da7e9783
authored
May 09, 2016
by
Hongchao Deng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
etcd3/watcher: Event.Object should have the same rev as etcd delete
instead of previous object's revision.
parent
def76394
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
4 deletions
+38
-4
watcher.go
pkg/storage/etcd3/watcher.go
+5
-1
watcher_test.go
pkg/storage/etcd3/watcher_test.go
+33
-3
No files found.
pkg/storage/etcd3/watcher.go
View file @
da7e9783
...
@@ -322,7 +322,11 @@ func prepareObjs(ctx context.Context, e *event, client *clientv3.Client, codec r
...
@@ -322,7 +322,11 @@ func prepareObjs(ctx context.Context, e *event, client *clientv3.Client, codec r
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
err
return
nil
,
nil
,
err
}
}
oldObj
,
err
=
decodeObj
(
codec
,
versioner
,
getResp
.
Kvs
[
0
]
.
Value
,
getResp
.
Kvs
[
0
]
.
ModRevision
)
// Note that this sends the *old* object with the etcd revision for the time at
// which it gets deleted.
// We assume old object is returned only in Deleted event. Users (e.g. cacher) need
// to have larger than previous rev to tell the ordering.
oldObj
,
err
=
decodeObj
(
codec
,
versioner
,
getResp
.
Kvs
[
0
]
.
Value
,
e
.
rev
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
err
return
nil
,
nil
,
err
}
}
...
...
pkg/storage/etcd3/watcher_test.go
View file @
da7e9783
...
@@ -20,11 +20,11 @@ import (
...
@@ -20,11 +20,11 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"reflect"
"reflect"
"sync"
"testing"
"testing"
"time"
"time"
"sync"
"github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/integration"
"github.com/coreos/etcd/integration"
"golang.org/x/net/context"
"golang.org/x/net/context"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
...
@@ -123,7 +123,7 @@ func TestDeleteTriggerWatch(t *testing.T) {
...
@@ -123,7 +123,7 @@ func TestDeleteTriggerWatch(t *testing.T) {
if
err
:=
store
.
Delete
(
ctx
,
key
,
&
api
.
Pod
{},
nil
);
err
!=
nil
{
if
err
:=
store
.
Delete
(
ctx
,
key
,
&
api
.
Pod
{},
nil
);
err
!=
nil
{
t
.
Fatalf
(
"Delete failed: %v"
,
err
)
t
.
Fatalf
(
"Delete failed: %v"
,
err
)
}
}
testCheckResult
(
t
,
0
,
watch
.
Deleted
,
w
,
storedObj
)
testCheckResult
(
t
,
0
,
watch
.
Deleted
,
w
,
nil
)
}
}
// TestWatchSync tests that
// TestWatchSync tests that
...
@@ -213,6 +213,36 @@ func TestWatchErrResultNotBlockAfterCancel(t *testing.T) {
...
@@ -213,6 +213,36 @@ func TestWatchErrResultNotBlockAfterCancel(t *testing.T) {
wg
.
Wait
()
wg
.
Wait
()
}
}
func
TestWatchDeleteEventObjectShouldHaveLatestRV
(
t
*
testing
.
T
)
{
ctx
,
store
,
cluster
:=
testSetup
(
t
)
defer
cluster
.
Terminate
(
t
)
key
,
storedObj
:=
testPropogateStore
(
t
,
store
,
ctx
,
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}})
w
,
err
:=
store
.
Watch
(
ctx
,
key
,
storedObj
.
ResourceVersion
,
storage
.
Everything
)
if
err
!=
nil
{
t
.
Fatalf
(
"Watch failed: %v"
,
err
)
}
etcdW
:=
cluster
.
RandClient
()
.
Watch
(
ctx
,
"/"
,
clientv3
.
WithPrefix
())
if
err
:=
store
.
Delete
(
ctx
,
key
,
&
api
.
Pod
{},
&
storage
.
Preconditions
{});
err
!=
nil
{
t
.
Fatalf
(
"Delete failed: %v"
,
err
)
}
e
:=
<-
w
.
ResultChan
()
watchedDeleteObj
:=
e
.
Object
.
(
*
api
.
Pod
)
var
wres
clientv3
.
WatchResponse
wres
=
<-
etcdW
watchedDeleteRev
,
err
:=
storage
.
ParseWatchResourceVersion
(
watchedDeleteObj
.
ResourceVersion
)
if
err
!=
nil
{
t
.
Fatalf
(
"ParseWatchResourceVersion failed: %v"
,
err
)
}
if
int64
(
watchedDeleteRev
)
!=
wres
.
Events
[
0
]
.
Kv
.
ModRevision
{
t
.
Errorf
(
"Object from delete event have version: %v, should be the same as etcd delete's mod rev: %d"
,
watchedDeleteRev
,
wres
.
Events
[
0
]
.
Kv
.
ModRevision
)
}
}
type
testWatchStruct
struct
{
type
testWatchStruct
struct
{
obj
*
api
.
Pod
obj
*
api
.
Pod
expectEvent
bool
expectEvent
bool
...
...
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