mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Move rest.Pods to pkg/registry/pod/rest.go
This commit is contained in:
parent
7a93af57c0
commit
72da3b4424
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user