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
858e515f
Commit
858e515f
authored
Aug 18, 2016
by
jianhuiz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ignore clusterName on create and update
parent
7be20b0d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
0 deletions
+59
-0
create.go
pkg/api/rest/create.go
+3
-0
resttest.go
pkg/api/rest/resttest/resttest.go
+53
-0
update.go
pkg/api/rest/update.go
+3
-0
No files found.
pkg/api/rest/create.go
View file @
858e515f
...
@@ -71,6 +71,9 @@ func BeforeCreate(strategy RESTCreateStrategy, ctx api.Context, obj runtime.Obje
...
@@ -71,6 +71,9 @@ func BeforeCreate(strategy RESTCreateStrategy, ctx api.Context, obj runtime.Obje
api
.
FillObjectMetaSystemFields
(
ctx
,
objectMeta
)
api
.
FillObjectMetaSystemFields
(
ctx
,
objectMeta
)
api
.
GenerateName
(
strategy
,
objectMeta
)
api
.
GenerateName
(
strategy
,
objectMeta
)
// ClusterName is ignored and should not be saved
objectMeta
.
ClusterName
=
""
if
errs
:=
strategy
.
Validate
(
ctx
,
obj
);
len
(
errs
)
>
0
{
if
errs
:=
strategy
.
Validate
(
ctx
,
obj
);
len
(
errs
)
>
0
{
return
errors
.
NewInvalid
(
kind
.
GroupKind
(),
objectMeta
.
Name
,
errs
)
return
errors
.
NewInvalid
(
kind
.
GroupKind
(),
objectMeta
.
Name
,
errs
)
}
}
...
...
pkg/api/rest/resttest/resttest.go
View file @
858e515f
...
@@ -159,6 +159,7 @@ func (t *Tester) TestCreate(valid runtime.Object, createFn CreateFunc, getFn Get
...
@@ -159,6 +159,7 @@ func (t *Tester) TestCreate(valid runtime.Object, createFn CreateFunc, getFn Get
}
}
t
.
testCreateInvokesValidation
(
invalid
...
)
t
.
testCreateInvokesValidation
(
invalid
...
)
t
.
testCreateValidatesNames
(
copyOrDie
(
valid
))
t
.
testCreateValidatesNames
(
copyOrDie
(
valid
))
t
.
testCreateIgnoreClusterName
(
copyOrDie
(
valid
))
}
}
// Test updating an object.
// Test updating an object.
...
@@ -174,6 +175,7 @@ func (t *Tester) TestUpdate(valid runtime.Object, createFn CreateFunc, getFn Get
...
@@ -174,6 +175,7 @@ func (t *Tester) TestUpdate(valid runtime.Object, createFn CreateFunc, getFn Get
t
.
testUpdateRetrievesOldObject
(
copyOrDie
(
valid
),
createFn
,
getFn
)
t
.
testUpdateRetrievesOldObject
(
copyOrDie
(
valid
),
createFn
,
getFn
)
t
.
testUpdatePropagatesUpdatedObjectError
(
copyOrDie
(
valid
),
createFn
,
getFn
)
t
.
testUpdatePropagatesUpdatedObjectError
(
copyOrDie
(
valid
),
createFn
,
getFn
)
t
.
testUpdateIgnoreGenerationUpdates
(
copyOrDie
(
valid
),
createFn
,
getFn
)
t
.
testUpdateIgnoreGenerationUpdates
(
copyOrDie
(
valid
),
createFn
,
getFn
)
t
.
testUpdateIgnoreClusterName
(
copyOrDie
(
valid
),
createFn
,
getFn
)
}
}
// Test deleting an object.
// Test deleting an object.
...
@@ -430,6 +432,22 @@ func (t *Tester) testCreateResetsUserData(valid runtime.Object) {
...
@@ -430,6 +432,22 @@ func (t *Tester) testCreateResetsUserData(valid runtime.Object) {
}
}
}
}
func
(
t
*
Tester
)
testCreateIgnoreClusterName
(
valid
runtime
.
Object
)
{
objectMeta
:=
t
.
getObjectMetaOrFail
(
valid
)
objectMeta
.
Name
=
t
.
namer
(
3
)
objectMeta
.
ClusterName
=
"clustername-to-ignore"
obj
,
err
:=
t
.
storage
.
(
rest
.
Creater
)
.
Create
(
t
.
TestContext
(),
copyOrDie
(
valid
))
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
defer
t
.
delete
(
t
.
TestContext
(),
obj
)
createdObjectMeta
:=
t
.
getObjectMetaOrFail
(
obj
)
if
len
(
createdObjectMeta
.
ClusterName
)
!=
0
{
t
.
Errorf
(
"Expected empty clusterName on created object, got '%v'"
,
createdObjectMeta
.
ClusterName
)
}
}
// =============================================================================
// =============================================================================
// Update tests.
// Update tests.
...
@@ -691,6 +709,41 @@ func (t *Tester) testUpdateRejectsMismatchedNamespace(obj runtime.Object, create
...
@@ -691,6 +709,41 @@ func (t *Tester) testUpdateRejectsMismatchedNamespace(obj runtime.Object, create
}
}
}
}
func
(
t
*
Tester
)
testUpdateIgnoreClusterName
(
obj
runtime
.
Object
,
createFn
CreateFunc
,
getFn
GetFunc
)
{
ctx
:=
t
.
TestContext
()
foo
:=
copyOrDie
(
obj
)
name
:=
t
.
namer
(
9
)
t
.
setObjectMeta
(
foo
,
name
)
if
err
:=
createFn
(
ctx
,
foo
);
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
storedFoo
,
err
:=
getFn
(
ctx
,
foo
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
older
:=
copyOrDie
(
storedFoo
)
olderMeta
:=
t
.
getObjectMetaOrFail
(
older
)
olderMeta
.
ClusterName
=
"clustername-to-ignore"
_
,
_
,
err
=
t
.
storage
.
(
rest
.
Updater
)
.
Update
(
t
.
TestContext
(),
olderMeta
.
Name
,
rest
.
DefaultUpdatedObjectInfo
(
older
,
api
.
Scheme
))
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
updatedFoo
,
err
:=
getFn
(
ctx
,
older
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
if
clusterName
:=
t
.
getObjectMetaOrFail
(
updatedFoo
)
.
ClusterName
;
len
(
clusterName
)
!=
0
{
t
.
Errorf
(
"Unexpected clusterName update: expected empty, got %v"
,
clusterName
)
}
}
// =============================================================================
// =============================================================================
// Deletion tests.
// Deletion tests.
...
...
pkg/api/rest/update.go
View file @
858e515f
...
@@ -95,6 +95,9 @@ func BeforeUpdate(strategy RESTUpdateStrategy, ctx api.Context, obj, old runtime
...
@@ -95,6 +95,9 @@ func BeforeUpdate(strategy RESTUpdateStrategy, ctx api.Context, obj, old runtime
strategy
.
PrepareForUpdate
(
ctx
,
obj
,
old
)
strategy
.
PrepareForUpdate
(
ctx
,
obj
,
old
)
// ClusterName is ignored and should not be saved
objectMeta
.
ClusterName
=
""
// Ensure some common fields, like UID, are validated for all resources.
// Ensure some common fields, like UID, are validated for all resources.
errs
,
err
:=
validateCommonFields
(
obj
,
old
)
errs
,
err
:=
validateCommonFields
(
obj
,
old
)
if
err
!=
nil
{
if
err
!=
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