mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
rename FirstFitScheduler to RandomFitScheduler
This commit is contained in:
parent
070b4ffe9f
commit
c875a6d3ba
@ -84,7 +84,7 @@ func (m *Master) init(cloud cloudprovider.Interface, podInfoGetter client.PodInf
|
|||||||
m.random = rand.New(rand.NewSource(int64(time.Now().Nanosecond())))
|
m.random = rand.New(rand.NewSource(int64(time.Now().Nanosecond())))
|
||||||
podCache := NewPodCache(podInfoGetter, m.podRegistry, time.Second*30)
|
podCache := NewPodCache(podInfoGetter, m.podRegistry, time.Second*30)
|
||||||
go podCache.Loop()
|
go podCache.Loop()
|
||||||
s := scheduler.MakeFirstFitScheduler(m.podRegistry, m.random)
|
s := scheduler.MakeRandomFitScheduler(m.podRegistry, m.random)
|
||||||
m.storage = map[string]apiserver.RESTStorage{
|
m.storage = map[string]apiserver.RESTStorage{
|
||||||
"pods": registry.MakePodRegistryStorage(m.podRegistry, podInfoGetter, s, m.minionRegistry, cloud, podCache),
|
"pods": registry.MakePodRegistryStorage(m.podRegistry, podInfoGetter, s, m.minionRegistry, cloud, podCache),
|
||||||
"replicationControllers": registry.NewControllerRegistryStorage(m.controllerRegistry, m.podRegistry),
|
"replicationControllers": registry.NewControllerRegistryStorage(m.controllerRegistry, m.podRegistry),
|
||||||
|
@ -25,21 +25,21 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FirstFitScheduler is a Scheduler which schedules a Pod on a random machine which matches its requirement.
|
// RandomFitScheduler is a Scheduler which schedules a Pod on a random machine which matches its requirement.
|
||||||
type FirstFitScheduler struct {
|
type RandomFitScheduler struct {
|
||||||
podLister PodLister
|
podLister PodLister
|
||||||
random *rand.Rand
|
random *rand.Rand
|
||||||
randomLock sync.Mutex
|
randomLock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeFirstFitScheduler(podLister PodLister, random *rand.Rand) Scheduler {
|
func MakeRandomFitScheduler(podLister PodLister, random *rand.Rand) Scheduler {
|
||||||
return &FirstFitScheduler{
|
return &RandomFitScheduler{
|
||||||
podLister: podLister,
|
podLister: podLister,
|
||||||
random: random,
|
random: random,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *FirstFitScheduler) containsPort(pod api.Pod, port api.Port) bool {
|
func (s *RandomFitScheduler) containsPort(pod api.Pod, port api.Port) bool {
|
||||||
for _, container := range pod.DesiredState.Manifest.Containers {
|
for _, container := range pod.DesiredState.Manifest.Containers {
|
||||||
for _, podPort := range container.Ports {
|
for _, podPort := range container.Ports {
|
||||||
if podPort.HostPort == port.HostPort {
|
if podPort.HostPort == port.HostPort {
|
||||||
@ -51,7 +51,7 @@ func (s *FirstFitScheduler) containsPort(pod api.Pod, port api.Port) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Schedule schedules a pod on a random machine which matches its requirement.
|
// Schedule schedules a pod on a random machine which matches its requirement.
|
||||||
func (s *FirstFitScheduler) Schedule(pod api.Pod, minionLister MinionLister) (string, error) {
|
func (s *RandomFitScheduler) Schedule(pod api.Pod, minionLister MinionLister) (string, error) {
|
||||||
machines, err := minionLister.List()
|
machines, err := minionLister.List()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
@ -23,31 +23,31 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFirstFitSchedulerNothingScheduled(t *testing.T) {
|
func TestRandomFitSchedulerNothingScheduled(t *testing.T) {
|
||||||
fakeRegistry := FakePodLister{}
|
fakeRegistry := FakePodLister{}
|
||||||
r := rand.New(rand.NewSource(0))
|
r := rand.New(rand.NewSource(0))
|
||||||
st := schedulerTester{
|
st := schedulerTester{
|
||||||
t: t,
|
t: t,
|
||||||
scheduler: MakeFirstFitScheduler(&fakeRegistry, r),
|
scheduler: MakeRandomFitScheduler(&fakeRegistry, r),
|
||||||
minionLister: FakeMinionLister{"m1", "m2", "m3"},
|
minionLister: FakeMinionLister{"m1", "m2", "m3"},
|
||||||
}
|
}
|
||||||
st.expectSchedule(api.Pod{}, "m3")
|
st.expectSchedule(api.Pod{}, "m3")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFirstFitSchedulerFirstScheduled(t *testing.T) {
|
func TestRandomFitSchedulerFirstScheduled(t *testing.T) {
|
||||||
fakeRegistry := FakePodLister{
|
fakeRegistry := FakePodLister{
|
||||||
makePod("m1", 8080),
|
makePod("m1", 8080),
|
||||||
}
|
}
|
||||||
r := rand.New(rand.NewSource(0))
|
r := rand.New(rand.NewSource(0))
|
||||||
st := schedulerTester{
|
st := schedulerTester{
|
||||||
t: t,
|
t: t,
|
||||||
scheduler: MakeFirstFitScheduler(fakeRegistry, r),
|
scheduler: MakeRandomFitScheduler(fakeRegistry, r),
|
||||||
minionLister: FakeMinionLister{"m1", "m2", "m3"},
|
minionLister: FakeMinionLister{"m1", "m2", "m3"},
|
||||||
}
|
}
|
||||||
st.expectSchedule(makePod("", 8080), "m3")
|
st.expectSchedule(makePod("", 8080), "m3")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFirstFitSchedulerFirstScheduledComplicated(t *testing.T) {
|
func TestRandomFitSchedulerFirstScheduledComplicated(t *testing.T) {
|
||||||
fakeRegistry := FakePodLister{
|
fakeRegistry := FakePodLister{
|
||||||
makePod("m1", 80, 8080),
|
makePod("m1", 80, 8080),
|
||||||
makePod("m2", 8081, 8082, 8083),
|
makePod("m2", 8081, 8082, 8083),
|
||||||
@ -56,13 +56,13 @@ func TestFirstFitSchedulerFirstScheduledComplicated(t *testing.T) {
|
|||||||
r := rand.New(rand.NewSource(0))
|
r := rand.New(rand.NewSource(0))
|
||||||
st := schedulerTester{
|
st := schedulerTester{
|
||||||
t: t,
|
t: t,
|
||||||
scheduler: MakeFirstFitScheduler(fakeRegistry, r),
|
scheduler: MakeRandomFitScheduler(fakeRegistry, r),
|
||||||
minionLister: FakeMinionLister{"m1", "m2", "m3"},
|
minionLister: FakeMinionLister{"m1", "m2", "m3"},
|
||||||
}
|
}
|
||||||
st.expectSchedule(makePod("", 8080, 8081), "m3")
|
st.expectSchedule(makePod("", 8080, 8081), "m3")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFirstFitSchedulerFirstScheduledImpossible(t *testing.T) {
|
func TestRandomFitSchedulerFirstScheduledImpossible(t *testing.T) {
|
||||||
fakeRegistry := FakePodLister{
|
fakeRegistry := FakePodLister{
|
||||||
makePod("m1", 8080),
|
makePod("m1", 8080),
|
||||||
makePod("m2", 8081),
|
makePod("m2", 8081),
|
||||||
@ -71,7 +71,7 @@ func TestFirstFitSchedulerFirstScheduledImpossible(t *testing.T) {
|
|||||||
r := rand.New(rand.NewSource(0))
|
r := rand.New(rand.NewSource(0))
|
||||||
st := schedulerTester{
|
st := schedulerTester{
|
||||||
t: t,
|
t: t,
|
||||||
scheduler: MakeFirstFitScheduler(fakeRegistry, r),
|
scheduler: MakeRandomFitScheduler(fakeRegistry, r),
|
||||||
minionLister: FakeMinionLister{"m1", "m2", "m3"},
|
minionLister: FakeMinionLister{"m1", "m2", "m3"},
|
||||||
}
|
}
|
||||||
st.expectFailure(makePod("", 8080, 8081))
|
st.expectFailure(makePod("", 8080, 8081))
|
Loading…
Reference in New Issue
Block a user