Fix locking issue in pod manager

pull/6/head
Yu-Ju Hong 2015-04-15 11:39:57 -07:00
parent 902e1196ac
commit 967405f0bb
1 changed files with 11 additions and 8 deletions

View File

@ -249,22 +249,25 @@ func (self *basicPodManager) TranslatePodUID(uid types.UID) types.UID {
return uid
}
func (self *basicPodManager) getFullNameMaps() (map[string]*api.Pod, map[string]*api.Pod) {
func (self *basicPodManager) getOrphanedMirrorPodNames() []string {
self.lock.RLock()
defer self.lock.RUnlock()
return self.podByFullName, self.mirrorPodByFullName
var podFullNames []string
for podFullName := range self.mirrorPodByFullName {
if _, ok := self.podByFullName[podFullName]; !ok {
podFullNames = append(podFullNames, podFullName)
}
}
return podFullNames
}
// Delete all mirror pods which do not have associated static pods. This method
// sends deletion requets to the API server, but does NOT modify the internal
// pod storage in basicPodManager.
func (self *basicPodManager) DeleteOrphanedMirrorPods() {
podByFullName, mirrorPodByFullName := self.getFullNameMaps()
for podFullName := range mirrorPodByFullName {
if _, ok := podByFullName[podFullName]; !ok {
self.mirrorClient.DeleteMirrorPod(podFullName)
}
podFullNames := self.getOrphanedMirrorPodNames()
for _, podFullName := range podFullNames {
self.mirrorClient.DeleteMirrorPod(podFullName)
}
}