Require namespace on controller, pod, service objects

This commit is contained in:
derekwaynecarr
2014-09-29 17:17:42 -04:00
parent 1b2c62a8ca
commit e4ec49ee6b
10 changed files with 142 additions and 3 deletions

View File

@@ -17,6 +17,7 @@ limitations under the License.
package controller
import (
stderrs "errors"
"fmt"
"time"
@@ -59,6 +60,10 @@ 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.ValidNamespaceOnCreateOrUpdate(ctx, &controller.JSONBase) {
return nil, errors.NewConflict("controller", controller.Namespace, stderrs.New("Controller.Namespace does not match the provided context"))
}
if len(controller.ID) == 0 {
controller.ID = uuid.NewUUID().String()
}
@@ -128,6 +133,9 @@ 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.ValidNamespaceOnCreateOrUpdate(ctx, &controller.JSONBase) {
return nil, errors.NewConflict("controller", controller.Namespace, stderrs.New("Controller.Namespace does not match the provided context"))
}
if errs := validation.ValidateReplicationController(controller); len(errs) > 0 {
return nil, errors.NewInvalid("replicationController", controller.ID, errs)
}