serialize access to active with a lock

pull/6/head
Mike Danese 2015-09-18 12:02:59 -07:00
parent e07eb387bb
commit 267cc9de91
1 changed files with 5 additions and 0 deletions

View File

@ -361,6 +361,7 @@ func getStatus(pods []api.Pod) (successful, unsuccessful int) {
} }
func (jm *JobController) manageJob(activePods []*api.Pod, successful, unsuccessful int, job *experimental.Job) int { func (jm *JobController) manageJob(activePods []*api.Pod, successful, unsuccessful int, job *experimental.Job) int {
var activeLock sync.Mutex
active := len(activePods) active := len(activePods)
parallelism := *job.Spec.Parallelism parallelism := *job.Spec.Parallelism
jobKey, err := controller.KeyFunc(job) jobKey, err := controller.KeyFunc(job)
@ -389,7 +390,9 @@ func (jm *JobController) manageJob(activePods []*api.Pod, successful, unsuccessf
glog.V(2).Infof("Failed deletion, decrementing expectations for controller %q", jobKey) glog.V(2).Infof("Failed deletion, decrementing expectations for controller %q", jobKey)
jm.expectations.DeletionObserved(jobKey) jm.expectations.DeletionObserved(jobKey)
util.HandleError(err) util.HandleError(err)
activeLock.Lock()
active++ active++
activeLock.Unlock()
} }
}(i) }(i)
} }
@ -417,7 +420,9 @@ func (jm *JobController) manageJob(activePods []*api.Pod, successful, unsuccessf
glog.V(2).Infof("Failed creation, decrementing expectations for controller %q", jobKey) glog.V(2).Infof("Failed creation, decrementing expectations for controller %q", jobKey)
jm.expectations.CreationObserved(jobKey) jm.expectations.CreationObserved(jobKey)
util.HandleError(err) util.HandleError(err)
activeLock.Lock()
active-- active--
activeLock.Unlock()
} }
}() }()
} }