Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid panic when stopping the podKiller #39479

Merged
merged 1 commit into from
Jan 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions pkg/kubelet/kubelet_pods.go
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"runtime" "runtime"
"sort" "sort"
"strings" "strings"
"sync"
"time" "time"


"github.com/golang/glog" "github.com/golang/glog"
Expand Down Expand Up @@ -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{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add a one-line comment explaining that the mutex is used to guard the mutation of the killing set.

for { for {
select { select {
case podPair, ok := <-kl.podKillingCh: case podPair, ok := <-kl.podKillingCh:
Expand All @@ -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)
}
} }
} }
} }
Expand Down