New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement multi-scheduler: #17865
Implement multi-scheduler: #17865
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,10 @@ import ( | |
"github.com/golang/glog" | ||
) | ||
|
||
const ( | ||
SchedulerAnnotationKey = "scheduler.alpha.kubernetes.io/name" | ||
) | ||
|
||
// ConfigFactory knows how to fill out a scheduler config with its support functions. | ||
type ConfigFactory struct { | ||
Client *client.Client | ||
|
@@ -66,10 +70,15 @@ type ConfigFactory struct { | |
|
||
scheduledPodPopulator *framework.Controller | ||
modeler scheduler.SystemModeler | ||
|
||
// SchedulerName of a scheduler is used to select which pods will be | ||
// processed by this scheduler, based on pods's annotation key: | ||
// 'scheduler.alpha.kubernetes.io/name' | ||
SchedulerName string | ||
} | ||
|
||
// Initializes the factory. | ||
func NewConfigFactory(client *client.Client, rateLimiter util.RateLimiter) *ConfigFactory { | ||
func NewConfigFactory(client *client.Client, rateLimiter util.RateLimiter, schedulerName string) *ConfigFactory { | ||
c := &ConfigFactory{ | ||
Client: client, | ||
PodQueue: cache.NewFIFO(cache.MetaNamespaceKeyFunc), | ||
|
@@ -79,6 +88,7 @@ func NewConfigFactory(client *client.Client, rateLimiter util.RateLimiter) *Conf | |
ServiceLister: &cache.StoreToServiceLister{Store: cache.NewStore(cache.MetaNamespaceKeyFunc)}, | ||
ControllerLister: &cache.StoreToReplicationControllerLister{Store: cache.NewStore(cache.MetaNamespaceKeyFunc)}, | ||
StopEverything: make(chan struct{}), | ||
SchedulerName: schedulerName, | ||
} | ||
modeler := scheduler.NewSimpleModeler(&cache.StoreToPodLister{Store: c.PodQueue}, c.ScheduledPodLister) | ||
c.modeler = modeler | ||
|
@@ -228,16 +238,32 @@ func (f *ConfigFactory) CreateFromKeys(predicateKeys, priorityKeys sets.String, | |
Algorithm: algo, | ||
Binder: &binder{f.Client}, | ||
NextPod: func() *api.Pod { | ||
pod := f.PodQueue.Pop().(*api.Pod) | ||
glog.V(2).Infof("About to try and schedule pod %v", pod.Name) | ||
return pod | ||
return f.getNextPod() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just use the function as the value of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point -- I assume you mean this line and the previous and next can collapse to just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing to NextPod: f.getNextPod() would require many follow-up changes which I think is not necessary. It is not as easy as I thought. Other than that, all comments are respected in the updated PR, including an integration test. |
||
}, | ||
Error: f.makeDefaultErrorFunc(&podBackoff, f.PodQueue), | ||
BindPodsRateLimiter: f.BindPodsRateLimiter, | ||
StopEverything: f.StopEverything, | ||
}, nil | ||
} | ||
|
||
func (f *ConfigFactory) getNextPod() *api.Pod { | ||
for { | ||
pod := f.PodQueue.Pop().(*api.Pod) | ||
if f.responsibleForPod(pod) { | ||
glog.V(4).Infof("About to try and schedule pod %v", pod.Name) | ||
return pod | ||
} | ||
} | ||
} | ||
|
||
func (f *ConfigFactory) responsibleForPod(pod *api.Pod) bool { | ||
if f.SchedulerName == api.DefaultSchedulerName { | ||
return pod.Annotations[SchedulerAnnotationKey] == f.SchedulerName || pod.Annotations[SchedulerAnnotationKey] == "" | ||
} else { | ||
return pod.Annotations[SchedulerAnnotationKey] == f.SchedulerName | ||
} | ||
} | ||
|
||
func getNodeConditionPredicate() cache.NodeConditionPredicate { | ||
return func(node api.Node) bool { | ||
for _, cond := range node.Status.Conditions { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smarterclayton was saying we should make these constants versioned, so you should make the same change to pkg/api/v1/types.go