Merge pull request #39479 from fraenkel/podkiller

Automatic merge from submit-queue

Avoid panic when stopping the podKiller

use a mutex instead of a channel

fixes #38857
This commit is contained in:
Kubernetes Submit Queue 2017-01-06 16:02:16 -08:00 committed by GitHub
commit 0bbb49d2d5

View File

@ -29,6 +29,7 @@ import (
"runtime" "runtime"
"sort" "sort"
"strings" "strings"
"sync"
"time" "time"
"github.com/golang/glog" "github.com/golang/glog"
@ -799,8 +800,8 @@ func (kl *Kubelet) HandlePodCleanups() error {
// another goroutine isn't already in action. // another goroutine isn't already in action.
func (kl *Kubelet) podKiller() { func (kl *Kubelet) podKiller() {
killing := sets.NewString() killing := sets.NewString()
resultCh := make(chan types.UID) // guard for the killing set
defer close(resultCh) lock := sync.Mutex{}
for { for {
select { select {
case podPair, ok := <-kl.podKillingCh: case podPair, ok := <-kl.podKillingCh:
@ -811,24 +812,25 @@ func (kl *Kubelet) podKiller() {
runningPod := podPair.RunningPod runningPod := podPair.RunningPod
apiPod := podPair.APIPod apiPod := podPair.APIPod
if killing.Has(string(runningPod.ID)) { lock.Lock()
// The pod is already being killed. exists := killing.Has(string(runningPod.ID))
break if !exists {
killing.Insert(string(runningPod.ID))
} }
killing.Insert(string(runningPod.ID)) lock.Unlock()
go func(apiPod *v1.Pod, runningPod *kubecontainer.Pod, ch chan types.UID) {
defer func() {
ch <- runningPod.ID
}()
glog.V(2).Infof("Killing unwanted pod %q", runningPod.Name)
err := kl.killPod(apiPod, runningPod, nil, nil)
if err != nil {
glog.Errorf("Failed killing the pod %q: %v", runningPod.Name, err)
}
}(apiPod, runningPod, resultCh)
case podID := <-resultCh: if !exists {
killing.Delete(string(podID)) go func(apiPod *v1.Pod, runningPod *kubecontainer.Pod) {
glog.V(2).Infof("Killing unwanted pod %q", runningPod.Name)
err := kl.killPod(apiPod, runningPod, nil, nil)
if err != nil {
glog.Errorf("Failed killing the pod %q: %v", runningPod.Name, err)
}
lock.Lock()
killing.Delete(string(runningPod.ID))
lock.Unlock()
}(apiPod, runningPod)
}
} }
} }
} }