diff --git a/pkg/controller/volume/persistentvolume/scheduler_binder.go b/pkg/controller/volume/persistentvolume/scheduler_binder.go index 9cbf315d899..8fb159e59a6 100644 --- a/pkg/controller/volume/persistentvolume/scheduler_binder.go +++ b/pkg/controller/volume/persistentvolume/scheduler_binder.go @@ -182,6 +182,11 @@ func (b *volumeBinder) FindPodVolumes(pod *v1.Pod, node *v1.Node) (unboundVolume ) defer func() { // We recreate bindings for each new schedule loop. + if len(matchedClaims) == 0 && len(provisionedClaims) == 0 { + // Clear cache if no claims to bind or provision for this node. + b.podBindingCache.ClearBindings(pod, node.Name) + return + } // Although we do not distinguish nil from empty in this function, for // easier testing, we normalize empty to nil. if len(matchedClaims) == 0 { diff --git a/pkg/controller/volume/persistentvolume/scheduler_binder_cache.go b/pkg/controller/volume/persistentvolume/scheduler_binder_cache.go index e5bb3a6ea1a..f67644f8914 100644 --- a/pkg/controller/volume/persistentvolume/scheduler_binder_cache.go +++ b/pkg/controller/volume/persistentvolume/scheduler_binder_cache.go @@ -30,6 +30,9 @@ type PodBindingCache interface { // pod and node. UpdateBindings(pod *v1.Pod, node string, bindings []*bindingInfo, provisionings []*v1.PersistentVolumeClaim) + // ClearBindings will clear the cached bindings for the given pod and node. + ClearBindings(pod *v1.Pod, node string) + // GetBindings will return the cached bindings for the given pod and node. // A nil return value means that the entry was not found. An empty slice // means that no binding operations are needed. @@ -148,3 +151,15 @@ func (c *podBindingCache) GetProvisionedPVCs(pod *v1.Pod, node string) []*v1.Per } return decision.provisionings } + +func (c *podBindingCache) ClearBindings(pod *v1.Pod, node string) { + c.rwMutex.Lock() + defer c.rwMutex.Unlock() + + podName := getPodName(pod) + decisions, ok := c.bindingDecisions[podName] + if !ok { + return + } + delete(decisions, node) +}