From 7208d91c410faacbb1d7af3de5f7d6c8c4f9646f Mon Sep 17 00:00:00 2001 From: Diego Pontoriero Date: Tue, 24 Oct 2017 12:30:53 -0700 Subject: [PATCH] agent: deserialize waitForPodDeletion check. This adds a sync.WaitGroup to check all pods concurrently and avoid erroneously extended grace periods. --- pkg/agent/agent.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/pkg/agent/agent.go b/pkg/agent/agent.go index 35e360f7..20a6a9f2 100644 --- a/pkg/agent/agent.go +++ b/pkg/agent/agent.go @@ -2,6 +2,7 @@ package agent import ( "fmt" + "sync" "time" "github.com/coreos/go-systemd/login1" @@ -162,12 +163,19 @@ func (k *Klocksmith) process(stop <-chan struct{}) error { } } + // wait for the pods to delete completely. + wg := sync.WaitGroup{} for _, pod := range pods { - glog.Infof("Waiting for pod %q to terminate", pod.Name) - if err := k.waitForPodDeletion(pod); err != nil { - glog.Errorf("Skipping wait on pod %q: %v", pod.Name, err) - } - } + wg.Add(1) + go func(pod v1.Pod) { + glog.Infof("Waiting for pod %q to terminate", pod.Name) + if err := k.waitForPodDeletion(pod); err != nil { + glog.Errorf("Skipping wait on pod %q: %v", pod.Name, err) + } + wg.Done() + }(pod) + } + wg.Wait() glog.Info("Node drained, rebooting")