Refine WaitingPod interface

This commit is contained in:
Wei Huang 2020-02-07 15:36:51 -08:00
parent 64ba0bf3d6
commit b8e2b0d990
No known key found for this signature in database
GPG Key ID: BE5E9752F8B6E005
2 changed files with 11 additions and 15 deletions

View File

@ -202,11 +202,9 @@ type WaitingPod interface {
// Allow declares the waiting pod is allowed to be scheduled by plugin pluginName.
// If this is the last remaining plugin to allow, then a success signal is delivered
// to unblock the pod.
// Returns true if the allow signal was successfully dealt with, false otherwise.
Allow(pluginName string) bool
// Reject declares the waiting pod unschedulable. Returns true if the reject signal
// was successfully delivered, false otherwise.
Reject(msg string) bool
Allow(pluginName string)
// Reject declares the waiting pod unschedulable.
Reject(msg string)
}
// Plugin is the parent type for all the scheduling framework plugins.

View File

@ -121,8 +121,7 @@ func (w *waitingPod) GetPendingPlugins() []string {
// Allow declares the waiting pod is allowed to be scheduled by plugin pluginName.
// If this is the last remaining plugin to allow, then a success signal is delivered
// to unblock the pod.
// Returns true if the allow signal was successfully dealt with, false otherwise.
func (w *waitingPod) Allow(pluginName string) bool {
func (w *waitingPod) Allow(pluginName string) {
w.mu.Lock()
defer w.mu.Unlock()
if timer, exist := w.pendingPlugins[pluginName]; exist {
@ -132,30 +131,29 @@ func (w *waitingPod) Allow(pluginName string) bool {
// Only signal success status after all plugins have allowed
if len(w.pendingPlugins) != 0 {
return true
return
}
// The select clause works as a non-blocking send.
// If there is no receiver, it's a no-op (default case).
select {
case w.s <- NewStatus(Success, ""):
return true
default:
return false
}
}
// Reject declares the waiting pod unschedulable. Returns true if the reject signal
// was successfully delivered, false otherwise.
func (w *waitingPod) Reject(msg string) bool {
// Reject declares the waiting pod unschedulable.
func (w *waitingPod) Reject(msg string) {
w.mu.RLock()
defer w.mu.RUnlock()
for _, timer := range w.pendingPlugins {
timer.Stop()
}
// The select clause works as a non-blocking send.
// If there is no receiver, it's a no-op (default case).
select {
case w.s <- NewStatus(Unschedulable, msg):
return true
default:
return false
}
}