diff --git a/pkg/kubecfg/kubecfg.go b/pkg/kubecfg/kubecfg.go index 40cae52294a..35e836e0303 100644 --- a/pkg/kubecfg/kubecfg.go +++ b/pkg/kubecfg/kubecfg.go @@ -29,6 +29,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" + "github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait" "github.com/GoogleCloudPlatform/kubernetes/pkg/version" "github.com/golang/glog" "gopkg.in/v1/yaml" @@ -93,6 +94,10 @@ func Update(name string, client client.Interface, updatePeriod time.Duration) er if err != nil { return err } + expected := len(podList.Items) + if expected == 0 { + return nil + } for _, pod := range podList.Items { // We delete the pod here, the controller will recreate it. This will result in pulling // a new Docker image. This isn't a full "update" but it's what we support for now. @@ -102,7 +107,13 @@ func Update(name string, client client.Interface, updatePeriod time.Duration) er } time.Sleep(updatePeriod) } - return nil + return wait.Poll(time.Second*5, 60 /* timeout after 300 seconds */, func() (bool, error) { + podList, err := client.ListPods(s) + if err != nil { + return false, err + } + return len(podList.Items) == expected, nil + }) } // StopController stops a controller named 'name' by setting replicas to zero diff --git a/pkg/kubecfg/kubecfg_test.go b/pkg/kubecfg/kubecfg_test.go index 8c5696fea43..b08d2663cb8 100644 --- a/pkg/kubecfg/kubecfg_test.go +++ b/pkg/kubecfg/kubecfg_test.go @@ -44,7 +44,7 @@ func TestUpdateWithPods(t *testing.T) { }, } Update("foo", &fakeClient, 0) - if len(fakeClient.Actions) != 4 { + if len(fakeClient.Actions) != 5 { t.Errorf("Unexpected action list %#v", fakeClient.Actions) } validateAction(client.FakeAction{Action: "get-controller", Value: "foo"}, fakeClient.Actions[0], t) @@ -52,6 +52,7 @@ func TestUpdateWithPods(t *testing.T) { // Update deletes the pods, it relies on the replication controller to replace them. validateAction(client.FakeAction{Action: "delete-pod", Value: "pod-1"}, fakeClient.Actions[2], t) validateAction(client.FakeAction{Action: "delete-pod", Value: "pod-2"}, fakeClient.Actions[3], t) + validateAction(client.FakeAction{Action: "list-pods"}, fakeClient.Actions[4], t) } func TestUpdateNoPods(t *testing.T) {