diff --git a/pkg/kubelet/kuberuntime/kuberuntime_termination_order.go b/pkg/kubelet/kuberuntime/kuberuntime_termination_order.go index 0e8a2a6adf8..21fff12d46d 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_termination_order.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_termination_order.go @@ -17,6 +17,7 @@ limitations under the License. package kuberuntime import ( + "sync" "time" v1 "k8s.io/api/core/v1" @@ -34,6 +35,8 @@ type terminationOrdering struct { // prereqs is a map from container name to a list of channel that the container // must wait on to ensure termination ordering prereqs map[string][]chan struct{} + + lock sync.Mutex } // newTerminationOrdering constructs a terminationOrdering based on the pod spec and the currently running containers. @@ -114,9 +117,12 @@ func (o *terminationOrdering) waitForTurn(name string, gracePeriod int64) float6 return time.Since(start).Seconds() } -// containerTerminated should be called once the container with the speecified name has exited. +// containerTerminated should be called once the container with the specified name has exited. func (o *terminationOrdering) containerTerminated(name string) { + o.lock.Lock() + defer o.lock.Unlock() if ch, ok := o.terminated[name]; ok { close(ch) + delete(o.terminated, name) } }