Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
2ee074f9
Commit
2ee074f9
authored
Jul 11, 2014
by
brendandburns
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #410 from nyaxt/lint_scheduler
Add comments to pkg/scheduler/ to pass golint
parents
93d45c1e
bf137c38
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
8 deletions
+12
-8
firstfit.go
pkg/scheduler/firstfit.go
+3
-2
listers.go
pkg/scheduler/listers.go
+6
-5
random.go
pkg/scheduler/random.go
+2
-1
roundrobin.go
pkg/scheduler/roundrobin.go
+1
-0
No files found.
pkg/scheduler/firstfit.go
View file @
2ee074f9
...
@@ -24,6 +24,7 @@ import (
...
@@ -24,6 +24,7 @@ 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
...
@@ -48,6 +49,7 @@ func (s *FirstFitScheduler) containsPort(pod api.Pod, port api.Port) bool {
...
@@ -48,6 +49,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 +82,6 @@ func (s *FirstFitScheduler) Schedule(pod api.Pod, minionLister MinionLister) (st
...
@@ -80,7 +82,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
}
}
pkg/scheduler/listers.go
View file @
2ee074f9
...
@@ -21,27 +21,28 @@ import (
...
@@ -21,27 +21,28 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
)
)
//
A
nything that can list minions for a scheduler.
//
MinionLister interface represents a
nything 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
//
R
eturns minions as a []string
//
List r
eturns minions as a []string
func
(
f
FakeMinionLister
)
List
()
([]
string
,
error
)
{
func
(
f
FakeMinionLister
)
List
()
([]
string
,
error
)
{
return
[]
string
(
f
),
nil
return
[]
string
(
f
),
nil
}
}
//
A
nything that can list pods for a scheduler
//
PodLister interface represents a
nything 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
))
{
...
...
pkg/scheduler/random.go
View file @
2ee074f9
...
@@ -22,7 +22,7 @@ import (
...
@@ -22,7 +22,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)
)
// RandomScheduler choses machines uniformly at random.
// RandomScheduler cho
o
ses 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
...
@@ -34,6 +34,7 @@ func MakeRandomScheduler(random *rand.Rand) Scheduler {
...
@@ -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
)
{
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
{
...
...
pkg/scheduler/roundrobin.go
View file @
2ee074f9
...
@@ -31,6 +31,7 @@ func MakeRoundRobinScheduler() Scheduler {
...
@@ -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
)
{
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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment