diff --git a/pkg/scheduler/firstfit.go b/pkg/scheduler/firstfit.go index e98c9a96932..e1e088c5cc4 100644 --- a/pkg/scheduler/firstfit.go +++ b/pkg/scheduler/firstfit.go @@ -24,6 +24,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" ) +// FirstFitScheduler is a Scheduler interface implementation which uses first fit algorithm. type FirstFitScheduler struct { podLister PodLister // TODO: *rand.Rand is *not* threadsafe @@ -48,6 +49,7 @@ func (s *FirstFitScheduler) containsPort(pod api.Pod, port api.Port) bool { return false } +// Schedule schedules a pod on the first machine which matches its requirement. func (s *FirstFitScheduler) Schedule(pod api.Pod, minionLister MinionLister) (string, error) { machines, err := minionLister.List() if err != nil { @@ -80,7 +82,6 @@ func (s *FirstFitScheduler) Schedule(pod api.Pod, minionLister MinionLister) (st } if len(machineOptions) == 0 { return "", fmt.Errorf("failed to find fit for %#v", pod) - } else { - return machineOptions[s.random.Int()%len(machineOptions)], nil } + return machineOptions[s.random.Int()%len(machineOptions)], nil } diff --git a/pkg/scheduler/listers.go b/pkg/scheduler/listers.go index ad7a41562f7..96b216d8b44 100644 --- a/pkg/scheduler/listers.go +++ b/pkg/scheduler/listers.go @@ -21,27 +21,28 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" ) -// Anything that can list minions for a scheduler. +// MinionLister interface represents anything that can list minions for a scheduler. type MinionLister interface { List() (machines []string, err error) } -// Make a MinionLister from a []string +// FakeMinionLister implements MinionLister on a []string for test purposes. type FakeMinionLister []string -// Returns minions as a []string +// List returns minions as a []string func (f FakeMinionLister) List() ([]string, error) { return []string(f), nil } -// Anything that can list pods for a scheduler +// PodLister interface represents anything that can list pods for a scheduler type PodLister interface { ListPods(labels.Selector) ([]api.Pod, error) } -// Make a MinionLister from an []api.Pods +// FakePodLister implements PodLister on an []api.Pods for test purposes. type FakePodLister []api.Pod +// ListPods returns []api.Pod matching a query. func (f FakePodLister) ListPods(s labels.Selector) (selected []api.Pod, err error) { for _, pod := range f { if s.Matches(labels.Set(pod.Labels)) { diff --git a/pkg/scheduler/random.go b/pkg/scheduler/random.go index 6d268a33f09..23a076636a8 100644 --- a/pkg/scheduler/random.go +++ b/pkg/scheduler/random.go @@ -22,7 +22,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" ) -// RandomScheduler choses machines uniformly at random. +// RandomScheduler chooses machines uniformly at random. type RandomScheduler struct { // TODO: rand.Rand is *NOT* thread safe. random *rand.Rand @@ -34,6 +34,7 @@ func MakeRandomScheduler(random *rand.Rand) Scheduler { } } +// Schedule schedules a given pod to a random machine. func (s *RandomScheduler) Schedule(pod api.Pod, minionLister MinionLister) (string, error) { machines, err := minionLister.List() if err != nil { diff --git a/pkg/scheduler/roundrobin.go b/pkg/scheduler/roundrobin.go index 6d1df35fee6..02ad62a0881 100644 --- a/pkg/scheduler/roundrobin.go +++ b/pkg/scheduler/roundrobin.go @@ -31,6 +31,7 @@ func MakeRoundRobinScheduler() Scheduler { } } +// Schedule schedules a pod on the machine next to the last scheduled machine. func (s *RoundRobinScheduler) Schedule(pod api.Pod, minionLister MinionLister) (string, error) { machines, err := minionLister.List() if err != nil {