Skip to content

Commit

Permalink
reuse polling function
Browse files Browse the repository at this point in the history
  • Loading branch information
sosiouxme committed Jan 23, 2018
1 parent e5c0a59 commit 672f41c
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import (
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"

appscmd "github.com/openshift/origin/pkg/apps/cmd"
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
newproject "github.com/openshift/origin/pkg/oc/admin/project"
)

const podGoneTimeout = 30 // seconds to wait for previous app pods to disappear

func (d *AppCreate) prepareForApp() bool {
defer func() {
d.result.PrepDuration = jsonDuration(time.Since(time.Time(d.result.BeginTime)))
Expand Down Expand Up @@ -101,17 +104,20 @@ func (d *AppCreate) cleanupApp() {

func (d *AppCreate) waitForPodGone() bool {
d.out.Debug("DCluAC045", fmt.Sprintf("%s: Waiting to ensure any previous pod for '%s' is gone.", now(), d.appName))
for timeout := 30; timeout > 0; timeout-- {
err := wait.PollImmediate(time.Second, time.Duration(podGoneTimeout)*time.Second, func() (bool, error) {
pods, err := d.KubeClient.Core().Pods(d.project).List(metav1.ListOptions{LabelSelector: d.labelSelector})
if err != nil {
d.out.Error("DCluAC046", err, fmt.Sprintf("%s: Error on checking for previous app pod:\n%v", now(), err))
return false
}
if len(pods.Items) == 0 {
return true
if err == nil && len(pods.Items) == 0 {
return true, nil
}
time.Sleep(time.Second)
return false, err
})
switch err {
case nil:
return true
case wait.ErrWaitTimeout:
d.out.Error("DCluAC046", err, fmt.Sprintf("%s: Previous app pod still present after %ds", now(), podGoneTimeout))
default:
d.out.Error("DCluAC047", err, fmt.Sprintf("%s: Error while checking for previous app pod:\n%v", now(), err))
}
d.out.Error("DCluAC047", nil, fmt.Sprintf("%s: Previous app pod still present after 30s", now()))
return false
}

0 comments on commit 672f41c

Please sign in to comment.