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
92e2c2b3
Commit
92e2c2b3
authored
Dec 15, 2014
by
derekwaynecarr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated default function names, keyroot to keyrootfunc
parent
6353612f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
11 deletions
+12
-11
registry.go
pkg/registry/event/registry.go
+1
-1
etcd.go
pkg/registry/generic/etcd/etcd.go
+9
-8
etcd_test.go
pkg/registry/generic/etcd/etcd_test.go
+2
-2
No files found.
pkg/registry/event/registry.go
View file @
92e2c2b3
...
@@ -51,7 +51,7 @@ func NewEtcdRegistry(h tools.EtcdHelper, ttl uint64) generic.Registry {
...
@@ -51,7 +51,7 @@ func NewEtcdRegistry(h tools.EtcdHelper, ttl uint64) generic.Registry {
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
Event
{}
},
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
Event
{}
},
NewListFunc
:
func
()
runtime
.
Object
{
return
&
api
.
EventList
{}
},
NewListFunc
:
func
()
runtime
.
Object
{
return
&
api
.
EventList
{}
},
EndpointName
:
"events"
,
EndpointName
:
"events"
,
KeyRoot
:
func
(
ctx
api
.
Context
)
string
{
KeyRoot
Func
:
func
(
ctx
api
.
Context
)
string
{
return
"/registry/events"
return
"/registry/events"
},
},
KeyFunc
:
func
(
ctx
api
.
Context
,
id
string
)
(
string
,
error
)
{
KeyFunc
:
func
(
ctx
api
.
Context
,
id
string
)
(
string
,
error
)
{
...
...
pkg/registry/generic/etcd/etcd.go
View file @
92e2c2b3
...
@@ -42,7 +42,7 @@ type Etcd struct {
...
@@ -42,7 +42,7 @@ type Etcd struct {
EndpointName
string
EndpointName
string
// Used for listing/watching; should not include trailing "/"
// Used for listing/watching; should not include trailing "/"
KeyRoot
func
(
ctx
api
.
Context
)
string
KeyRoot
Func
func
(
ctx
api
.
Context
)
string
// Called for Create/Update/Get/Delete
// Called for Create/Update/Get/Delete
KeyFunc
func
(
ctx
api
.
Context
,
id
string
)
(
string
,
error
)
KeyFunc
func
(
ctx
api
.
Context
,
id
string
)
(
string
,
error
)
...
@@ -51,8 +51,8 @@ type Etcd struct {
...
@@ -51,8 +51,8 @@ type Etcd struct {
Helper
tools
.
EtcdHelper
Helper
tools
.
EtcdHelper
}
}
//
MakeEtcdListKey constructs etcd paths to resource directories enforcing namespace rules
//
NamespaceKeyRootFunc is the default function for constructing etcd paths to resource directories enforcing namespace rules.
func
MakeEtcdListKey
(
ctx
api
.
Context
,
prefix
string
)
string
{
func
NamespaceKeyRootFunc
(
ctx
api
.
Context
,
prefix
string
)
string
{
key
:=
prefix
key
:=
prefix
ns
,
ok
:=
api
.
NamespaceFrom
(
ctx
)
ns
,
ok
:=
api
.
NamespaceFrom
(
ctx
)
if
ok
&&
len
(
ns
)
>
0
{
if
ok
&&
len
(
ns
)
>
0
{
...
@@ -61,9 +61,10 @@ func MakeEtcdListKey(ctx api.Context, prefix string) string {
...
@@ -61,9 +61,10 @@ func MakeEtcdListKey(ctx api.Context, prefix string) string {
return
key
return
key
}
}
// MakeEtcdItemKey constructs etcd paths to a resource relative to prefix enforcing namespace rules. If no namespace is on context, it errors.
// NamespaceKeyFunc is the default function for constructing etcd paths to a resource relative to prefix enforcing namespace rules.
func
MakeEtcdItemKey
(
ctx
api
.
Context
,
prefix
string
,
id
string
)
(
string
,
error
)
{
// If no namespace is on context, it errors.
key
:=
MakeEtcdListKey
(
ctx
,
prefix
)
func
NamespaceKeyFunc
(
ctx
api
.
Context
,
prefix
string
,
id
string
)
(
string
,
error
)
{
key
:=
NamespaceKeyRootFunc
(
ctx
,
prefix
)
ns
,
ok
:=
api
.
NamespaceFrom
(
ctx
)
ns
,
ok
:=
api
.
NamespaceFrom
(
ctx
)
if
!
ok
||
len
(
ns
)
==
0
{
if
!
ok
||
len
(
ns
)
==
0
{
return
""
,
kubeerr
.
NewBadRequest
(
"Namespace parameter required."
)
return
""
,
kubeerr
.
NewBadRequest
(
"Namespace parameter required."
)
...
@@ -78,7 +79,7 @@ func MakeEtcdItemKey(ctx api.Context, prefix string, id string) (string, error)
...
@@ -78,7 +79,7 @@ func MakeEtcdItemKey(ctx api.Context, prefix string, id string) (string, error)
// List returns a list of all the items matching m.
// List returns a list of all the items matching m.
func
(
e
*
Etcd
)
List
(
ctx
api
.
Context
,
m
generic
.
Matcher
)
(
runtime
.
Object
,
error
)
{
func
(
e
*
Etcd
)
List
(
ctx
api
.
Context
,
m
generic
.
Matcher
)
(
runtime
.
Object
,
error
)
{
list
:=
e
.
NewListFunc
()
list
:=
e
.
NewListFunc
()
err
:=
e
.
Helper
.
ExtractToList
(
e
.
KeyRoot
(
ctx
),
list
)
err
:=
e
.
Helper
.
ExtractToList
(
e
.
KeyRoot
Func
(
ctx
),
list
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -137,7 +138,7 @@ func (e *Etcd) Watch(ctx api.Context, m generic.Matcher, resourceVersion string)
...
@@ -137,7 +138,7 @@ func (e *Etcd) Watch(ctx api.Context, m generic.Matcher, resourceVersion string)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
e
.
Helper
.
WatchList
(
e
.
KeyRoot
(
ctx
),
version
,
func
(
obj
runtime
.
Object
)
bool
{
return
e
.
Helper
.
WatchList
(
e
.
KeyRoot
Func
(
ctx
),
version
,
func
(
obj
runtime
.
Object
)
bool
{
matches
,
err
:=
m
.
Matches
(
obj
)
matches
,
err
:=
m
.
Matches
(
obj
)
return
err
==
nil
&&
matches
return
err
==
nil
&&
matches
})
})
...
...
pkg/registry/generic/etcd/etcd_test.go
View file @
92e2c2b3
...
@@ -41,7 +41,7 @@ func NewTestGenericEtcdRegistry(t *testing.T) (*tools.FakeEtcdClient, *Etcd) {
...
@@ -41,7 +41,7 @@ func NewTestGenericEtcdRegistry(t *testing.T) (*tools.FakeEtcdClient, *Etcd) {
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
Pod
{}
},
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
Pod
{}
},
NewListFunc
:
func
()
runtime
.
Object
{
return
&
api
.
PodList
{}
},
NewListFunc
:
func
()
runtime
.
Object
{
return
&
api
.
PodList
{}
},
EndpointName
:
"pods"
,
EndpointName
:
"pods"
,
KeyRoot
:
func
(
ctx
api
.
Context
)
string
{
return
"/registry/pods"
},
KeyRoot
Func
:
func
(
ctx
api
.
Context
)
string
{
return
"/registry/pods"
},
KeyFunc
:
func
(
ctx
api
.
Context
,
id
string
)
(
string
,
error
)
{
KeyFunc
:
func
(
ctx
api
.
Context
,
id
string
)
(
string
,
error
)
{
return
path
.
Join
(
"/registry/pods"
,
id
),
nil
return
path
.
Join
(
"/registry/pods"
,
id
),
nil
},
},
...
@@ -139,7 +139,7 @@ func TestEtcdList(t *testing.T) {
...
@@ -139,7 +139,7 @@ func TestEtcdList(t *testing.T) {
for
name
,
item
:=
range
table
{
for
name
,
item
:=
range
table
{
fakeClient
,
registry
:=
NewTestGenericEtcdRegistry
(
t
)
fakeClient
,
registry
:=
NewTestGenericEtcdRegistry
(
t
)
fakeClient
.
Data
[
registry
.
KeyRoot
(
api
.
NewContext
())]
=
item
.
in
fakeClient
.
Data
[
registry
.
KeyRoot
Func
(
api
.
NewContext
())]
=
item
.
in
list
,
err
:=
registry
.
List
(
api
.
NewContext
(),
item
.
m
)
list
,
err
:=
registry
.
List
(
api
.
NewContext
(),
item
.
m
)
if
e
,
a
:=
item
.
succeed
,
err
==
nil
;
e
!=
a
{
if
e
,
a
:=
item
.
succeed
,
err
==
nil
;
e
!=
a
{
t
.
Errorf
(
"%v: expected %v, got %v"
,
name
,
e
,
a
)
t
.
Errorf
(
"%v: expected %v, got %v"
,
name
,
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