diff --git a/pkg/api/rest/create_test.go b/pkg/api/rest/create_test.go index 695f8cd746a..bb2be35245c 100644 --- a/pkg/api/rest/create_test.go +++ b/pkg/api/rest/create_test.go @@ -25,17 +25,17 @@ import ( func TestCheckGeneratedNameError(t *testing.T) { expect := errors.NewNotFound("foo", "bar") - if err := CheckGeneratedNameError(Pods, expect, &api.Pod{}); err != expect { + if err := CheckGeneratedNameError(Services, expect, &api.Pod{}); err != expect { t.Errorf("NotFoundError should be ignored: %v", err) } expect = errors.NewAlreadyExists("foo", "bar") - if err := CheckGeneratedNameError(Pods, expect, &api.Pod{}); err != expect { + if err := CheckGeneratedNameError(Services, expect, &api.Pod{}); err != expect { t.Errorf("AlreadyExists should be returned when no GenerateName field: %v", err) } expect = errors.NewAlreadyExists("foo", "bar") - if err := CheckGeneratedNameError(Pods, expect, &api.Pod{ObjectMeta: api.ObjectMeta{GenerateName: "foo"}}); err == nil || !errors.IsServerTimeout(err) { + if err := CheckGeneratedNameError(Services, expect, &api.Pod{ObjectMeta: api.ObjectMeta{GenerateName: "foo"}}); err == nil || !errors.IsServerTimeout(err) { t.Errorf("expected try again later error: %v", err) } } diff --git a/pkg/api/rest/types.go b/pkg/api/rest/types.go index 71c710f37c8..f3b6741f82d 100644 --- a/pkg/api/rest/types.go +++ b/pkg/api/rest/types.go @@ -72,46 +72,6 @@ func (rcStrategy) Validate(obj runtime.Object) errors.ValidationErrorList { return validation.ValidateReplicationController(controller) } -// podStrategy implements behavior for Pods -// TODO: move to a pod specific package. -type podStrategy struct { - runtime.ObjectTyper - api.NameGenerator -} - -// Pods is the default logic that applies when creating and updating Pod -// objects. -var Pods = podStrategy{api.Scheme, api.SimpleNameGenerator} - -// NamespaceScoped is true for pods. -func (podStrategy) NamespaceScoped() bool { - return true -} - -// ResetBeforeCreate clears fields that are not allowed to be set by end users on creation. -func (podStrategy) ResetBeforeCreate(obj runtime.Object) { - pod := obj.(*api.Pod) - pod.Status = api.PodStatus{ - Phase: api.PodPending, - } -} - -// Validate validates a new pod. -func (podStrategy) Validate(obj runtime.Object) errors.ValidationErrorList { - pod := obj.(*api.Pod) - return validation.ValidatePod(pod) -} - -// AllowCreateOnUpdate is false for pods. -func (podStrategy) AllowCreateOnUpdate() bool { - return false -} - -// ValidateUpdate is the default update validation for an end user. -func (podStrategy) ValidateUpdate(obj, old runtime.Object) errors.ValidationErrorList { - return validation.ValidatePodUpdate(obj.(*api.Pod), old.(*api.Pod)) -} - // svcStrategy implements behavior for Services // TODO: move to a service specific package. type svcStrategy struct { diff --git a/pkg/registry/pod/etcd/etcd.go b/pkg/registry/pod/etcd/etcd.go index 3b01928bc61..6c7f1b96e04 100644 --- a/pkg/registry/pod/etcd/etcd.go +++ b/pkg/registry/pod/etcd/etcd.go @@ -56,9 +56,9 @@ func NewREST(h tools.EtcdHelper, factory pod.BoundPodFactory) (*REST, *BindingRE }, EndpointName: "pods", - CreateStrategy: rest.Pods, + CreateStrategy: pod.Strategy, - UpdateStrategy: rest.Pods, + UpdateStrategy: pod.Strategy, AfterUpdate: bindings.AfterUpdate, ReturnDeletedObject: true, diff --git a/pkg/registry/pod/rest.go b/pkg/registry/pod/rest.go index 8175d7dbece..53c1df1a403 100644 --- a/pkg/registry/pod/rest.go +++ b/pkg/registry/pod/rest.go @@ -24,11 +24,53 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1" + "github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" ) +// podStrategy implements behavior for Pods +// TODO: move to a pod specific package. +type podStrategy struct { + runtime.ObjectTyper + api.NameGenerator +} + +// Strategy is the default logic that applies when creating and updating Pod +// objects via the REST API. +// TODO: Create other strategies for updating status, bindings, etc +var Strategy = podStrategy{api.Scheme, api.SimpleNameGenerator} + +// NamespaceScoped is true for pods. +func (podStrategy) NamespaceScoped() bool { + return true +} + +// ResetBeforeCreate clears fields that are not allowed to be set by end users on creation. +func (podStrategy) ResetBeforeCreate(obj runtime.Object) { + pod := obj.(*api.Pod) + pod.Status = api.PodStatus{ + Phase: api.PodPending, + } +} + +// Validate validates a new pod. +func (podStrategy) Validate(obj runtime.Object) errors.ValidationErrorList { + pod := obj.(*api.Pod) + return validation.ValidatePod(pod) +} + +// AllowCreateOnUpdate is false for pods. +func (podStrategy) AllowCreateOnUpdate() bool { + return false +} + +// ValidateUpdate is the default update validation for an end user. +func (podStrategy) ValidateUpdate(obj, old runtime.Object) errors.ValidationErrorList { + return validation.ValidatePodUpdate(obj.(*api.Pod), old.(*api.Pod)) +} + // PodStatusGetter is an interface used by Pods to fetch and retrieve status info. type PodStatusGetter interface { GetPodStatus(namespace, name string) (*api.PodStatus, error)