// Create creates a scheduler and all support functions. func (factory *ConfigFactory) Create() *scheduler.Config { // Watch and queue pods that need scheduling. podQueue := cache.NewFIFO() cache.NewReflector(factory.createUnassignedPodLW(), &api.Pod{}, podQueue).Run() // Watch and cache all running pods. Scheduler needs to find all pods // so it knows where it's safe to place a pod. Cache this locally. podCache := cache.NewStore() cache.NewReflector(factory.createAssignedPodLW(), &api.Pod{}, podCache).Run() // Watch minions. // Minions may be listed frequently, so provide a local up-to-date cache. minionCache := cache.NewStore() if false { // Disable this code until minions support watches. cache.NewReflector(factory.createMinionLW(), &api.Minion{}, minionCache).Run() } else { cache.NewPoller(factory.pollMinions, 10*time.Second, minionCache).Run() } 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(minionLister), // Fit is determined by non-conflicting disk volumes algorithm.NoDiskConflict, // Fit is determined by node selector query algorithm.NewSelectorMatchPredicate(minionLister), }, // Prioritize nodes by least requested utilization. algorithm.LeastRequestedPriority, &storeToPodLister{podCache}, r) podBackoff := podBackoff{ perPodBackoff: map[string]*backoffEntry{}, clock: realClock{}, } return &scheduler.Config{ MinionLister: minionLister, Algorithm: algo, Binder: &binder{factory.Client}, NextPod: func() *api.Pod { pod := podQueue.Pop().(*api.Pod) glog.V(2).Infof("About to try and schedule pod %v\n"+ "\tknown minions: %v\n"+ "\tknown scheduled pods: %v\n", pod.Name, minionCache.ContainedIDs(), podCache.ContainedIDs()) return pod }, Error: factory.makeDefaultErrorFunc(&podBackoff, podQueue), } }
// CreateFromKeys creates a scheduler from a set of registered fit predicate keys and priority keys. func (f *ConfigFactory) CreateFromKeys(predicateKeys, priorityKeys util.StringSet) (*scheduler.Config, error) { glog.V(2).Infof("creating scheduler with fit predicates '%v' and priority functions '%v", predicateKeys, priorityKeys) predicateFuncs, err := getFitPredicateFunctions(predicateKeys) if err != nil { return nil, err } priorityConfigs, err := getPriorityFunctionConfigs(priorityKeys) if err != nil { return nil, err } // Watch and queue pods that need scheduling. cache.NewReflector(f.createUnassignedPodLW(), &api.Pod{}, f.PodQueue).Run() // Watch and cache all running pods. Scheduler needs to find all pods // so it knows where it's safe to place a pod. Cache this locally. cache.NewReflector(f.createAssignedPodLW(), &api.Pod{}, f.PodLister.Store).Run() // Watch minions. // Minions may be listed frequently, so provide a local up-to-date cache. if false { // Disable this code until minions support watches. Note when this code is enabled, // we need to make sure minion ListWatcher has proper FieldSelector. cache.NewReflector(f.createMinionLW(), &api.Node{}, f.MinionLister.Store).Run() } else { cache.NewPoller(f.pollMinions, 10*time.Second, f.MinionLister.Store).Run() } // Watch and cache all service objects. Scheduler needs to find all pods // created by the same service, so that it can spread them correctly. // Cache this locally. cache.NewReflector(f.createServiceLW(), &api.Service{}, f.ServiceLister.Store).Run() r := rand.New(rand.NewSource(time.Now().UnixNano())) algo := algorithm.NewGenericScheduler(predicateFuncs, priorityConfigs, f.PodLister, r) podBackoff := podBackoff{ perPodBackoff: map[string]*backoffEntry{}, clock: realClock{}, defaultDuration: 1 * time.Second, maxDuration: 60 * time.Second, } return &scheduler.Config{ MinionLister: f.MinionLister, Algorithm: algo, Binder: &binder{f.Client}, NextPod: func() *api.Pod { pod := f.PodQueue.Pop().(*api.Pod) glog.V(2).Infof("glog.v2 --> About to try and schedule pod %v", pod.Name) return pod }, Error: f.makeDefaultErrorFunc(&podBackoff, f.PodQueue), }, nil }
// Create creates a scheduler and all support functions. func (factory *ConfigFactory) Create() *scheduler.Config { // Watch and queue pods that need scheduling. podQueue := cache.NewFIFO() cache.NewReflector(factory.createUnassignedPodLW(), &api.Pod{}, podQueue).Run() // Watch and cache all running pods. Scheduler needs to find all pods // so it knows where it's safe to place a pod. Cache this locally. podCache := cache.NewStore() cache.NewReflector(factory.createAssignedPodLW(), &api.Pod{}, podCache).Run() // Watch minions. // Minions may be listed frequently, so provide a local up-to-date cache. minionCache := cache.NewStore() if false { // Disable this code until minions support watches. cache.NewReflector(factory.createMinionLW(), &api.Minion{}, minionCache).Run() } else { cache.NewPoller(factory.pollMinions, 10*time.Second, minionCache).Run() } r := rand.New(rand.NewSource(time.Now().UnixNano())) algo := algorithm.NewRandomFitScheduler( &storeToPodLister{podCache}, r) return &scheduler.Config{ MinionLister: &storeToMinionLister{minionCache}, Algorithm: algo, Binder: &binder{factory.Client}, NextPod: func() *api.Pod { pod := podQueue.Pop().(*api.Pod) // TODO: Remove or reduce verbosity by sep 6th, 2014. Leave until then to // make it easy to find scheduling problems. glog.Infof("About to try and schedule pod %v\n"+ "\tknown minions: %v\n"+ "\tknown scheduled pods: %v\n", pod.ID, minionCache.Contains(), podCache.Contains()) return pod }, Error: factory.makeDefaultErrorFunc(podQueue), } }
// CreateFromKeys creates a scheduler from a set of registered fit predicate keys and priority keys. func (f *ConfigFactory) CreateFromKeys(predicateKeys, priorityKeys util.StringSet) (*scheduler.Config, error) { glog.V(2).Infof("creating scheduler with fit predicates '%v' and priority functions '%v", predicateKeys, priorityKeys) //predicateFuncs, err := getFitPredicateFunctions(predicateKeys) //if err != nil { // return nil, err //} //priorityConfigs, err := getPriorityFunctionConfigs(priorityKeys) //if err != nil { // return nil, err //} // Watch and queue pods that need scheduling. cache.NewReflector(f.createUnassignedPodLW(), &api.Pod{}, f.PodQueue).Run() // Watch minions. // Minions may be listed frequently, so provide a local up-to-date cache. if false { // Disable this code until minions support watches. Note when this code is enabled, // we need to make sure minion ListWatcher has proper FieldSelector. cache.NewReflector(f.createMinionLW(), &api.Node{}, f.MinionLister.Store).Run() } else { cache.NewPoller(f.pollMinions, 10*time.Second, f.MinionLister.Store).Run() } algo := algorithm.NewYARNScheduler() //wrap the pod cache so that the scheduler can be notified of "deletes" //the dependency here is "inverted". The generic scheduler depends on the podCache //and the schedulerPodCache below depends on the scheduler in order to delegate deletes. //This needs to be fixed. //See : https://github.com/GoogleCloudPlatform/kubernetes/issues/1517 schedulerPodCache.SetScheduler(algo) // Watch and cache all running pods. Scheduler needs to find all pods // so it knows where it's safe to place a pod. Cache this locally. cache.NewReflector(f.createAssignedPodLW(), &api.Pod{}, f.PodLister.Store).Run() // Watch and cache all service objects. Scheduler needs to find all pods // created by the same service, so that it can spread them correctly. // Cache this locally. cache.NewReflector(f.createServiceLW(), &api.Service{}, f.ServiceLister.Store).Run() //r := rand.New(rand.NewSource(time.Now().UnixNano())) //algo := algorithm.NewGenericScheduler(predicateFuncs, priorityConfigs, f.PodLister, r) podBackoff := podBackoff{ perPodBackoff: map[string]*backoffEntry{}, clock: realClock{}, defaultDuration: 1 * time.Second, maxDuration: 60 * time.Second, } return &scheduler.Config{ MinionLister: f.MinionLister, Algorithm: algo, Binder: &binder{f.Client}, NextPod: func() *api.Pod { pod := f.PodQueue.Pop().(*api.Pod) glog.V(2).Infof("glog.v2 --> About to try and schedule pod %v\n"+ "\tknown minions: %v\n"+ "\tknown scheduled pods: %v\n", pod.Name, f.MinionLister.Store.ContainedIDs(), schedulerPodCache.ContainedIDs()) return pod }, Error: f.makeDefaultErrorFunc(&podBackoff, f.PodQueue), }, nil }