Add comments to pkg/scheduler/ to pass golint

This commit is contained in:
Kouhei Ueno
2014-07-11 22:01:12 +09:00
parent 628667a2b0
commit e268e4bb7a
4 changed files with 15 additions and 8 deletions

View File

@@ -24,12 +24,14 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
) )
// FirstFitScheduler is a Scheduler interface implementation which uses first fit algorithm.
type FirstFitScheduler struct { type FirstFitScheduler struct {
podLister PodLister podLister PodLister
// TODO: *rand.Rand is *not* threadsafe // TODO: *rand.Rand is *not* threadsafe
random *rand.Rand random *rand.Rand
} }
// MakeFirstFitScheduler creates a new instance of FirstFitScheduler.
func MakeFirstFitScheduler(podLister PodLister, random *rand.Rand) Scheduler { func MakeFirstFitScheduler(podLister PodLister, random *rand.Rand) Scheduler {
return &FirstFitScheduler{ return &FirstFitScheduler{
podLister: podLister, podLister: podLister,
@@ -48,6 +50,7 @@ func (s *FirstFitScheduler) containsPort(pod api.Pod, port api.Port) bool {
return false 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) { func (s *FirstFitScheduler) Schedule(pod api.Pod, minionLister MinionLister) (string, error) {
machines, err := minionLister.List() machines, err := minionLister.List()
if err != nil { if err != nil {
@@ -80,7 +83,6 @@ func (s *FirstFitScheduler) Schedule(pod api.Pod, minionLister MinionLister) (st
} }
if len(machineOptions) == 0 { if len(machineOptions) == 0 {
return "", fmt.Errorf("failed to find fit for %#v", pod) 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
} }

View File

@@ -21,27 +21,28 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "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 { type MinionLister interface {
List() (machines []string, err error) List() (machines []string, err error)
} }
// Make a MinionLister from a []string // FakeMinionLister implements MinionLister on a []string for test purposes.
type FakeMinionLister []string type FakeMinionLister []string
// Returns minions as a []string // List returns minions as a []string
func (f FakeMinionLister) List() ([]string, error) { func (f FakeMinionLister) List() ([]string, error) {
return []string(f), nil 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 { type PodLister interface {
ListPods(labels.Selector) ([]api.Pod, error) 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 type FakePodLister []api.Pod
// ListPods returns []api.Pod matching a query.
func (f FakePodLister) ListPods(s labels.Selector) (selected []api.Pod, err error) { func (f FakePodLister) ListPods(s labels.Selector) (selected []api.Pod, err error) {
for _, pod := range f { for _, pod := range f {
if s.Matches(labels.Set(pod.Labels)) { if s.Matches(labels.Set(pod.Labels)) {

View File

@@ -22,18 +22,20 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
) )
// RandomScheduler choses machines uniformly at random. // RandomScheduler chooses machines uniformly at random.
type RandomScheduler struct { type RandomScheduler struct {
// TODO: rand.Rand is *NOT* thread safe. // TODO: rand.Rand is *NOT* thread safe.
random *rand.Rand random *rand.Rand
} }
// MakeRandomScheduler creates a new RandomScheduler instance.
func MakeRandomScheduler(random *rand.Rand) Scheduler { func MakeRandomScheduler(random *rand.Rand) Scheduler {
return &RandomScheduler{ return &RandomScheduler{
random: random, random: random,
} }
} }
// Schedule schedules a given pod to a random machine.
func (s *RandomScheduler) Schedule(pod api.Pod, minionLister MinionLister) (string, error) { func (s *RandomScheduler) Schedule(pod api.Pod, minionLister MinionLister) (string, error) {
machines, err := minionLister.List() machines, err := minionLister.List()
if err != nil { if err != nil {

View File

@@ -25,12 +25,14 @@ type RoundRobinScheduler struct {
currentIndex int currentIndex int
} }
// MakeRoundRobinScheduler creates a new RoundRobinScheduler instance.
func MakeRoundRobinScheduler() Scheduler { func MakeRoundRobinScheduler() Scheduler {
return &RoundRobinScheduler{ return &RoundRobinScheduler{
currentIndex: -1, currentIndex: -1,
} }
} }
// Schedule schedules a pod on the machine next to the last scheduled machine.
func (s *RoundRobinScheduler) Schedule(pod api.Pod, minionLister MinionLister) (string, error) { func (s *RoundRobinScheduler) Schedule(pod api.Pod, minionLister MinionLister) (string, error) {
machines, err := minionLister.List() machines, err := minionLister.List()
if err != nil { if err != nil {