mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Use cache for minion lookups, don't hammer apiserver
This commit is contained in:
parent
13acb63fb3
commit
0431f2430d
@ -137,10 +137,7 @@ func startComponents(manifestURL string) (apiServerURL string) {
|
||||
|
||||
// Scheduler
|
||||
schedulerConfigFactory := &factory.ConfigFactory{cl}
|
||||
schedulerConfig, err := schedulerConfigFactory.Create()
|
||||
if err != nil {
|
||||
glog.Fatalf("Unable to construct scheduler config: %v", err)
|
||||
}
|
||||
schedulerConfig := schedulerConfigFactory.Create()
|
||||
scheduler.New(schedulerConfig).Run()
|
||||
|
||||
endpoints := service.NewEndpointController(cl)
|
||||
|
@ -58,10 +58,7 @@ func main() {
|
||||
go http.ListenAndServe(net.JoinHostPort(address.String(), strconv.Itoa(*port)), nil)
|
||||
|
||||
configFactory := &factory.ConfigFactory{Client: kubeClient}
|
||||
config, err := configFactory.Create()
|
||||
if err != nil {
|
||||
glog.Fatalf("Can't create scheduler config: %v", err)
|
||||
}
|
||||
config := configFactory.Create()
|
||||
s := scheduler.New(config)
|
||||
s.Run()
|
||||
|
||||
|
@ -19,6 +19,7 @@ limitations under the License.
|
||||
package factory
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"sync"
|
||||
"time"
|
||||
@ -42,7 +43,7 @@ type ConfigFactory struct {
|
||||
}
|
||||
|
||||
// Create creates a scheduler and all support functions.
|
||||
func (factory *ConfigFactory) Create() (*scheduler.Config, error) {
|
||||
func (factory *ConfigFactory) Create() *scheduler.Config {
|
||||
// Watch and queue pods that need scheduling.
|
||||
podQueue := cache.NewFIFO()
|
||||
cache.NewReflector(factory.createUnassignedPodLW(), &api.Pod{}, podQueue).Run()
|
||||
@ -63,13 +64,14 @@ func (factory *ConfigFactory) Create() (*scheduler.Config, error) {
|
||||
}
|
||||
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
minionLister := &storeToMinionLister{minionCache}
|
||||
|
||||
algo := algorithm.NewGenericScheduler(
|
||||
[]algorithm.FitPredicate{
|
||||
// Fit is defined based on the absence of port conflicts.
|
||||
algorithm.PodFitsPorts,
|
||||
// Fit is determined by resource availability
|
||||
algorithm.NewResourceFitPredicate(algorithm.ClientNodeInfo{factory.Client}),
|
||||
algorithm.NewResourceFitPredicate(minionLister),
|
||||
},
|
||||
// Prioritize nodes by least requested utilization.
|
||||
algorithm.LeastRequestedPriority,
|
||||
@ -81,7 +83,7 @@ func (factory *ConfigFactory) Create() (*scheduler.Config, error) {
|
||||
}
|
||||
|
||||
return &scheduler.Config{
|
||||
MinionLister: &storeToMinionLister{minionCache},
|
||||
MinionLister: minionLister,
|
||||
Algorithm: algo,
|
||||
Binder: &binder{factory.Client},
|
||||
NextPod: func() *api.Pod {
|
||||
@ -93,7 +95,7 @@ func (factory *ConfigFactory) Create() (*scheduler.Config, error) {
|
||||
return pod
|
||||
},
|
||||
Error: factory.makeDefaultErrorFunc(&podBackoff, podQueue),
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
type listWatch struct {
|
||||
@ -204,6 +206,14 @@ func (s *storeToMinionLister) List() (machines api.MinionList, err error) {
|
||||
return machines, nil
|
||||
}
|
||||
|
||||
// GetNodeInfo returns cached data for the minion 'id'.
|
||||
func (s *storeToMinionLister) GetNodeInfo(id string) (*api.Minion, error) {
|
||||
if minion, ok := s.Get(id); ok {
|
||||
return minion.(*api.Minion), nil
|
||||
}
|
||||
return nil, fmt.Errorf("minion '%v' is not in cache")
|
||||
}
|
||||
|
||||
// storeToPodLister turns a store into a pod lister. The store must contain (only) pods.
|
||||
type storeToPodLister struct {
|
||||
cache.Store
|
||||
|
Loading…
Reference in New Issue
Block a user