From e268e4bb7a9c4e6e4e5026481b9a27cbe211e0ce Mon Sep 17 00:00:00 2001 From: Kouhei Ueno Date: Fri, 11 Jul 2014 22:01:12 +0900 Subject: [PATCH 1/2] Add comments to pkg/scheduler/ to pass golint --- pkg/scheduler/firstfit.go | 6 ++++-- pkg/scheduler/listers.go | 11 ++++++----- pkg/scheduler/random.go | 4 +++- pkg/scheduler/roundrobin.go | 2 ++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pkg/scheduler/firstfit.go b/pkg/scheduler/firstfit.go index e98c9a96932..35073072e5e 100644 --- a/pkg/scheduler/firstfit.go +++ b/pkg/scheduler/firstfit.go @@ -24,12 +24,14 @@ 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 random *rand.Rand } +// MakeFirstFitScheduler creates a new instance of FirstFitScheduler. func MakeFirstFitScheduler(podLister PodLister, random *rand.Rand) Scheduler { return &FirstFitScheduler{ podLister: podLister, @@ -48,6 +50,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 +83,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..f488548ce90 100644 --- a/pkg/scheduler/random.go +++ b/pkg/scheduler/random.go @@ -22,18 +22,20 @@ 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 } +// MakeRandomScheduler creates a new RandomScheduler instance. func MakeRandomScheduler(random *rand.Rand) Scheduler { return &RandomScheduler{ random: random, } } +// 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..eadbab0cabf 100644 --- a/pkg/scheduler/roundrobin.go +++ b/pkg/scheduler/roundrobin.go @@ -25,12 +25,14 @@ type RoundRobinScheduler struct { currentIndex int } +// MakeRoundRobinScheduler creates a new RoundRobinScheduler instance. func MakeRoundRobinScheduler() Scheduler { return &RoundRobinScheduler{ 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) { machines, err := minionLister.List() if err != nil { From bf137c38e7cf14d658824f10d4c09a7eb1f5c9be Mon Sep 17 00:00:00 2001 From: Kouhei Ueno Date: Sat, 12 Jul 2014 13:16:16 +0900 Subject: [PATCH 2/2] remove comments on Make.+() --- pkg/scheduler/firstfit.go | 1 - pkg/scheduler/random.go | 1 - pkg/scheduler/roundrobin.go | 1 - 3 files changed, 3 deletions(-) diff --git a/pkg/scheduler/firstfit.go b/pkg/scheduler/firstfit.go index 35073072e5e..e1e088c5cc4 100644 --- a/pkg/scheduler/firstfit.go +++ b/pkg/scheduler/firstfit.go @@ -31,7 +31,6 @@ type FirstFitScheduler struct { random *rand.Rand } -// MakeFirstFitScheduler creates a new instance of FirstFitScheduler. func MakeFirstFitScheduler(podLister PodLister, random *rand.Rand) Scheduler { return &FirstFitScheduler{ podLister: podLister, diff --git a/pkg/scheduler/random.go b/pkg/scheduler/random.go index f488548ce90..23a076636a8 100644 --- a/pkg/scheduler/random.go +++ b/pkg/scheduler/random.go @@ -28,7 +28,6 @@ type RandomScheduler struct { random *rand.Rand } -// MakeRandomScheduler creates a new RandomScheduler instance. func MakeRandomScheduler(random *rand.Rand) Scheduler { return &RandomScheduler{ random: random, diff --git a/pkg/scheduler/roundrobin.go b/pkg/scheduler/roundrobin.go index eadbab0cabf..02ad62a0881 100644 --- a/pkg/scheduler/roundrobin.go +++ b/pkg/scheduler/roundrobin.go @@ -25,7 +25,6 @@ type RoundRobinScheduler struct { currentIndex int } -// MakeRoundRobinScheduler creates a new RoundRobinScheduler instance. func MakeRoundRobinScheduler() Scheduler { return &RoundRobinScheduler{ currentIndex: -1,