Merge pull request #122781 from pacoxu/fix-channel-panic

kubelet: delete channel from the terminated after closing it
This commit is contained in:
Kubernetes Prow Robot
2024-09-09 04:56:27 +01:00
committed by GitHub

View File

@@ -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)
}
}