From 09800643e26de868f905913d18c1425a2df3fd5c Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Thu, 23 Oct 2014 16:53:32 -0400 Subject: [PATCH] Change validation now that namespace is on ObjectMeta --- pkg/api/context.go | 2 +- pkg/registry/controller/rest.go | 4 ++-- pkg/registry/pod/rest.go | 4 ++-- pkg/registry/service/rest.go | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/api/context.go b/pkg/api/context.go index 5c74020c47e..a1f2ffc511e 100644 --- a/pkg/api/context.go +++ b/pkg/api/context.go @@ -70,7 +70,7 @@ func Namespace(ctx Context) string { } // ValidNamespace returns false if the namespace on the context differs from the resource. If the resource has no namespace, it is set to the value in the context. -func ValidNamespace(ctx Context, resource *TypeMeta) bool { +func ValidNamespace(ctx Context, resource *ObjectMeta) bool { ns, ok := NamespaceFrom(ctx) if len(resource.Namespace) == 0 { resource.Namespace = ns diff --git a/pkg/registry/controller/rest.go b/pkg/registry/controller/rest.go index d73c282c6b6..b45910c2169 100644 --- a/pkg/registry/controller/rest.go +++ b/pkg/registry/controller/rest.go @@ -59,7 +59,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Obje if !ok { return nil, fmt.Errorf("not a replication controller: %#v", obj) } - if !api.ValidNamespace(ctx, &controller.TypeMeta) { + if !api.ValidNamespace(ctx, &controller.ObjectMeta) { return nil, errors.NewConflict("controller", controller.Namespace, fmt.Errorf("Controller.Namespace does not match the provided context")) } @@ -132,7 +132,7 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan runtime.Obje if !ok { return nil, fmt.Errorf("not a replication controller: %#v", obj) } - if !api.ValidNamespace(ctx, &controller.TypeMeta) { + if !api.ValidNamespace(ctx, &controller.ObjectMeta) { return nil, errors.NewConflict("controller", controller.Namespace, fmt.Errorf("Controller.Namespace does not match the provided context")) } if errs := validation.ValidateReplicationController(controller); len(errs) > 0 { diff --git a/pkg/registry/pod/rest.go b/pkg/registry/pod/rest.go index eec3f135b26..f6715a768bb 100644 --- a/pkg/registry/pod/rest.go +++ b/pkg/registry/pod/rest.go @@ -90,7 +90,7 @@ func NewREST(config *RESTConfig) *REST { func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) { pod := obj.(*api.Pod) - if !api.ValidNamespace(ctx, &pod.TypeMeta) { + if !api.ValidNamespace(ctx, &pod.ObjectMeta) { return nil, errors.NewConflict("pod", pod.Namespace, fmt.Errorf("Pod.Namespace does not match the provided context")) } pod.DesiredState.Manifest.UUID = uuid.NewUUID().String() @@ -186,7 +186,7 @@ func (*REST) New() runtime.Object { func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) { pod := obj.(*api.Pod) - if !api.ValidNamespace(ctx, &pod.TypeMeta) { + if !api.ValidNamespace(ctx, &pod.ObjectMeta) { return nil, errors.NewConflict("pod", pod.Namespace, fmt.Errorf("Pod.Namespace does not match the provided context")) } if errs := validation.ValidatePod(pod); len(errs) > 0 { diff --git a/pkg/registry/service/rest.go b/pkg/registry/service/rest.go index 68f6c599f21..8ed59b5c413 100644 --- a/pkg/registry/service/rest.go +++ b/pkg/registry/service/rest.go @@ -81,7 +81,7 @@ func reloadIPsFromStorage(ipa *ipAllocator, registry Registry) { func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) { service := obj.(*api.Service) - if !api.ValidNamespace(ctx, &service.TypeMeta) { + if !api.ValidNamespace(ctx, &service.ObjectMeta) { return nil, errors.NewConflict("service", service.Namespace, fmt.Errorf("Service.Namespace does not match the provided context")) } if errs := validation.ValidateService(service); len(errs) > 0 { @@ -213,7 +213,7 @@ func GetServiceEnvironmentVariables(ctx api.Context, registry Registry, machine func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) { service := obj.(*api.Service) - if !api.ValidNamespace(ctx, &service.TypeMeta) { + if !api.ValidNamespace(ctx, &service.ObjectMeta) { return nil, errors.NewConflict("service", service.Namespace, fmt.Errorf("Service.Namespace does not match the provided context")) } if errs := validation.ValidateService(service); len(errs) > 0 {