Commit dbd80460 authored by Yecheng Fu's avatar Yecheng Fu

Clear cache instead of saving nils if no claims to bind or provision

parent c2d25e08
...@@ -182,6 +182,11 @@ func (b *volumeBinder) FindPodVolumes(pod *v1.Pod, node *v1.Node) (unboundVolume ...@@ -182,6 +182,11 @@ func (b *volumeBinder) FindPodVolumes(pod *v1.Pod, node *v1.Node) (unboundVolume
) )
defer func() { defer func() {
// We recreate bindings for each new schedule loop. // 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 // Although we do not distinguish nil from empty in this function, for
// easier testing, we normalize empty to nil. // easier testing, we normalize empty to nil.
if len(matchedClaims) == 0 { if len(matchedClaims) == 0 {
......
...@@ -30,6 +30,9 @@ type PodBindingCache interface { ...@@ -30,6 +30,9 @@ type PodBindingCache interface {
// pod and node. // pod and node.
UpdateBindings(pod *v1.Pod, node string, bindings []*bindingInfo, provisionings []*v1.PersistentVolumeClaim) 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. // 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 // A nil return value means that the entry was not found. An empty slice
// means that no binding operations are needed. // means that no binding operations are needed.
...@@ -148,3 +151,15 @@ func (c *podBindingCache) GetProvisionedPVCs(pod *v1.Pod, node string) []*v1.Per ...@@ -148,3 +151,15 @@ func (c *podBindingCache) GetProvisionedPVCs(pod *v1.Pod, node string) []*v1.Per
} }
return decision.provisionings 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)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment