diff --git a/pkg/registry/core/pod/storage/BUILD b/pkg/registry/core/pod/storage/BUILD index a9501a009e5..419a6cd6040 100644 --- a/pkg/registry/core/pod/storage/BUILD +++ b/pkg/registry/core/pod/storage/BUILD @@ -64,6 +64,7 @@ go_library( "//pkg/registry/core/pod/rest:go_default_library", "//staging/src/k8s.io/api/policy/v1beta1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/api/meta:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", diff --git a/pkg/registry/core/pod/storage/storage.go b/pkg/registry/core/pod/storage/storage.go index 3f07af35c32..f005bef0f1e 100644 --- a/pkg/registry/core/pod/storage/storage.go +++ b/pkg/registry/core/pod/storage/storage.go @@ -23,6 +23,7 @@ import ( "net/url" "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apiserver/pkg/registry/generic" @@ -49,6 +50,7 @@ import ( type PodStorage struct { Pod *REST Binding *BindingREST + LegacyBinding *LegacyBindingREST Eviction *EvictionREST Status *StatusREST EphemeralContainers *EphemeralContainersREST @@ -95,9 +97,11 @@ func NewStorage(optsGetter generic.RESTOptionsGetter, k client.ConnectionInfoGet ephemeralContainersStore := *store ephemeralContainersStore.UpdateStrategy = pod.EphemeralContainersStrategy + bindingREST := &BindingREST{store: store} return PodStorage{ Pod: &REST{store, proxyTransport}, Binding: &BindingREST{store: store}, + LegacyBinding: &LegacyBindingREST{bindingREST}, Eviction: newEvictionStorage(store, podDisruptionBudgetClient), Status: &StatusREST{store: &statusStore}, EphemeralContainers: &EphemeralContainersREST{store: &ephemeralContainersStore}, @@ -225,6 +229,32 @@ func (r *BindingREST) assignPod(ctx context.Context, podID string, machine strin return } +var _ = rest.Creater(&LegacyBindingREST{}) + +// LegacyBindingREST implements the REST endpoint for binding pods to nodes when etcd is in use. +type LegacyBindingREST struct { + bindingRest *BindingREST +} + +// NamespaceScoped fulfill rest.Scoper +func (r *LegacyBindingREST) NamespaceScoped() bool { + return r.bindingRest.NamespaceScoped() +} + +// New creates a new binding resource +func (r *LegacyBindingREST) New() runtime.Object { + return r.bindingRest.New() +} + +// Create ensures a pod is bound to a specific host. +func (r *LegacyBindingREST) Create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (out runtime.Object, err error) { + metadata, err := meta.Accessor(obj) + if err != nil { + return nil, errors.NewBadRequest(fmt.Sprintf("not a Binding object: %T", obj)) + } + return r.bindingRest.Create(ctx, metadata.GetName(), obj, createValidation, options) +} + // StatusREST implements the REST endpoint for changing the status of a pod. type StatusREST struct { store *genericregistry.Store diff --git a/pkg/registry/core/rest/storage_core.go b/pkg/registry/core/rest/storage_core.go index bd5a56f7a6b..6a00feae183 100644 --- a/pkg/registry/core/rest/storage_core.go +++ b/pkg/registry/core/rest/storage_core.go @@ -248,7 +248,7 @@ func (c LegacyRESTStorageProvider) NewLegacyRESTStorage(restOptionsGetter generi "pods/portforward": podStorage.PortForward, "pods/proxy": podStorage.Proxy, "pods/binding": podStorage.Binding, - "bindings": podStorage.Binding, + "bindings": podStorage.LegacyBinding, "podTemplates": podTemplateStorage,