Merge pull request #87936 from Huang-Wei/waitingPods-glitch

Refine WaitingPod interface for scheduler Permit plugin
This commit is contained in:
Kubernetes Prow Robot 2020-02-10 09:23:54 -08:00 committed by GitHub
commit db9123e50e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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. // 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 // If this is the last remaining plugin to allow, then a success signal is delivered
// to unblock the pod. // to unblock the pod.
// Returns true if the allow signal was successfully dealt with, false otherwise. Allow(pluginName string)
Allow(pluginName string) bool // Reject declares the waiting pod unschedulable.
// Reject declares the waiting pod unschedulable. Returns true if the reject signal Reject(msg string)
// was successfully delivered, false otherwise.
Reject(msg string) bool
} }
// Plugin is the parent type for all the scheduling framework plugins. // 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. // 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 // If this is the last remaining plugin to allow, then a success signal is delivered
// to unblock the pod. // to unblock the pod.
// Returns true if the allow signal was successfully dealt with, false otherwise. func (w *waitingPod) Allow(pluginName string) {
func (w *waitingPod) Allow(pluginName string) bool {
w.mu.Lock() w.mu.Lock()
defer w.mu.Unlock() defer w.mu.Unlock()
if timer, exist := w.pendingPlugins[pluginName]; exist { 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 // Only signal success status after all plugins have allowed
if len(w.pendingPlugins) != 0 { 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 { select {
case w.s <- NewStatus(Success, ""): case w.s <- NewStatus(Success, ""):
return true
default: default:
return false
} }
} }
// Reject declares the waiting pod unschedulable. Returns true if the reject signal // Reject declares the waiting pod unschedulable.
// was successfully delivered, false otherwise. func (w *waitingPod) Reject(msg string) {
func (w *waitingPod) Reject(msg string) bool {
w.mu.RLock() w.mu.RLock()
defer w.mu.RUnlock() defer w.mu.RUnlock()
for _, timer := range w.pendingPlugins { for _, timer := range w.pendingPlugins {
timer.Stop() timer.Stop()
} }
// The select clause works as a non-blocking send.
// If there is no receiver, it's a no-op (default case).
select { select {
case w.s <- NewStatus(Unschedulable, msg): case w.s <- NewStatus(Unschedulable, msg):
return true
default: default:
return false
} }
} }