mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-07 04:03:20 +00:00
Merge pull request #122781 from pacoxu/fix-channel-panic
kubelet: delete channel from the terminated after closing it
This commit is contained in:
@@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package kuberuntime
|
package kuberuntime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
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
|
// prereqs is a map from container name to a list of channel that the container
|
||||||
// must wait on to ensure termination ordering
|
// must wait on to ensure termination ordering
|
||||||
prereqs map[string][]chan struct{}
|
prereqs map[string][]chan struct{}
|
||||||
|
|
||||||
|
lock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// newTerminationOrdering constructs a terminationOrdering based on the pod spec and the currently running containers.
|
// 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()
|
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) {
|
func (o *terminationOrdering) containerTerminated(name string) {
|
||||||
|
o.lock.Lock()
|
||||||
|
defer o.lock.Unlock()
|
||||||
if ch, ok := o.terminated[name]; ok {
|
if ch, ok := o.terminated[name]; ok {
|
||||||
close(ch)
|
close(ch)
|
||||||
|
delete(o.terminated, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user