Skip to content

Commit d4d696d

Browse files
committed
add legacyBinding for non-Named Binding Creater
1 parent b28f62c commit d4d696d

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

pkg/registry/core/pod/storage/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ go_library(
6464
"//pkg/registry/core/pod/rest:go_default_library",
6565
"//staging/src/k8s.io/api/policy/v1beta1:go_default_library",
6666
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
67+
"//staging/src/k8s.io/apimachinery/pkg/api/meta:go_default_library",
6768
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
6869
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
6970
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",

pkg/registry/core/pod/storage/storage.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"net/url"
2424

2525
"k8s.io/apimachinery/pkg/api/errors"
26+
"k8s.io/apimachinery/pkg/api/meta"
2627
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2728
"k8s.io/apimachinery/pkg/runtime"
2829
"k8s.io/apiserver/pkg/registry/generic"
@@ -49,6 +50,7 @@ import (
4950
type PodStorage struct {
5051
Pod *REST
5152
Binding *BindingREST
53+
LegacyBinding *LegacyBindingREST
5254
Eviction *EvictionREST
5355
Status *StatusREST
5456
EphemeralContainers *EphemeralContainersREST
@@ -95,9 +97,11 @@ func NewStorage(optsGetter generic.RESTOptionsGetter, k client.ConnectionInfoGet
9597
ephemeralContainersStore := *store
9698
ephemeralContainersStore.UpdateStrategy = pod.EphemeralContainersStrategy
9799

100+
bindingREST := &BindingREST{store: store}
98101
return PodStorage{
99102
Pod: &REST{store, proxyTransport},
100103
Binding: &BindingREST{store: store},
104+
LegacyBinding: &LegacyBindingREST{bindingREST},
101105
Eviction: newEvictionStorage(store, podDisruptionBudgetClient),
102106
Status: &StatusREST{store: &statusStore},
103107
EphemeralContainers: &EphemeralContainersREST{store: &ephemeralContainersStore},
@@ -225,6 +229,32 @@ func (r *BindingREST) assignPod(ctx context.Context, podID string, machine strin
225229
return
226230
}
227231

232+
var _ = rest.Creater(&LegacyBindingREST{})
233+
234+
// LegacyBindingREST implements the REST endpoint for binding pods to nodes when etcd is in use.
235+
type LegacyBindingREST struct {
236+
bindingRest *BindingREST
237+
}
238+
239+
// NamespaceScoped fulfill rest.Scoper
240+
func (r *LegacyBindingREST) NamespaceScoped() bool {
241+
return r.bindingRest.NamespaceScoped()
242+
}
243+
244+
// New creates a new binding resource
245+
func (r *LegacyBindingREST) New() runtime.Object {
246+
return r.bindingRest.New()
247+
}
248+
249+
// Create ensures a pod is bound to a specific host.
250+
func (r *LegacyBindingREST) Create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (out runtime.Object, err error) {
251+
metadata, err := meta.Accessor(obj)
252+
if err != nil {
253+
return nil, errors.NewBadRequest(fmt.Sprintf("not a Binding object: %T", obj))
254+
}
255+
return r.bindingRest.Create(ctx, metadata.GetName(), obj, createValidation, options)
256+
}
257+
228258
// StatusREST implements the REST endpoint for changing the status of a pod.
229259
type StatusREST struct {
230260
store *genericregistry.Store

pkg/registry/core/rest/storage_core.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func (c LegacyRESTStorageProvider) NewLegacyRESTStorage(restOptionsGetter generi
248248
"pods/portforward": podStorage.PortForward,
249249
"pods/proxy": podStorage.Proxy,
250250
"pods/binding": podStorage.Binding,
251-
"bindings": podStorage.Binding,
251+
"bindings": podStorage.LegacyBinding,
252252

253253
"podTemplates": podTemplateStorage,
254254

0 commit comments

Comments
 (0)