mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-11 13:02:14 +00:00
Make scheduler emit events
This commit is contained in:
parent
95b855b8e6
commit
10214457b7
@ -18,6 +18,7 @@ limitations under the License.
|
|||||||
package testapi
|
package testapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||||
@ -52,3 +53,13 @@ func ResourceVersioner() runtime.ResourceVersioner {
|
|||||||
}
|
}
|
||||||
return interfaces.ResourceVersioner
|
return interfaces.ResourceVersioner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SelfLink returns a self link that will appear to be for the version Version().
|
||||||
|
// 'resource' should be the resource path, e.g. "pods" for the Pod type. 'name' should be
|
||||||
|
// empty for lists.
|
||||||
|
func SelfLink(resource, name string) string {
|
||||||
|
if name == "" {
|
||||||
|
return fmt.Sprintf("/api/%s/%s", Version(), resource)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("/api/%s/%s/%s", Version(), resource, name)
|
||||||
|
}
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
|
||||||
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz"
|
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz"
|
||||||
masterPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/master"
|
masterPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/master"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
@ -55,6 +56,8 @@ func main() {
|
|||||||
glog.Fatalf("Invalid API configuration: %v", err)
|
glog.Fatalf("Invalid API configuration: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
record.StartRecording(kubeClient, "scheduler")
|
||||||
|
|
||||||
go http.ListenAndServe(net.JoinHostPort(address.String(), strconv.Itoa(*port)), nil)
|
go http.ListenAndServe(net.JoinHostPort(address.String(), strconv.Itoa(*port)), nil)
|
||||||
|
|
||||||
configFactory := &factory.ConfigFactory{Client: kubeClient}
|
configFactory := &factory.ConfigFactory{Client: kubeClient}
|
||||||
|
@ -18,6 +18,7 @@ package scheduler
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"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.
|
// TODO: move everything from pkg/scheduler into this package. Remove references from registry.
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/scheduler"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/scheduler"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
@ -67,6 +68,7 @@ func (s *Scheduler) scheduleOne() {
|
|||||||
pod := s.config.NextPod()
|
pod := s.config.NextPod()
|
||||||
dest, err := s.config.Algorithm.Schedule(*pod, s.config.MinionLister)
|
dest, err := s.config.Algorithm.Schedule(*pod, s.config.MinionLister)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
record.Eventf(pod, "", string(api.PodWaiting), "failedScheduling", "Error scheduling: %v", err)
|
||||||
s.config.Error(pod, err)
|
s.config.Error(pod, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -75,6 +77,9 @@ func (s *Scheduler) scheduleOne() {
|
|||||||
Host: dest,
|
Host: dest,
|
||||||
}
|
}
|
||||||
if err := s.config.Binder.Bind(b); err != nil {
|
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)
|
s.config.Error(pod, err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
record.Eventf(pod, "", string(api.PodWaiting), "scheduled", "Successfully assigned %v to %v", pod.ID, dest)
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"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"
|
"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 (fb fakeBinder) Bind(binding *api.Binding) error { return fb.b(binding) }
|
||||||
|
|
||||||
func podWithID(id string) *api.Pod {
|
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 {
|
type mockScheduler struct {
|
||||||
@ -45,7 +47,7 @@ func (es mockScheduler) Schedule(pod api.Pod, ml scheduler.MinionLister) (string
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestScheduler(t *testing.T) {
|
func TestScheduler(t *testing.T) {
|
||||||
|
defer record.StartLogging(t.Logf).Stop()
|
||||||
errS := errors.New("scheduler")
|
errS := errors.New("scheduler")
|
||||||
errB := errors.New("binder")
|
errB := errors.New("binder")
|
||||||
|
|
||||||
@ -56,16 +58,19 @@ func TestScheduler(t *testing.T) {
|
|||||||
expectErrorPod *api.Pod
|
expectErrorPod *api.Pod
|
||||||
expectError error
|
expectError error
|
||||||
expectBind *api.Binding
|
expectBind *api.Binding
|
||||||
|
eventReason string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
sendPod: podWithID("foo"),
|
sendPod: podWithID("foo"),
|
||||||
algo: mockScheduler{"machine1", nil},
|
algo: mockScheduler{"machine1", nil},
|
||||||
expectBind: &api.Binding{PodID: "foo", Host: "machine1"},
|
expectBind: &api.Binding{PodID: "foo", Host: "machine1"},
|
||||||
|
eventReason: "scheduled",
|
||||||
}, {
|
}, {
|
||||||
sendPod: podWithID("foo"),
|
sendPod: podWithID("foo"),
|
||||||
algo: mockScheduler{"machine1", errS},
|
algo: mockScheduler{"machine1", errS},
|
||||||
expectError: errS,
|
expectError: errS,
|
||||||
expectErrorPod: podWithID("foo"),
|
expectErrorPod: podWithID("foo"),
|
||||||
|
eventReason: "failedScheduling",
|
||||||
}, {
|
}, {
|
||||||
sendPod: podWithID("foo"),
|
sendPod: podWithID("foo"),
|
||||||
algo: mockScheduler{"machine1", nil},
|
algo: mockScheduler{"machine1", nil},
|
||||||
@ -73,6 +78,7 @@ func TestScheduler(t *testing.T) {
|
|||||||
injectBindError: errB,
|
injectBindError: errB,
|
||||||
expectError: errB,
|
expectError: errB,
|
||||||
expectErrorPod: podWithID("foo"),
|
expectErrorPod: podWithID("foo"),
|
||||||
|
eventReason: "failedScheduling",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,6 +104,13 @@ func TestScheduler(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
s := New(c)
|
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()
|
s.scheduleOne()
|
||||||
if e, a := item.expectErrorPod, gotPod; !reflect.DeepEqual(e, a) {
|
if e, a := item.expectErrorPod, gotPod; !reflect.DeepEqual(e, a) {
|
||||||
t.Errorf("%v: error pod: wanted %v, got %v", i, 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) {
|
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: wanted %v, got %v", i, e, a)
|
||||||
}
|
}
|
||||||
|
<-called
|
||||||
|
events.Stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user