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
8440310e
Commit
8440310e
authored
Feb 11, 2015
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adapt to changes to generic etcd/registry
parent
23d199de
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
24 additions
and
45 deletions
+24
-45
registry.go
pkg/registry/event/registry.go
+3
-24
registry_test.go
pkg/registry/event/registry_test.go
+2
-2
rest.go
pkg/registry/event/rest.go
+5
-5
registry_test.go
pkg/registry/limitrange/registry_test.go
+1
-1
rest.go
pkg/registry/limitrange/rest.go
+3
-3
rest.go
pkg/registry/namespace/rest.go
+5
-5
registry.go
pkg/registry/resourcequota/registry.go
+1
-1
registry_test.go
pkg/registry/resourcequota/registry_test.go
+1
-1
rest.go
pkg/registry/resourcequota/rest.go
+3
-3
No files found.
pkg/registry/event/registry.go
View file @
8440310e
...
@@ -18,7 +18,6 @@ package event
...
@@ -18,7 +18,6 @@ package event
import
(
import
(
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
etcderr
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors/etcd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
etcdgeneric
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic/etcd"
etcdgeneric
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic/etcd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
...
@@ -28,28 +27,6 @@ import (
...
@@ -28,28 +27,6 @@ import (
// registry implements custom changes to generic.Etcd.
// registry implements custom changes to generic.Etcd.
type
registry
struct
{
type
registry
struct
{
*
etcdgeneric
.
Etcd
*
etcdgeneric
.
Etcd
ttl
uint64
}
// Create stores the object with a ttl, so that events don't stay in the system forever.
func
(
r
registry
)
Create
(
ctx
api
.
Context
,
id
string
,
obj
runtime
.
Object
)
error
{
key
,
err
:=
r
.
Etcd
.
KeyFunc
(
ctx
,
id
)
if
err
!=
nil
{
return
err
}
err
=
r
.
Etcd
.
Helper
.
CreateObj
(
key
,
obj
,
r
.
ttl
)
return
etcderr
.
InterpretCreateError
(
err
,
r
.
Etcd
.
EndpointName
,
id
)
}
// Update replaces an existing instance of the object, and sets a ttl so that the event
// doesn't stay in the system forever.
func
(
r
registry
)
Update
(
ctx
api
.
Context
,
id
string
,
obj
runtime
.
Object
)
error
{
key
,
err
:=
r
.
Etcd
.
KeyFunc
(
ctx
,
id
)
if
err
!=
nil
{
return
err
}
err
=
r
.
Etcd
.
Helper
.
SetObj
(
key
,
obj
,
r
.
ttl
)
return
etcderr
.
InterpretUpdateError
(
err
,
r
.
Etcd
.
EndpointName
,
id
)
}
}
// NewEtcdRegistry returns a registry which will store Events in the given
// NewEtcdRegistry returns a registry which will store Events in the given
...
@@ -66,8 +43,10 @@ func NewEtcdRegistry(h tools.EtcdHelper, ttl uint64) generic.Registry {
...
@@ -66,8 +43,10 @@ func NewEtcdRegistry(h tools.EtcdHelper, ttl uint64) generic.Registry {
KeyFunc
:
func
(
ctx
api
.
Context
,
id
string
)
(
string
,
error
)
{
KeyFunc
:
func
(
ctx
api
.
Context
,
id
string
)
(
string
,
error
)
{
return
etcdgeneric
.
NamespaceKeyFunc
(
ctx
,
"/registry/events"
,
id
)
return
etcdgeneric
.
NamespaceKeyFunc
(
ctx
,
"/registry/events"
,
id
)
},
},
TTLFunc
:
func
(
runtime
.
Object
,
bool
)
(
uint64
,
error
)
{
return
ttl
,
nil
},
Helper
:
h
,
Helper
:
h
,
},
},
ttl
:
ttl
,
}
}
}
}
pkg/registry/event/registry_test.go
View file @
8440310e
...
@@ -98,7 +98,7 @@ func TestEventCreate(t *testing.T) {
...
@@ -98,7 +98,7 @@ func TestEventCreate(t *testing.T) {
for
name
,
item
:=
range
table
{
for
name
,
item
:=
range
table
{
fakeClient
,
registry
:=
NewTestEventEtcdRegistry
(
t
)
fakeClient
,
registry
:=
NewTestEventEtcdRegistry
(
t
)
fakeClient
.
Data
[
path
]
=
item
.
existing
fakeClient
.
Data
[
path
]
=
item
.
existing
err
:=
registry
.
Create
(
ctx
,
key
,
item
.
toCreate
)
err
:=
registry
.
Create
WithName
(
ctx
,
key
,
item
.
toCreate
)
if
!
item
.
errOK
(
err
)
{
if
!
item
.
errOK
(
err
)
{
t
.
Errorf
(
"%v: unexpected error: %v"
,
name
,
err
)
t
.
Errorf
(
"%v: unexpected error: %v"
,
name
,
err
)
}
}
...
@@ -200,7 +200,7 @@ func TestEventUpdate(t *testing.T) {
...
@@ -200,7 +200,7 @@ func TestEventUpdate(t *testing.T) {
for
name
,
item
:=
range
table
{
for
name
,
item
:=
range
table
{
fakeClient
,
registry
:=
NewTestEventEtcdRegistry
(
t
)
fakeClient
,
registry
:=
NewTestEventEtcdRegistry
(
t
)
fakeClient
.
Data
[
path
]
=
item
.
existing
fakeClient
.
Data
[
path
]
=
item
.
existing
err
:=
registry
.
Update
(
ctx
,
key
,
item
.
toUpdate
)
err
:=
registry
.
Update
WithName
(
ctx
,
key
,
item
.
toUpdate
)
if
!
item
.
errOK
(
err
)
{
if
!
item
.
errOK
(
err
)
{
t
.
Errorf
(
"%v: unexpected error: %v"
,
name
,
err
)
t
.
Errorf
(
"%v: unexpected error: %v"
,
name
,
err
)
}
}
...
...
pkg/registry/event/rest.go
View file @
8440310e
...
@@ -56,7 +56,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
...
@@ -56,7 +56,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
}
}
api
.
FillObjectMetaSystemFields
(
ctx
,
&
event
.
ObjectMeta
)
api
.
FillObjectMetaSystemFields
(
ctx
,
&
event
.
ObjectMeta
)
err
:=
rs
.
registry
.
Create
(
ctx
,
event
.
Name
,
event
)
err
:=
rs
.
registry
.
Create
WithName
(
ctx
,
event
.
Name
,
event
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -79,7 +79,7 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
...
@@ -79,7 +79,7 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
}
}
api
.
FillObjectMetaSystemFields
(
ctx
,
&
event
.
ObjectMeta
)
api
.
FillObjectMetaSystemFields
(
ctx
,
&
event
.
ObjectMeta
)
err
:=
rs
.
registry
.
Update
(
ctx
,
event
.
Name
,
event
)
err
:=
rs
.
registry
.
Update
WithName
(
ctx
,
event
.
Name
,
event
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
false
,
err
return
nil
,
false
,
err
}
}
...
@@ -87,8 +87,8 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
...
@@ -87,8 +87,8 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
return
out
,
false
,
err
return
out
,
false
,
err
}
}
func
(
rs
*
REST
)
Delete
(
ctx
api
.
Context
,
id
string
)
(
runtime
.
Object
,
error
)
{
func
(
rs
*
REST
)
Delete
(
ctx
api
.
Context
,
name
string
)
(
runtime
.
Object
,
error
)
{
obj
,
err
:=
rs
.
registry
.
Get
(
ctx
,
id
)
obj
,
err
:=
rs
.
registry
.
Get
(
ctx
,
name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -96,7 +96,7 @@ func (rs *REST) Delete(ctx api.Context, id string) (runtime.Object, error) {
...
@@ -96,7 +96,7 @@ func (rs *REST) Delete(ctx api.Context, id string) (runtime.Object, error) {
if
!
ok
{
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"invalid object type"
)
return
nil
,
fmt
.
Errorf
(
"invalid object type"
)
}
}
return
&
api
.
Status
{
Status
:
api
.
StatusSuccess
},
rs
.
registry
.
Delete
(
ctx
,
id
)
return
rs
.
registry
.
Delete
(
ctx
,
name
)
}
}
func
(
rs
*
REST
)
Get
(
ctx
api
.
Context
,
id
string
)
(
runtime
.
Object
,
error
)
{
func
(
rs
*
REST
)
Get
(
ctx
api
.
Context
,
id
string
)
(
runtime
.
Object
,
error
)
{
...
...
pkg/registry/limitrange/registry_test.go
View file @
8440310e
...
@@ -109,7 +109,7 @@ func TestLimitRangeCreate(t *testing.T) {
...
@@ -109,7 +109,7 @@ func TestLimitRangeCreate(t *testing.T) {
for
name
,
item
:=
range
table
{
for
name
,
item
:=
range
table
{
fakeClient
,
registry
:=
NewTestLimitRangeEtcdRegistry
(
t
)
fakeClient
,
registry
:=
NewTestLimitRangeEtcdRegistry
(
t
)
fakeClient
.
Data
[
path
]
=
item
.
existing
fakeClient
.
Data
[
path
]
=
item
.
existing
err
:=
registry
.
Create
(
ctx
,
key
,
item
.
toCreate
)
err
:=
registry
.
Create
WithName
(
ctx
,
key
,
item
.
toCreate
)
if
!
item
.
errOK
(
err
)
{
if
!
item
.
errOK
(
err
)
{
t
.
Errorf
(
"%v: unexpected error: %v"
,
name
,
err
)
t
.
Errorf
(
"%v: unexpected error: %v"
,
name
,
err
)
}
}
...
...
pkg/registry/limitrange/rest.go
View file @
8440310e
...
@@ -62,7 +62,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
...
@@ -62,7 +62,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
}
}
api
.
FillObjectMetaSystemFields
(
ctx
,
&
limitRange
.
ObjectMeta
)
api
.
FillObjectMetaSystemFields
(
ctx
,
&
limitRange
.
ObjectMeta
)
err
:=
rs
.
registry
.
Create
(
ctx
,
limitRange
.
Name
,
limitRange
)
err
:=
rs
.
registry
.
Create
WithName
(
ctx
,
limitRange
.
Name
,
limitRange
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -97,7 +97,7 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
...
@@ -97,7 +97,7 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
return
nil
,
false
,
errors
.
NewInvalid
(
"limitRange"
,
editLimitRange
.
Name
,
errs
)
return
nil
,
false
,
errors
.
NewInvalid
(
"limitRange"
,
editLimitRange
.
Name
,
errs
)
}
}
if
err
:=
rs
.
registry
.
Update
(
ctx
,
editLimitRange
.
Name
,
editLimitRange
);
err
!=
nil
{
if
err
:=
rs
.
registry
.
Update
WithName
(
ctx
,
editLimitRange
.
Name
,
editLimitRange
);
err
!=
nil
{
return
nil
,
false
,
err
return
nil
,
false
,
err
}
}
out
,
err
:=
rs
.
registry
.
Get
(
ctx
,
editLimitRange
.
Name
)
out
,
err
:=
rs
.
registry
.
Get
(
ctx
,
editLimitRange
.
Name
)
...
@@ -114,7 +114,7 @@ func (rs *REST) Delete(ctx api.Context, name string) (runtime.Object, error) {
...
@@ -114,7 +114,7 @@ func (rs *REST) Delete(ctx api.Context, name string) (runtime.Object, error) {
if
!
ok
{
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"invalid object type"
)
return
nil
,
fmt
.
Errorf
(
"invalid object type"
)
}
}
return
&
api
.
Status
{
Status
:
api
.
StatusSuccess
},
rs
.
registry
.
Delete
(
ctx
,
name
)
return
rs
.
registry
.
Delete
(
ctx
,
name
)
}
}
// Get gets a LimitRange with the specified name
// Get gets a LimitRange with the specified name
...
...
pkg/registry/namespace/rest.go
View file @
8440310e
...
@@ -48,7 +48,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
...
@@ -48,7 +48,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
if
err
:=
rest
.
BeforeCreate
(
rest
.
Namespaces
,
ctx
,
obj
);
err
!=
nil
{
if
err
:=
rest
.
BeforeCreate
(
rest
.
Namespaces
,
ctx
,
obj
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
err
:=
rs
.
registry
.
Create
(
ctx
,
namespace
.
Name
,
namespace
);
err
!=
nil
{
if
err
:=
rs
.
registry
.
Create
WithName
(
ctx
,
namespace
.
Name
,
namespace
);
err
!=
nil
{
err
=
rest
.
CheckGeneratedNameError
(
rest
.
Namespaces
,
err
,
namespace
)
err
=
rest
.
CheckGeneratedNameError
(
rest
.
Namespaces
,
err
,
namespace
)
return
nil
,
err
return
nil
,
err
}
}
...
@@ -72,7 +72,7 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
...
@@ -72,7 +72,7 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
return
nil
,
false
,
kerrors
.
NewInvalid
(
"namespace"
,
namespace
.
Name
,
errs
)
return
nil
,
false
,
kerrors
.
NewInvalid
(
"namespace"
,
namespace
.
Name
,
errs
)
}
}
if
err
:=
rs
.
registry
.
Update
(
ctx
,
oldNamespace
.
Name
,
oldNamespace
);
err
!=
nil
{
if
err
:=
rs
.
registry
.
Update
WithName
(
ctx
,
oldNamespace
.
Name
,
oldNamespace
);
err
!=
nil
{
return
nil
,
false
,
err
return
nil
,
false
,
err
}
}
out
,
err
:=
rs
.
registry
.
Get
(
ctx
,
oldNamespace
.
Name
)
out
,
err
:=
rs
.
registry
.
Get
(
ctx
,
oldNamespace
.
Name
)
...
@@ -80,8 +80,8 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
...
@@ -80,8 +80,8 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
}
}
// Delete deletes the Namespace with the specified name
// Delete deletes the Namespace with the specified name
func
(
rs
*
REST
)
Delete
(
ctx
api
.
Context
,
id
string
)
(
runtime
.
Object
,
error
)
{
func
(
rs
*
REST
)
Delete
(
ctx
api
.
Context
,
name
string
)
(
runtime
.
Object
,
error
)
{
obj
,
err
:=
rs
.
registry
.
Get
(
ctx
,
id
)
obj
,
err
:=
rs
.
registry
.
Get
(
ctx
,
name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -89,7 +89,7 @@ func (rs *REST) Delete(ctx api.Context, id string) (runtime.Object, error) {
...
@@ -89,7 +89,7 @@ func (rs *REST) Delete(ctx api.Context, id string) (runtime.Object, error) {
if
!
ok
{
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"invalid object type"
)
return
nil
,
fmt
.
Errorf
(
"invalid object type"
)
}
}
return
&
api
.
Status
{
Status
:
api
.
StatusSuccess
},
rs
.
registry
.
Delete
(
ctx
,
id
)
return
rs
.
registry
.
Delete
(
ctx
,
name
)
}
}
func
(
rs
*
REST
)
Get
(
ctx
api
.
Context
,
id
string
)
(
runtime
.
Object
,
error
)
{
func
(
rs
*
REST
)
Get
(
ctx
api
.
Context
,
id
string
)
(
runtime
.
Object
,
error
)
{
...
...
pkg/registry/resourcequota/registry.go
View file @
8440310e
...
@@ -53,7 +53,7 @@ func (r *registry) ApplyStatus(ctx api.Context, usage *api.ResourceQuotaUsage) e
...
@@ -53,7 +53,7 @@ func (r *registry) ApplyStatus(ctx api.Context, usage *api.ResourceQuotaUsage) e
resourceQuota
:=
obj
.
(
*
api
.
ResourceQuota
)
resourceQuota
:=
obj
.
(
*
api
.
ResourceQuota
)
resourceQuota
.
ResourceVersion
=
usage
.
ResourceVersion
resourceQuota
.
ResourceVersion
=
usage
.
ResourceVersion
resourceQuota
.
Status
=
usage
.
Status
resourceQuota
.
Status
=
usage
.
Status
return
r
.
Update
(
ctx
,
resourceQuota
.
Name
,
resourceQuota
)
return
r
.
Update
WithName
(
ctx
,
resourceQuota
.
Name
,
resourceQuota
)
}
}
// NewEtcdRegistry returns a registry which will store ResourceQuota in the given helper
// NewEtcdRegistry returns a registry which will store ResourceQuota in the given helper
...
...
pkg/registry/resourcequota/registry_test.go
View file @
8440310e
...
@@ -104,7 +104,7 @@ func TestResourceQuotaCreate(t *testing.T) {
...
@@ -104,7 +104,7 @@ func TestResourceQuotaCreate(t *testing.T) {
for
name
,
item
:=
range
table
{
for
name
,
item
:=
range
table
{
fakeClient
,
registry
:=
NewTestLimitRangeEtcdRegistry
(
t
)
fakeClient
,
registry
:=
NewTestLimitRangeEtcdRegistry
(
t
)
fakeClient
.
Data
[
path
]
=
item
.
existing
fakeClient
.
Data
[
path
]
=
item
.
existing
err
:=
registry
.
Create
(
ctx
,
key
,
item
.
toCreate
)
err
:=
registry
.
Create
WithName
(
ctx
,
key
,
item
.
toCreate
)
if
!
item
.
errOK
(
err
)
{
if
!
item
.
errOK
(
err
)
{
t
.
Errorf
(
"%v: unexpected error: %v, %v"
,
name
,
err
,
path
)
t
.
Errorf
(
"%v: unexpected error: %v, %v"
,
name
,
err
,
path
)
}
}
...
...
pkg/registry/resourcequota/rest.go
View file @
8440310e
...
@@ -65,7 +65,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
...
@@ -65,7 +65,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
}
}
api
.
FillObjectMetaSystemFields
(
ctx
,
&
resourceQuota
.
ObjectMeta
)
api
.
FillObjectMetaSystemFields
(
ctx
,
&
resourceQuota
.
ObjectMeta
)
err
:=
rs
.
registry
.
Create
(
ctx
,
resourceQuota
.
Name
,
resourceQuota
)
err
:=
rs
.
registry
.
Create
WithName
(
ctx
,
resourceQuota
.
Name
,
resourceQuota
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -100,7 +100,7 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
...
@@ -100,7 +100,7 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
return
nil
,
false
,
errors
.
NewInvalid
(
"resourceQuota"
,
editResourceQuota
.
Name
,
errs
)
return
nil
,
false
,
errors
.
NewInvalid
(
"resourceQuota"
,
editResourceQuota
.
Name
,
errs
)
}
}
if
err
:=
rs
.
registry
.
Update
(
ctx
,
editResourceQuota
.
Name
,
editResourceQuota
);
err
!=
nil
{
if
err
:=
rs
.
registry
.
Update
WithName
(
ctx
,
editResourceQuota
.
Name
,
editResourceQuota
);
err
!=
nil
{
return
nil
,
false
,
err
return
nil
,
false
,
err
}
}
out
,
err
:=
rs
.
registry
.
Get
(
ctx
,
editResourceQuota
.
Name
)
out
,
err
:=
rs
.
registry
.
Get
(
ctx
,
editResourceQuota
.
Name
)
...
@@ -117,7 +117,7 @@ func (rs *REST) Delete(ctx api.Context, name string) (runtime.Object, error) {
...
@@ -117,7 +117,7 @@ func (rs *REST) Delete(ctx api.Context, name string) (runtime.Object, error) {
if
!
ok
{
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"invalid object type"
)
return
nil
,
fmt
.
Errorf
(
"invalid object type"
)
}
}
return
&
api
.
Status
{
Status
:
api
.
StatusSuccess
},
rs
.
registry
.
Delete
(
ctx
,
name
)
return
rs
.
registry
.
Delete
(
ctx
,
name
)
}
}
// Get gets a ResourceQuota with the specified name
// Get gets a ResourceQuota with the specified name
...
...
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