@@ -6,12 +6,15 @@ import (
6
6
"time"
7
7
8
8
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9
+ "k8s.io/apimachinery/pkg/util/wait"
9
10
10
11
appscmd "github.com/openshift/origin/pkg/apps/cmd"
11
12
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
12
13
newproject "github.com/openshift/origin/pkg/oc/admin/project"
13
14
)
14
15
16
+ const podGoneTimeout = 30 // seconds to wait for previous app pods to disappear
17
+
15
18
func (d * AppCreate ) prepareForApp () bool {
16
19
defer func () {
17
20
d .result .PrepDuration = jsonDuration (time .Since (time .Time (d .result .BeginTime )))
@@ -101,17 +104,20 @@ func (d *AppCreate) cleanupApp() {
101
104
102
105
func (d * AppCreate ) waitForPodGone () bool {
103
106
d .out .Debug ("DCluAC045" , fmt .Sprintf ("%s: Waiting to ensure any previous pod for '%s' is gone." , now (), d .appName ))
104
- for timeout := 30 ; timeout > 0 ; timeout -- {
107
+ err := wait . PollImmediate ( time . Second , time . Duration ( podGoneTimeout ) * time . Second , func () ( bool , error ) {
105
108
pods , err := d .KubeClient .Core ().Pods (d .project ).List (metav1.ListOptions {LabelSelector : d .labelSelector })
106
- if err != nil {
107
- d .out .Error ("DCluAC046" , err , fmt .Sprintf ("%s: Error on checking for previous app pod:\n %v" , now (), err ))
108
- return false
109
- }
110
- if len (pods .Items ) == 0 {
111
- return true
109
+ if err == nil && len (pods .Items ) == 0 {
110
+ return true , nil
112
111
}
113
- time .Sleep (time .Second )
112
+ return false , err
113
+ })
114
+ switch err {
115
+ case nil :
116
+ return true
117
+ case wait .ErrWaitTimeout :
118
+ d .out .Error ("DCluAC046" , err , fmt .Sprintf ("%s: Previous app pod still present after %ds" , now (), podGoneTimeout ))
119
+ default :
120
+ d .out .Error ("DCluAC047" , err , fmt .Sprintf ("%s: Error while checking for previous app pod:\n %v" , now (), err ))
114
121
}
115
- d .out .Error ("DCluAC047" , nil , fmt .Sprintf ("%s: Previous app pod still present after 30s" , now ()))
116
122
return false
117
123
}
0 commit comments