mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-17 23:19:26 +00:00
Add a subbindings resource as /pods/{name}/binding
Allows POST to create a binding as a child. Also refactors internal and v1beta3 Binding to be more generic (so that other resources can support Bindings).
This commit is contained in:
@@ -287,9 +287,11 @@ type binder struct {
|
||||
|
||||
// Bind just does a POST binding RPC.
|
||||
func (b *binder) Bind(binding *api.Binding) error {
|
||||
glog.V(2).Infof("Attempting to bind %v to %v", binding.PodID, binding.Host)
|
||||
glog.V(2).Infof("Attempting to bind %v to %v", binding.Name, binding.Target.Name)
|
||||
ctx := api.WithNamespace(api.NewContext(), binding.Namespace)
|
||||
return b.Post().Namespace(api.NamespaceValue(ctx)).Resource("bindings").Body(binding).Do().Error()
|
||||
// TODO: use Pods interface for binding once clusters are upgraded
|
||||
// return b.Pods(binding.Namespace).Bind(binding)
|
||||
}
|
||||
|
||||
type clock interface {
|
||||
|
@@ -366,9 +366,11 @@ func TestBind(t *testing.T) {
|
||||
{binding: &api.Binding{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Namespace: api.NamespaceDefault,
|
||||
Name: "foo",
|
||||
},
|
||||
Target: api.ObjectReference{
|
||||
Name: "foohost.kubernetes.mydomain.com",
|
||||
},
|
||||
PodID: "foo",
|
||||
Host: "foohost.kubernetes.mydomain.com",
|
||||
}},
|
||||
}
|
||||
|
||||
|
@@ -80,9 +80,11 @@ func (s *Scheduler) scheduleOne() {
|
||||
return
|
||||
}
|
||||
b := &api.Binding{
|
||||
ObjectMeta: api.ObjectMeta{Namespace: pod.Namespace},
|
||||
PodID: pod.Name,
|
||||
Host: dest,
|
||||
ObjectMeta: api.ObjectMeta{Namespace: pod.Namespace, Name: pod.Name},
|
||||
Target: api.ObjectReference{
|
||||
Kind: "Node",
|
||||
Name: dest,
|
||||
},
|
||||
}
|
||||
if err := s.config.Binder.Bind(b); err != nil {
|
||||
glog.V(1).Infof("Failed to bind pod: %v", err)
|
||||
|
@@ -25,6 +25,7 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/scheduler"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
)
|
||||
|
||||
type fakeBinder struct {
|
||||
@@ -63,7 +64,7 @@ func TestScheduler(t *testing.T) {
|
||||
{
|
||||
sendPod: podWithID("foo"),
|
||||
algo: mockScheduler{"machine1", nil},
|
||||
expectBind: &api.Binding{PodID: "foo", Host: "machine1"},
|
||||
expectBind: &api.Binding{ObjectMeta: api.ObjectMeta{Name: "foo"}, Target: api.ObjectReference{Kind: "Node", Name: "machine1"}},
|
||||
eventReason: "scheduled",
|
||||
}, {
|
||||
sendPod: podWithID("foo"),
|
||||
@@ -74,7 +75,7 @@ func TestScheduler(t *testing.T) {
|
||||
}, {
|
||||
sendPod: podWithID("foo"),
|
||||
algo: mockScheduler{"machine1", nil},
|
||||
expectBind: &api.Binding{PodID: "foo", Host: "machine1"},
|
||||
expectBind: &api.Binding{ObjectMeta: api.ObjectMeta{Name: "foo"}, Target: api.ObjectReference{Kind: "Node", Name: "machine1"}},
|
||||
injectBindError: errB,
|
||||
expectError: errB,
|
||||
expectErrorPod: podWithID("foo"),
|
||||
@@ -120,7 +121,7 @@ func TestScheduler(t *testing.T) {
|
||||
t.Errorf("%v: error: wanted %v, got %v", i, e, a)
|
||||
}
|
||||
if e, a := item.expectBind, gotBinding; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("%v: error: wanted %v, got %v", i, e, a)
|
||||
t.Errorf("%v: error: %s", i, util.ObjectDiff(e, a))
|
||||
}
|
||||
<-called
|
||||
events.Stop()
|
||||
|
Reference in New Issue
Block a user