craigcondit commented on a change in pull request #365:
URL: 
https://github.com/apache/incubator-yunikorn-k8shim/pull/365#discussion_r802131105



##########
File path: pkg/cache/external/scheduler_cache.go
##########
@@ -283,34 +281,46 @@ func (cache *SchedulerCache) addPod(pod *v1.Pod) {
                }
                n.AddPod(pod)
        }
+       cache.podsMap[key] = pod
 }
 
-func (cache *SchedulerCache) updatePod(oldPod, newPod *v1.Pod) error {
-       if err := cache.removePod(oldPod); err != nil {
-               return err
+func (cache *SchedulerCache) updatePod(oldPod, newPod *v1.Pod, key string) 
error {
+       var result error = nil
+       // remove old version from cache
+       if err := cache.removePod(oldPod, false); err != nil {
+               result = err
        }
-       cache.addPod(newPod)
-       return nil
+       // add new version to cache
+       cache.addPod(newPod, key)
+       return result
 }
 
 func (cache *SchedulerCache) RemovePod(pod *v1.Pod) error {
        cache.lock.Lock()
        defer cache.lock.Unlock()
-       return cache.removePod(pod)
+       return cache.removePod(pod, true)
 }
 
-func (cache *SchedulerCache) removePod(pod *v1.Pod) error {
+func (cache *SchedulerCache) removePod(pod *v1.Pod, removeAlloc bool) error {
+       if removeAlloc {
+               // remove pod from any pending or in-progress allocations
+               delete(cache.pendingAllocations, string(pod.UID))
+               delete(cache.inProgressAllocations, string(pod.UID))
+       }
+
+       // remove pod from cache
+       delete(cache.podsMap, string(pod.UID))
+
+       // remove pod from node

Review comment:
       Here we make sure to remove from cache regardless so that we don't leak 
resources.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to