Skip to content

Commit

Permalink
Merge pull request kubernetes#6163 from ncdc/add-ctx-to-rest-prepare
Browse files Browse the repository at this point in the history
Pass ctx to Validate, ValidateUpdate
  • Loading branch information
smarterclayton committed Mar 30, 2015
2 parents 73452fd + d7c5f42 commit 1dc895e
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions pkg/api/rest/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/rest/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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))
}
4 changes: 2 additions & 2 deletions pkg/api/rest/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkg/registry/controller/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package controller

import (
"fmt"
"strconv"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
Expand All @@ -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.
Expand Down Expand Up @@ -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)
}
Expand All @@ -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))
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/registry/endpoint/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand All @@ -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))
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/registry/generic/etcd/etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/registry/minion/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/registry/namespace/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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))
}

Expand All @@ -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))
}

Expand All @@ -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))
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/registry/pod/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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))
}

Expand All @@ -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))
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/registry/resourcequota/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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))
}

Expand All @@ -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))
}

Expand Down

0 comments on commit 1dc895e

Please sign in to comment.