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
d7c5f427
Commit
d7c5f427
authored
Mar 30, 2015
by
Andy Goldstein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass ctx to Validate, ValidateUpdate
Pass ctx to Validate/ValidateUpdate. This is useful so strategies can access data such as the current user.
parent
d5ce931f
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
25 additions
and
25 deletions
+25
-25
create.go
pkg/api/rest/create.go
+2
-2
types.go
pkg/api/rest/types.go
+2
-2
update.go
pkg/api/rest/update.go
+2
-2
rest.go
pkg/registry/controller/rest.go
+3
-3
rest.go
pkg/registry/endpoint/rest.go
+2
-2
etcd_test.go
pkg/registry/generic/etcd/etcd_test.go
+2
-2
rest.go
pkg/registry/minion/rest.go
+2
-2
rest.go
pkg/registry/namespace/rest.go
+4
-4
rest.go
pkg/registry/pod/rest.go
+3
-3
rest.go
pkg/registry/resourcequota/rest.go
+3
-3
No files found.
pkg/api/rest/create.go
View file @
d7c5f427
...
...
@@ -40,7 +40,7 @@ type RESTCreateStrategy interface {
PrepareForCreate
(
obj
runtime
.
Object
)
// Validate is invoked after default fields in the object have been filled in before
// the object is persisted.
Validate
(
obj
runtime
.
Object
)
fielderrors
.
ValidationErrorList
Validate
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
fielderrors
.
ValidationErrorList
}
// BeforeCreate ensures that common operations for all resources are performed on creation. It only returns
...
...
@@ -63,7 +63,7 @@ func BeforeCreate(strategy RESTCreateStrategy, ctx api.Context, obj runtime.Obje
api
.
FillObjectMetaSystemFields
(
ctx
,
objectMeta
)
api
.
GenerateName
(
strategy
,
objectMeta
)
if
errs
:=
strategy
.
Validate
(
obj
);
len
(
errs
)
>
0
{
if
errs
:=
strategy
.
Validate
(
ctx
,
obj
);
len
(
errs
)
>
0
{
return
errors
.
NewInvalid
(
kind
,
objectMeta
.
Name
,
errs
)
}
return
nil
...
...
pkg/api/rest/types.go
View file @
d7c5f427
...
...
@@ -75,7 +75,7 @@ func (svcStrategy) PrepareForUpdate(obj, old runtime.Object) {
}
// Validate validates a new service.
func
(
svcStrategy
)
Validate
(
obj
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
func
(
svcStrategy
)
Validate
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
service
:=
obj
.
(
*
api
.
Service
)
return
validation
.
ValidateService
(
service
)
}
...
...
@@ -84,6 +84,6 @@ func (svcStrategy) AllowCreateOnUpdate() bool {
return
true
}
func
(
svcStrategy
)
ValidateUpdate
(
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
func
(
svcStrategy
)
ValidateUpdate
(
ctx
api
.
Context
,
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
return
validation
.
ValidateServiceUpdate
(
old
.
(
*
api
.
Service
),
obj
.
(
*
api
.
Service
))
}
pkg/api/rest/update.go
View file @
d7c5f427
...
...
@@ -39,7 +39,7 @@ type RESTUpdateStrategy interface {
PrepareForUpdate
(
obj
,
old
runtime
.
Object
)
// ValidateUpdate is invoked after default fields in the object have been filled in before
// the object is persisted.
ValidateUpdate
(
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
ValidateUpdate
(
ctx
api
.
Context
,
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
}
// BeforeUpdate ensures that common operations for all resources are performed on update. It only returns
...
...
@@ -58,7 +58,7 @@ func BeforeUpdate(strategy RESTUpdateStrategy, ctx api.Context, obj, old runtime
objectMeta
.
Namespace
=
api
.
NamespaceNone
}
strategy
.
PrepareForUpdate
(
obj
,
old
)
if
errs
:=
strategy
.
ValidateUpdate
(
obj
,
old
);
len
(
errs
)
>
0
{
if
errs
:=
strategy
.
ValidateUpdate
(
ctx
,
obj
,
old
);
len
(
errs
)
>
0
{
return
errors
.
NewInvalid
(
kind
,
objectMeta
.
Name
,
errs
)
}
return
nil
...
...
pkg/registry/controller/rest.go
View file @
d7c5f427
...
...
@@ -18,6 +18,7 @@ package controller
import
(
"fmt"
"strconv"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
...
...
@@ -26,7 +27,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/fielderrors"
"strconv"
)
// rcStrategy implements verification logic for Replication Controllers.
...
...
@@ -58,7 +58,7 @@ func (rcStrategy) PrepareForUpdate(obj, old runtime.Object) {
}
// Validate validates a new replication controller.
func
(
rcStrategy
)
Validate
(
obj
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
func
(
rcStrategy
)
Validate
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
controller
:=
obj
.
(
*
api
.
ReplicationController
)
return
validation
.
ValidateReplicationController
(
controller
)
}
...
...
@@ -70,7 +70,7 @@ func (rcStrategy) AllowCreateOnUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user.
func
(
rcStrategy
)
ValidateUpdate
(
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
func
(
rcStrategy
)
ValidateUpdate
(
ctx
api
.
Context
,
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
return
validation
.
ValidateReplicationControllerUpdate
(
old
.
(
*
api
.
ReplicationController
),
obj
.
(
*
api
.
ReplicationController
))
}
...
...
pkg/registry/endpoint/rest.go
View file @
d7c5f427
...
...
@@ -58,7 +58,7 @@ func (endpointsStrategy) PrepareForUpdate(obj, old runtime.Object) {
}
// Validate validates a new endpoints.
func
(
endpointsStrategy
)
Validate
(
obj
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
func
(
endpointsStrategy
)
Validate
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
return
validation
.
ValidateEndpoints
(
obj
.
(
*
api
.
Endpoints
))
}
...
...
@@ -68,7 +68,7 @@ func (endpointsStrategy) AllowCreateOnUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user.
func
(
endpointsStrategy
)
ValidateUpdate
(
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
func
(
endpointsStrategy
)
ValidateUpdate
(
ctx
api
.
Context
,
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
return
validation
.
ValidateEndpointsUpdate
(
old
.
(
*
api
.
Endpoints
),
obj
.
(
*
api
.
Endpoints
))
}
...
...
pkg/registry/generic/etcd/etcd_test.go
View file @
d7c5f427
...
...
@@ -45,10 +45,10 @@ func (t *testRESTStrategy) AllowCreateOnUpdate() bool { return t.allowCreateOnUp
func
(
t
*
testRESTStrategy
)
PrepareForCreate
(
obj
runtime
.
Object
)
{}
func
(
t
*
testRESTStrategy
)
PrepareForUpdate
(
obj
,
old
runtime
.
Object
)
{}
func
(
t
*
testRESTStrategy
)
Validate
(
obj
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
func
(
t
*
testRESTStrategy
)
Validate
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
return
nil
}
func
(
t
*
testRESTStrategy
)
ValidateUpdate
(
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
func
(
t
*
testRESTStrategy
)
ValidateUpdate
(
ctx
api
.
Context
,
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
return
nil
}
...
...
pkg/registry/minion/rest.go
View file @
d7c5f427
...
...
@@ -67,13 +67,13 @@ func (nodeStrategy) PrepareForUpdate(obj, old runtime.Object) {
}
// Validate validates a new node.
func
(
nodeStrategy
)
Validate
(
obj
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
func
(
nodeStrategy
)
Validate
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
node
:=
obj
.
(
*
api
.
Node
)
return
validation
.
ValidateMinion
(
node
)
}
// ValidateUpdate is the default update validation for an end user.
func
(
nodeStrategy
)
ValidateUpdate
(
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
func
(
nodeStrategy
)
ValidateUpdate
(
ctx
api
.
Context
,
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
return
validation
.
ValidateMinionUpdate
(
old
.
(
*
api
.
Node
),
obj
.
(
*
api
.
Node
))
}
...
...
pkg/registry/namespace/rest.go
View file @
d7c5f427
...
...
@@ -77,7 +77,7 @@ func (namespaceStrategy) PrepareForUpdate(obj, old runtime.Object) {
}
// Validate validates a new namespace.
func
(
namespaceStrategy
)
Validate
(
obj
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
func
(
namespaceStrategy
)
Validate
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
namespace
:=
obj
.
(
*
api
.
Namespace
)
return
validation
.
ValidateNamespace
(
namespace
)
}
...
...
@@ -88,7 +88,7 @@ func (namespaceStrategy) AllowCreateOnUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user.
func
(
namespaceStrategy
)
ValidateUpdate
(
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
func
(
namespaceStrategy
)
ValidateUpdate
(
ctx
api
.
Context
,
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
return
validation
.
ValidateNamespaceUpdate
(
obj
.
(
*
api
.
Namespace
),
old
.
(
*
api
.
Namespace
))
}
...
...
@@ -104,7 +104,7 @@ func (namespaceStatusStrategy) PrepareForUpdate(obj, old runtime.Object) {
newNamespace
.
Spec
=
oldNamespace
.
Spec
}
func
(
namespaceStatusStrategy
)
ValidateUpdate
(
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
func
(
namespaceStatusStrategy
)
ValidateUpdate
(
ctx
api
.
Context
,
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
return
validation
.
ValidateNamespaceStatusUpdate
(
obj
.
(
*
api
.
Namespace
),
old
.
(
*
api
.
Namespace
))
}
...
...
@@ -114,7 +114,7 @@ type namespaceFinalizeStrategy struct {
var
FinalizeStrategy
=
namespaceFinalizeStrategy
{
Strategy
}
func
(
namespaceFinalizeStrategy
)
ValidateUpdate
(
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
func
(
namespaceFinalizeStrategy
)
ValidateUpdate
(
ctx
api
.
Context
,
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
return
validation
.
ValidateNamespaceFinalizeUpdate
(
obj
.
(
*
api
.
Namespace
),
old
.
(
*
api
.
Namespace
))
}
...
...
pkg/registry/pod/rest.go
View file @
d7c5f427
...
...
@@ -67,7 +67,7 @@ func (podStrategy) PrepareForUpdate(obj, old runtime.Object) {
}
// Validate validates a new pod.
func
(
podStrategy
)
Validate
(
obj
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
func
(
podStrategy
)
Validate
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
pod
:=
obj
.
(
*
api
.
Pod
)
return
validation
.
ValidatePod
(
pod
)
}
...
...
@@ -78,7 +78,7 @@ func (podStrategy) AllowCreateOnUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user.
func
(
podStrategy
)
ValidateUpdate
(
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
func
(
podStrategy
)
ValidateUpdate
(
ctx
api
.
Context
,
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
return
validation
.
ValidatePodUpdate
(
obj
.
(
*
api
.
Pod
),
old
.
(
*
api
.
Pod
))
}
...
...
@@ -99,7 +99,7 @@ func (podStatusStrategy) PrepareForUpdate(obj, old runtime.Object) {
newPod
.
Spec
=
oldPod
.
Spec
}
func
(
podStatusStrategy
)
ValidateUpdate
(
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
func
(
podStatusStrategy
)
ValidateUpdate
(
ctx
api
.
Context
,
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
// TODO: merge valid fields after update
return
validation
.
ValidatePodStatusUpdate
(
obj
.
(
*
api
.
Pod
),
old
.
(
*
api
.
Pod
))
}
...
...
pkg/registry/resourcequota/rest.go
View file @
d7c5f427
...
...
@@ -57,7 +57,7 @@ func (resourcequotaStrategy) PrepareForUpdate(obj, old runtime.Object) {
}
// Validate validates a new resourcequota.
func
(
resourcequotaStrategy
)
Validate
(
obj
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
func
(
resourcequotaStrategy
)
Validate
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
resourcequota
:=
obj
.
(
*
api
.
ResourceQuota
)
return
validation
.
ValidateResourceQuota
(
resourcequota
)
}
...
...
@@ -68,7 +68,7 @@ func (resourcequotaStrategy) AllowCreateOnUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user.
func
(
resourcequotaStrategy
)
ValidateUpdate
(
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
func
(
resourcequotaStrategy
)
ValidateUpdate
(
ctx
api
.
Context
,
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
return
validation
.
ValidateResourceQuotaUpdate
(
obj
.
(
*
api
.
ResourceQuota
),
old
.
(
*
api
.
ResourceQuota
))
}
...
...
@@ -84,7 +84,7 @@ func (resourcequotaStatusStrategy) PrepareForUpdate(obj, old runtime.Object) {
newResourcequota
.
Spec
=
oldResourcequota
.
Spec
}
func
(
resourcequotaStatusStrategy
)
ValidateUpdate
(
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
func
(
resourcequotaStatusStrategy
)
ValidateUpdate
(
ctx
api
.
Context
,
obj
,
old
runtime
.
Object
)
fielderrors
.
ValidationErrorList
{
return
validation
.
ValidateResourceQuotaStatusUpdate
(
obj
.
(
*
api
.
ResourceQuota
),
old
.
(
*
api
.
ResourceQuota
))
}
...
...
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