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
51d9bb1f
Commit
51d9bb1f
authored
Nov 07, 2016
by
Hongchao Deng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
etcd3: have prefix to always prepended
parent
81177226
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
15 deletions
+8
-15
etcd.go
pkg/genericapiserver/options/etcd.go
+1
-1
store.go
pkg/storage/etcd3/store.go
+7
-14
No files found.
pkg/genericapiserver/options/etcd.go
View file @
51d9bb1f
...
...
@@ -70,7 +70,7 @@ func (s *EtcdOptions) AddFlags(fs *pflag.FlagSet) {
"List of etcd servers to connect with (scheme://ip:port), comma separated."
)
fs
.
StringVar
(
&
s
.
StorageConfig
.
Prefix
,
"etcd-prefix"
,
s
.
StorageConfig
.
Prefix
,
"The prefix
for
all resource paths in etcd."
)
"The prefix
to prepend to
all resource paths in etcd."
)
fs
.
StringVar
(
&
s
.
StorageConfig
.
KeyFile
,
"etcd-keyfile"
,
s
.
StorageConfig
.
KeyFile
,
"SSL key file used to secure etcd communication."
)
...
...
pkg/storage/etcd3/store.go
View file @
51d9bb1f
...
...
@@ -97,7 +97,7 @@ func (s *store) Versioner() storage.Versioner {
// Get implements storage.Interface.Get.
func
(
s
*
store
)
Get
(
ctx
context
.
Context
,
key
string
,
resourceVersion
string
,
out
runtime
.
Object
,
ignoreNotFound
bool
)
error
{
key
=
keyWithPrefix
(
s
.
pathPrefix
,
key
)
key
=
path
.
Join
(
s
.
pathPrefix
,
key
)
getResp
,
err
:=
s
.
client
.
KV
.
Get
(
ctx
,
key
,
s
.
getOps
...
)
if
err
!=
nil
{
return
err
...
...
@@ -122,7 +122,7 @@ func (s *store) Create(ctx context.Context, key string, obj, out runtime.Object,
if
err
!=
nil
{
return
err
}
key
=
keyWithPrefix
(
s
.
pathPrefix
,
key
)
key
=
path
.
Join
(
s
.
pathPrefix
,
key
)
opts
,
err
:=
s
.
ttlOpts
(
ctx
,
int64
(
ttl
))
if
err
!=
nil
{
...
...
@@ -154,7 +154,7 @@ func (s *store) Delete(ctx context.Context, key string, out runtime.Object, prec
if
err
!=
nil
{
panic
(
"unable to convert output object to pointer"
)
}
key
=
keyWithPrefix
(
s
.
pathPrefix
,
key
)
key
=
path
.
Join
(
s
.
pathPrefix
,
key
)
if
precondtions
==
nil
{
return
s
.
unconditionalDelete
(
ctx
,
key
,
out
)
}
...
...
@@ -223,7 +223,7 @@ func (s *store) GuaranteedUpdate(
if
err
!=
nil
{
panic
(
"unable to convert output object to pointer"
)
}
key
=
keyWithPrefix
(
s
.
pathPrefix
,
key
)
key
=
path
.
Join
(
s
.
pathPrefix
,
key
)
var
origState
*
objState
if
len
(
suggestion
)
==
1
&&
suggestion
[
0
]
!=
nil
{
...
...
@@ -299,7 +299,7 @@ func (s *store) GetToList(ctx context.Context, key string, resourceVersion strin
if
err
!=
nil
{
return
err
}
key
=
keyWithPrefix
(
s
.
pathPrefix
,
key
)
key
=
path
.
Join
(
s
.
pathPrefix
,
key
)
getResp
,
err
:=
s
.
client
.
KV
.
Get
(
ctx
,
key
,
s
.
getOps
...
)
if
err
!=
nil
{
...
...
@@ -325,7 +325,7 @@ func (s *store) List(ctx context.Context, key, resourceVersion string, pred stor
if
err
!=
nil
{
return
err
}
key
=
keyWithPrefix
(
s
.
pathPrefix
,
key
)
key
=
path
.
Join
(
s
.
pathPrefix
,
key
)
// We need to make sure the key ended with "/" so that we only get children "directories".
// e.g. if we have key "/a", "/a/b", "/ab", getting keys with prefix "/a" will return all three,
// while with prefix "/a/" will return only "/a/b" which is the correct answer.
...
...
@@ -366,7 +366,7 @@ func (s *store) watch(ctx context.Context, key string, rv string, pred storage.S
if
err
!=
nil
{
return
nil
,
err
}
key
=
keyWithPrefix
(
s
.
pathPrefix
,
key
)
key
=
path
.
Join
(
s
.
pathPrefix
,
key
)
return
s
.
watcher
.
Watch
(
ctx
,
key
,
int64
(
rev
),
recursive
,
pred
)
}
...
...
@@ -457,13 +457,6 @@ func (s *store) ttlOpts(ctx context.Context, ttl int64) ([]clientv3.OpOption, er
return
[]
clientv3
.
OpOption
{
clientv3
.
WithLease
(
clientv3
.
LeaseID
(
lcr
.
ID
))},
nil
}
func
keyWithPrefix
(
prefix
,
key
string
)
string
{
if
strings
.
HasPrefix
(
key
,
prefix
)
{
return
key
}
return
path
.
Join
(
prefix
,
key
)
}
// decode decodes value of bytes into object. It will also set the object resource version to rev.
// On success, objPtr would be set to the object.
func
decode
(
codec
runtime
.
Codec
,
versioner
storage
.
Versioner
,
value
[]
byte
,
objPtr
runtime
.
Object
,
rev
int64
)
error
{
...
...
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