Merge pull request #1789 from lavalamp/eventing4

Add event creation library and implement in scheduler.
This commit is contained in:
Eric Tune
2014-10-15 15:55:26 -07:00
15 changed files with 391 additions and 10 deletions

View File

@@ -213,7 +213,7 @@ func (s *storeToMinionLister) GetNodeInfo(id string) (*api.Minion, error) {
if minion, ok := s.Get(id); ok {
return minion.(*api.Minion), nil
}
return nil, fmt.Errorf("minion '%v' is not in cache")
return nil, fmt.Errorf("minion '%v' is not in cache", id)
}
// storeToPodLister turns a store into a pod lister. The store must contain (only) pods.

View File

@@ -18,6 +18,7 @@ package scheduler
import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
// TODO: move everything from pkg/scheduler into this package. Remove references from registry.
"github.com/GoogleCloudPlatform/kubernetes/pkg/scheduler"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
@@ -67,6 +68,7 @@ func (s *Scheduler) scheduleOne() {
pod := s.config.NextPod()
dest, err := s.config.Algorithm.Schedule(*pod, s.config.MinionLister)
if err != nil {
record.Eventf(pod, "", string(api.PodWaiting), "failedScheduling", "Error scheduling: %v", err)
s.config.Error(pod, err)
return
}
@@ -75,6 +77,9 @@ func (s *Scheduler) scheduleOne() {
Host: dest,
}
if err := s.config.Binder.Bind(b); err != nil {
record.Eventf(pod, "", string(api.PodWaiting), "failedScheduling", "Binding rejected: %v", err)
s.config.Error(pod, err)
return
}
record.Eventf(pod, "", string(api.PodWaiting), "scheduled", "Successfully assigned %v to %v", pod.ID, dest)
}

View File

@@ -22,6 +22,8 @@ import (
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
"github.com/GoogleCloudPlatform/kubernetes/pkg/scheduler"
)
@@ -32,7 +34,7 @@ type fakeBinder struct {
func (fb fakeBinder) Bind(binding *api.Binding) error { return fb.b(binding) }
func podWithID(id string) *api.Pod {
return &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}}
return &api.Pod{TypeMeta: api.TypeMeta{ID: id, SelfLink: testapi.SelfLink("pods", id)}}
}
type mockScheduler struct {
@@ -45,7 +47,7 @@ func (es mockScheduler) Schedule(pod api.Pod, ml scheduler.MinionLister) (string
}
func TestScheduler(t *testing.T) {
defer record.StartLogging(t.Logf).Stop()
errS := errors.New("scheduler")
errB := errors.New("binder")
@@ -56,16 +58,19 @@ func TestScheduler(t *testing.T) {
expectErrorPod *api.Pod
expectError error
expectBind *api.Binding
eventReason string
}{
{
sendPod: podWithID("foo"),
algo: mockScheduler{"machine1", nil},
expectBind: &api.Binding{PodID: "foo", Host: "machine1"},
sendPod: podWithID("foo"),
algo: mockScheduler{"machine1", nil},
expectBind: &api.Binding{PodID: "foo", Host: "machine1"},
eventReason: "scheduled",
}, {
sendPod: podWithID("foo"),
algo: mockScheduler{"machine1", errS},
expectError: errS,
expectErrorPod: podWithID("foo"),
eventReason: "failedScheduling",
}, {
sendPod: podWithID("foo"),
algo: mockScheduler{"machine1", nil},
@@ -73,6 +78,7 @@ func TestScheduler(t *testing.T) {
injectBindError: errB,
expectError: errB,
expectErrorPod: podWithID("foo"),
eventReason: "failedScheduling",
},
}
@@ -98,6 +104,13 @@ func TestScheduler(t *testing.T) {
},
}
s := New(c)
called := make(chan struct{})
events := record.GetEvents(func(e *api.Event) {
if e, a := item.eventReason, e.Reason; e != a {
t.Errorf("%v: expected %v, got %v", i, e, a)
}
close(called)
})
s.scheduleOne()
if e, a := item.expectErrorPod, gotPod; !reflect.DeepEqual(e, a) {
t.Errorf("%v: error pod: wanted %v, got %v", i, e, a)
@@ -108,5 +121,7 @@ func TestScheduler(t *testing.T) {
if e, a := item.expectBind, gotBinding; !reflect.DeepEqual(e, a) {
t.Errorf("%v: error: wanted %v, got %v", i, e, a)
}
<-called
events.Stop()
}
}