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
81779360
Commit
81779360
authored
Oct 13, 2016
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Accept Quorum parameter in etcd3.
parent
864a7bac
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
13 deletions
+31
-13
store.go
pkg/storage/etcd3/store.go
+22
-7
store_test.go
pkg/storage/etcd3/store_test.go
+2
-2
watcher.go
pkg/storage/etcd3/watcher.go
+1
-1
watcher_test.go
pkg/storage/etcd3/watcher_test.go
+2
-2
etcd3.go
pkg/storage/storagebackend/factory/etcd3.go
+4
-1
No files found.
pkg/storage/etcd3/store.go
View file @
81779360
...
...
@@ -38,7 +38,10 @@ import (
)
type
store
struct
{
client
*
clientv3
.
Client
client
*
clientv3
.
Client
// getOpts contains additional options that should be passed
// to all Get() calls.
getOps
[]
clientv3
.
OpOption
codec
runtime
.
Codec
versioner
storage
.
Versioner
pathPrefix
string
...
...
@@ -59,18 +62,30 @@ type objState struct {
// New returns an etcd3 implementation of storage.Interface.
func
New
(
c
*
clientv3
.
Client
,
codec
runtime
.
Codec
,
prefix
string
)
storage
.
Interface
{
return
newStore
(
c
,
codec
,
prefix
)
return
newStore
(
c
,
true
,
codec
,
prefix
)
}
func
newStore
(
c
*
clientv3
.
Client
,
codec
runtime
.
Codec
,
prefix
string
)
*
store
{
// NewWithNoQuorumRead returns etcd3 implementation of storage.Interface
// where Get operations don't require quorum read.
func
NewWithNoQuorumRead
(
c
*
clientv3
.
Client
,
codec
runtime
.
Codec
,
prefix
string
)
storage
.
Interface
{
return
newStore
(
c
,
false
,
codec
,
prefix
)
}
func
newStore
(
c
*
clientv3
.
Client
,
quorumRead
bool
,
codec
runtime
.
Codec
,
prefix
string
)
*
store
{
versioner
:=
etcd
.
APIObjectVersioner
{}
re
turn
&
store
{
re
sult
:=
&
store
{
client
:
c
,
versioner
:
versioner
,
codec
:
codec
,
pathPrefix
:
prefix
,
watcher
:
newWatcher
(
c
,
codec
,
versioner
),
}
if
!
quorumRead
{
// In case of non-quorum reads, we can set WithSerializable()
// options for all Get operations.
result
.
getOps
=
append
(
result
.
getOps
,
clientv3
.
WithSerializable
())
}
return
result
}
// Versioner implements storage.Interface.Versioner.
...
...
@@ -81,7 +96,7 @@ func (s *store) Versioner() storage.Versioner {
// Get implements storage.Interface.Get.
func
(
s
*
store
)
Get
(
ctx
context
.
Context
,
key
string
,
out
runtime
.
Object
,
ignoreNotFound
bool
)
error
{
key
=
keyWithPrefix
(
s
.
pathPrefix
,
key
)
getResp
,
err
:=
s
.
client
.
KV
.
Get
(
ctx
,
key
)
getResp
,
err
:=
s
.
client
.
KV
.
Get
(
ctx
,
key
,
s
.
getOps
...
)
if
err
!=
nil
{
return
err
}
...
...
@@ -202,7 +217,7 @@ func (s *store) GuaranteedUpdate(ctx context.Context, key string, out runtime.Ob
panic
(
"unable to convert output object to pointer"
)
}
key
=
keyWithPrefix
(
s
.
pathPrefix
,
key
)
getResp
,
err
:=
s
.
client
.
KV
.
Get
(
ctx
,
key
)
getResp
,
err
:=
s
.
client
.
KV
.
Get
(
ctx
,
key
,
s
.
getOps
...
)
if
err
!=
nil
{
return
err
}
...
...
@@ -262,7 +277,7 @@ func (s *store) GetToList(ctx context.Context, key string, pred storage.Selectio
}
key
=
keyWithPrefix
(
s
.
pathPrefix
,
key
)
getResp
,
err
:=
s
.
client
.
KV
.
Get
(
ctx
,
key
)
getResp
,
err
:=
s
.
client
.
KV
.
Get
(
ctx
,
key
,
s
.
getOps
...
)
if
err
!=
nil
{
return
err
}
...
...
pkg/storage/etcd3/store_test.go
View file @
81779360
...
...
@@ -451,7 +451,7 @@ func TestGuaranteedUpdateWithConflict(t *testing.T) {
func
TestList
(
t
*
testing
.
T
)
{
cluster
:=
integration
.
NewClusterV3
(
t
,
&
integration
.
ClusterConfig
{
Size
:
1
})
defer
cluster
.
Terminate
(
t
)
store
:=
newStore
(
cluster
.
RandClient
(),
testapi
.
Default
.
Codec
(),
""
)
store
:=
newStore
(
cluster
.
RandClient
(),
false
,
testapi
.
Default
.
Codec
(),
""
)
ctx
:=
context
.
Background
()
// Setup storage with the following structure:
...
...
@@ -538,7 +538,7 @@ func TestList(t *testing.T) {
func
testSetup
(
t
*
testing
.
T
)
(
context
.
Context
,
*
store
,
*
integration
.
ClusterV3
)
{
cluster
:=
integration
.
NewClusterV3
(
t
,
&
integration
.
ClusterConfig
{
Size
:
1
})
store
:=
newStore
(
cluster
.
RandClient
(),
testapi
.
Default
.
Codec
(),
""
)
store
:=
newStore
(
cluster
.
RandClient
(),
false
,
testapi
.
Default
.
Codec
(),
""
)
ctx
:=
context
.
Background
()
return
ctx
,
store
,
cluster
}
...
...
pkg/storage/etcd3/watcher.go
View file @
81779360
...
...
@@ -158,7 +158,7 @@ func (wc *watchChan) sync() error {
wc
.
initialRev
=
getResp
.
Header
.
Revision
for
_
,
kv
:=
range
getResp
.
Kvs
{
prevResp
,
err
:=
wc
.
watcher
.
client
.
Get
(
wc
.
ctx
,
string
(
kv
.
Key
),
clientv3
.
WithRev
(
kv
.
ModRevision
-
1
))
prevResp
,
err
:=
wc
.
watcher
.
client
.
Get
(
wc
.
ctx
,
string
(
kv
.
Key
),
clientv3
.
WithRev
(
kv
.
ModRevision
-
1
)
,
clientv3
.
WithSerializable
()
)
if
err
!=
nil
{
return
err
}
...
...
pkg/storage/etcd3/watcher_test.go
View file @
81779360
...
...
@@ -176,13 +176,13 @@ func TestWatchFromNoneZero(t *testing.T) {
func
TestWatchError
(
t
*
testing
.
T
)
{
cluster
:=
integration
.
NewClusterV3
(
t
,
&
integration
.
ClusterConfig
{
Size
:
1
})
defer
cluster
.
Terminate
(
t
)
invalidStore
:=
newStore
(
cluster
.
RandClient
(),
&
testCodec
{
testapi
.
Default
.
Codec
()},
""
)
invalidStore
:=
newStore
(
cluster
.
RandClient
(),
false
,
&
testCodec
{
testapi
.
Default
.
Codec
()},
""
)
ctx
:=
context
.
Background
()
w
,
err
:=
invalidStore
.
Watch
(
ctx
,
"/abc"
,
"0"
,
storage
.
Everything
)
if
err
!=
nil
{
t
.
Fatalf
(
"Watch failed: %v"
,
err
)
}
validStore
:=
newStore
(
cluster
.
RandClient
(),
testapi
.
Default
.
Codec
(),
""
)
validStore
:=
newStore
(
cluster
.
RandClient
(),
false
,
testapi
.
Default
.
Codec
(),
""
)
validStore
.
GuaranteedUpdate
(
ctx
,
"/abc"
,
&
api
.
Pod
{},
true
,
nil
,
storage
.
SimpleUpdate
(
func
(
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}},
nil
...
...
pkg/storage/storagebackend/factory/etcd3.go
View file @
81779360
...
...
@@ -55,5 +55,8 @@ func newETCD3Storage(c storagebackend.Config) (storage.Interface, DestroyFunc, e
cancel
()
client
.
Close
()
}
return
etcd3
.
New
(
client
,
c
.
Codec
,
c
.
Prefix
),
destroyFunc
,
nil
if
c
.
Quorum
{
return
etcd3
.
New
(
client
,
c
.
Codec
,
c
.
Prefix
),
destroyFunc
,
nil
}
return
etcd3
.
NewWithNoQuorumRead
(
client
,
c
.
Codec
,
c
.
Prefix
),
destroyFunc
,
nil
}
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