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
15701ff4
Commit
15701ff4
authored
Nov 12, 2014
by
derekwaynecarr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set uid during object create
parent
d4108ec4
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
106 additions
and
11 deletions
+106
-11
meta.go
pkg/api/meta.go
+33
-0
meta_test.go
pkg/api/meta_test.go
+48
-0
rest.go
pkg/registry/controller/rest.go
+1
-1
rest_test.go
pkg/registry/controller/rest_test.go
+3
-0
rest.go
pkg/registry/endpoint/rest.go
+3
-2
rest.go
pkg/registry/event/rest.go
+2
-2
rest_test.go
pkg/registry/event/rest_test.go
+3
-0
rest.go
pkg/registry/minion/rest.go
+1
-2
rest_test.go
pkg/registry/minion/rest_test.go
+3
-0
rest.go
pkg/registry/pod/rest.go
+2
-1
rest_test.go
pkg/registry/pod/rest_test.go
+3
-1
rest.go
pkg/registry/service/rest.go
+1
-2
rest_test.go
pkg/registry/service/rest_test.go
+3
-0
No files found.
pkg/api/meta.go
0 → 100644
View file @
15701ff4
/*
Copyright 2014 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
api
import
(
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)
// FillObjectMetaSystemFields populates fields that are managed by the system on ObjectMeta.
func
FillObjectMetaSystemFields
(
ctx
Context
,
meta
*
ObjectMeta
)
{
meta
.
CreationTimestamp
=
util
.
Now
()
meta
.
UID
=
util
.
NewUUID
()
.
String
()
}
// HasObjectMetaSystemFieldValues returns true if fields that are managed by the system on ObjectMeta have values.
func
HasObjectMetaSystemFieldValues
(
meta
*
ObjectMeta
)
bool
{
return
!
meta
.
CreationTimestamp
.
Time
.
IsZero
()
||
len
(
meta
.
UID
)
!=
0
}
pkg/api/meta_test.go
0 → 100644
View file @
15701ff4
/*
Copyright 2014 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
api_test
import
(
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)
// TestFillObjectMetaSystemFields validates that system populated fields are set on an object
func
TestFillObjectMetaSystemFields
(
t
*
testing
.
T
)
{
ctx
:=
api
.
NewDefaultContext
()
resource
:=
api
.
ObjectMeta
{}
api
.
FillObjectMetaSystemFields
(
ctx
,
&
resource
)
if
resource
.
CreationTimestamp
.
Time
.
IsZero
()
{
t
.
Errorf
(
"resource.CreationTimestamp is zero"
)
}
else
if
len
(
resource
.
UID
)
==
0
{
t
.
Errorf
(
"resource.UID missing"
)
}
}
// TestHasObjectMetaSystemFieldValues validates that true is returned if and only if all fields are populated
func
TestHasObjectMetaSystemFieldValues
(
t
*
testing
.
T
)
{
ctx
:=
api
.
NewDefaultContext
()
resource
:=
api
.
ObjectMeta
{}
if
api
.
HasObjectMetaSystemFieldValues
(
&
resource
)
{
t
.
Errorf
(
"the resource does not have all fields yet populated, but incorrectly reports it does"
)
}
api
.
FillObjectMetaSystemFields
(
ctx
,
&
resource
)
if
!
api
.
HasObjectMetaSystemFieldValues
(
&
resource
)
{
t
.
Errorf
(
"the resource does have all fields populated, but incorrectly reports it does not"
)
}
}
pkg/registry/controller/rest.go
View file @
15701ff4
...
@@ -68,7 +68,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
...
@@ -68,7 +68,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
return
nil
,
errors
.
NewInvalid
(
"replicationController"
,
controller
.
Name
,
errs
)
return
nil
,
errors
.
NewInvalid
(
"replicationController"
,
controller
.
Name
,
errs
)
}
}
controller
.
CreationTimestamp
=
util
.
Now
(
)
api
.
FillObjectMetaSystemFields
(
ctx
,
&
controller
.
ObjectMeta
)
return
apiserver
.
MakeAsync
(
func
()
(
runtime
.
Object
,
error
)
{
return
apiserver
.
MakeAsync
(
func
()
(
runtime
.
Object
,
error
)
{
err
:=
rs
.
registry
.
CreateController
(
ctx
,
controller
)
err
:=
rs
.
registry
.
CreateController
(
ctx
,
controller
)
...
...
pkg/registry/controller/rest_test.go
View file @
15701ff4
...
@@ -264,6 +264,9 @@ func TestCreateController(t *testing.T) {
...
@@ -264,6 +264,9 @@ func TestCreateController(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
if
!
api
.
HasObjectMetaSystemFieldValues
(
&
controller
.
ObjectMeta
)
{
t
.
Errorf
(
"storage did not populate object meta field values"
)
}
select
{
select
{
case
<-
channel
:
case
<-
channel
:
...
...
pkg/registry/endpoint/rest.go
View file @
15701ff4
...
@@ -24,7 +24,6 @@ import (
...
@@ -24,7 +24,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
)
...
@@ -68,7 +67,9 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
...
@@ -68,7 +67,9 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
if
len
(
endpoints
.
Name
)
==
0
{
if
len
(
endpoints
.
Name
)
==
0
{
return
nil
,
fmt
.
Errorf
(
"id is required: %#v"
,
obj
)
return
nil
,
fmt
.
Errorf
(
"id is required: %#v"
,
obj
)
}
}
endpoints
.
CreationTimestamp
=
util
.
Now
()
api
.
FillObjectMetaSystemFields
(
ctx
,
&
endpoints
.
ObjectMeta
)
return
apiserver
.
MakeAsync
(
func
()
(
runtime
.
Object
,
error
)
{
return
apiserver
.
MakeAsync
(
func
()
(
runtime
.
Object
,
error
)
{
err
:=
rs
.
registry
.
UpdateEndpoints
(
ctx
,
endpoints
)
err
:=
rs
.
registry
.
UpdateEndpoints
(
ctx
,
endpoints
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/registry/event/rest.go
View file @
15701ff4
...
@@ -24,7 +24,6 @@ import (
...
@@ -24,7 +24,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
)
...
@@ -46,7 +45,8 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
...
@@ -46,7 +45,8 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
if
!
ok
{
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"invalid object type"
)
return
nil
,
fmt
.
Errorf
(
"invalid object type"
)
}
}
event
.
CreationTimestamp
=
util
.
Now
()
api
.
FillObjectMetaSystemFields
(
ctx
,
&
event
.
ObjectMeta
)
return
apiserver
.
MakeAsync
(
func
()
(
runtime
.
Object
,
error
)
{
return
apiserver
.
MakeAsync
(
func
()
(
runtime
.
Object
,
error
)
{
err
:=
rs
.
registry
.
Create
(
ctx
,
event
.
Name
,
event
)
err
:=
rs
.
registry
.
Create
(
ctx
,
event
.
Name
,
event
)
...
...
pkg/registry/event/rest_test.go
View file @
15701ff4
...
@@ -48,6 +48,9 @@ func TestRESTCreate(t *testing.T) {
...
@@ -48,6 +48,9 @@ func TestRESTCreate(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error %v"
,
err
)
t
.
Fatalf
(
"Unexpected error %v"
,
err
)
}
}
if
!
api
.
HasObjectMetaSystemFieldValues
(
&
eventA
.
ObjectMeta
)
{
t
.
Errorf
(
"storage did not populate object meta field values"
)
}
if
e
,
a
:=
eventA
,
(
<-
c
)
.
Object
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
if
e
,
a
:=
eventA
,
(
<-
c
)
.
Object
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
t
.
Errorf
(
"diff: %s"
,
util
.
ObjectDiff
(
e
,
a
))
t
.
Errorf
(
"diff: %s"
,
util
.
ObjectDiff
(
e
,
a
))
}
}
...
...
pkg/registry/minion/rest.go
View file @
15701ff4
...
@@ -29,7 +29,6 @@ import (
...
@@ -29,7 +29,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/master/ports"
"github.com/GoogleCloudPlatform/kubernetes/pkg/master/ports"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)
)
// REST implements the RESTStorage interface, backed by a MinionRegistry.
// REST implements the RESTStorage interface, backed by a MinionRegistry.
...
@@ -57,7 +56,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
...
@@ -57,7 +56,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
return
nil
,
kerrors
.
NewInvalid
(
"minion"
,
minion
.
Name
,
errs
)
return
nil
,
kerrors
.
NewInvalid
(
"minion"
,
minion
.
Name
,
errs
)
}
}
minion
.
CreationTimestamp
=
util
.
Now
(
)
api
.
FillObjectMetaSystemFields
(
ctx
,
&
minion
.
ObjectMeta
)
return
apiserver
.
MakeAsync
(
func
()
(
runtime
.
Object
,
error
)
{
return
apiserver
.
MakeAsync
(
func
()
(
runtime
.
Object
,
error
)
{
err
:=
rs
.
registry
.
CreateMinion
(
ctx
,
minion
)
err
:=
rs
.
registry
.
CreateMinion
(
ctx
,
minion
)
...
...
pkg/registry/minion/rest_test.go
View file @
15701ff4
...
@@ -43,6 +43,9 @@ func TestMinionREST(t *testing.T) {
...
@@ -43,6 +43,9 @@ func TestMinionREST(t *testing.T) {
t
.
Errorf
(
"insert failed"
)
t
.
Errorf
(
"insert failed"
)
}
}
obj
:=
<-
c
obj
:=
<-
c
if
!
api
.
HasObjectMetaSystemFieldValues
(
&
obj
.
Object
.
(
*
api
.
Minion
)
.
ObjectMeta
)
{
t
.
Errorf
(
"storage did not populate object meta field values"
)
}
if
m
,
ok
:=
obj
.
Object
.
(
*
api
.
Minion
);
!
ok
||
m
.
Name
!=
"baz"
{
if
m
,
ok
:=
obj
.
Object
.
(
*
api
.
Minion
);
!
ok
||
m
.
Name
!=
"baz"
{
t
.
Errorf
(
"insert return value was weird: %#v"
,
obj
)
t
.
Errorf
(
"insert return value was weird: %#v"
,
obj
)
}
}
...
...
pkg/registry/pod/rest.go
View file @
15701ff4
...
@@ -100,7 +100,8 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
...
@@ -100,7 +100,8 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
if
errs
:=
validation
.
ValidatePod
(
pod
);
len
(
errs
)
>
0
{
if
errs
:=
validation
.
ValidatePod
(
pod
);
len
(
errs
)
>
0
{
return
nil
,
errors
.
NewInvalid
(
"pod"
,
pod
.
Name
,
errs
)
return
nil
,
errors
.
NewInvalid
(
"pod"
,
pod
.
Name
,
errs
)
}
}
pod
.
CreationTimestamp
=
util
.
Now
()
api
.
FillObjectMetaSystemFields
(
ctx
,
&
pod
.
ObjectMeta
)
return
apiserver
.
MakeAsync
(
func
()
(
runtime
.
Object
,
error
)
{
return
apiserver
.
MakeAsync
(
func
()
(
runtime
.
Object
,
error
)
{
if
err
:=
rs
.
registry
.
CreatePod
(
ctx
,
pod
);
err
!=
nil
{
if
err
:=
rs
.
registry
.
CreatePod
(
ctx
,
pod
);
err
!=
nil
{
...
...
pkg/registry/pod/rest_test.go
View file @
15701ff4
...
@@ -586,13 +586,15 @@ func TestCreatePod(t *testing.T) {
...
@@ -586,13 +586,15 @@ func TestCreatePod(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
select
{
select
{
case
<-
channel
:
case
<-
channel
:
// Do nothing, this is expected.
// Do nothing, this is expected.
case
<-
time
.
After
(
time
.
Millisecond
*
100
)
:
case
<-
time
.
After
(
time
.
Millisecond
*
100
)
:
t
.
Error
(
"Unexpected timeout on async channel"
)
t
.
Error
(
"Unexpected timeout on async channel"
)
}
}
if
!
api
.
HasObjectMetaSystemFieldValues
(
&
podRegistry
.
Pod
.
ObjectMeta
)
{
t
.
Errorf
(
"Expected ObjectMeta field values were populated"
)
}
}
}
type
FakePodInfoGetter
struct
{
type
FakePodInfoGetter
struct
{
...
...
pkg/registry/service/rest.go
View file @
15701ff4
...
@@ -31,7 +31,6 @@ import (
...
@@ -31,7 +31,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/minion"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/minion"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/golang/glog"
"github.com/golang/glog"
)
)
...
@@ -92,7 +91,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
...
@@ -92,7 +91,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
return
nil
,
errors
.
NewInvalid
(
"service"
,
service
.
Name
,
errs
)
return
nil
,
errors
.
NewInvalid
(
"service"
,
service
.
Name
,
errs
)
}
}
service
.
CreationTimestamp
=
util
.
Now
(
)
api
.
FillObjectMetaSystemFields
(
ctx
,
&
service
.
ObjectMeta
)
if
service
.
Spec
.
PortalIP
==
""
{
if
service
.
Spec
.
PortalIP
==
""
{
// Allocate next available.
// Allocate next available.
...
...
pkg/registry/service/rest_test.go
View file @
15701ff4
...
@@ -55,6 +55,9 @@ func TestServiceRegistryCreate(t *testing.T) {
...
@@ -55,6 +55,9 @@ func TestServiceRegistryCreate(t *testing.T) {
c
,
_
:=
storage
.
Create
(
ctx
,
svc
)
c
,
_
:=
storage
.
Create
(
ctx
,
svc
)
created_svc
:=
<-
c
created_svc
:=
<-
c
created_service
:=
created_svc
.
Object
.
(
*
api
.
Service
)
created_service
:=
created_svc
.
Object
.
(
*
api
.
Service
)
if
!
api
.
HasObjectMetaSystemFieldValues
(
&
created_service
.
ObjectMeta
)
{
t
.
Errorf
(
"storage did not populate object meta field values"
)
}
if
created_service
.
Name
!=
"foo"
{
if
created_service
.
Name
!=
"foo"
{
t
.
Errorf
(
"Expected foo, but got %v"
,
created_service
.
Name
)
t
.
Errorf
(
"Expected foo, but got %v"
,
created_service
.
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