@@ -74,6 +74,10 @@ func (a *Addon) Version() semver.Version {
74
74
// EnableMeshForNamespace will add the "istio-injection=enabled" label to the provided namespace
75
75
// by name which will indicate to Istio to inject sidecard pods to add it to the mesh network.
76
76
func (a * Addon ) EnableMeshForNamespace (ctx context.Context , cluster clusters.Cluster , name string ) error {
77
+ const (
78
+ namspaceWaitTime = time .Second
79
+ )
80
+
77
81
for {
78
82
select {
79
83
case <- ctx .Done ():
@@ -89,8 +93,12 @@ func (a *Addon) EnableMeshForNamespace(ctx context.Context, cluster clusters.Clu
89
93
if errors .IsConflict (err ) {
90
94
// if there's a conflict then an update happened since we pulled the namespace,
91
95
// simply pull and try again.
92
- time .Sleep (time .Second )
93
- continue
96
+ select {
97
+ case <- time .After (namspaceWaitTime ):
98
+ continue // try again if its not there yet
99
+ case <- ctx .Done ():
100
+ continue // this will return an error in the next iteration
101
+ }
94
102
}
95
103
return fmt .Errorf ("could not enable mesh for namespace %s: %w" , name , err )
96
104
}
@@ -141,6 +149,8 @@ func (a *Addon) Deploy(ctx context.Context, cluster clusters.Cluster) error {
141
149
return err
142
150
}
143
151
152
+ const jobWaitTime = time .Second
153
+
144
154
// wait for the job to complete
145
155
var deployJobCompleted bool
146
156
for ! deployJobCompleted {
@@ -155,7 +165,12 @@ func (a *Addon) Deploy(ctx context.Context, cluster clusters.Cluster) error {
155
165
if a .istioDeployJob .Status .Succeeded > 0 {
156
166
deployJobCompleted = true
157
167
} else {
158
- time .Sleep (time .Second )
168
+ select {
169
+ case <- time .After (jobWaitTime ):
170
+ continue
171
+ case <- ctx .Done ():
172
+ continue // this will return an error in the next iteration
173
+ }
159
174
}
160
175
}
161
176
}
@@ -302,8 +317,8 @@ func (a *Addon) deployExtras(ctx context.Context, cluster clusters.Cluster) erro
302
317
}
303
318
304
319
const (
305
- defaultRetries = 3
306
- defaultRetryWaitSeconds = 3
320
+ defaultRetries = 3
321
+ defaultRetryWaitTime = 3 * time . Second
307
322
)
308
323
309
324
// retryKubectlApply retries a command multiple times with a limit, and is particularly
@@ -319,8 +334,12 @@ func retryKubectlApply(ctx context.Context, args ...string) (err error) {
319
334
if err = cmd .Run (); err == nil {
320
335
break
321
336
}
322
- time .Sleep (time .Second * defaultRetryWaitSeconds )
323
- count --
337
+ select {
338
+ case <- ctx .Done ():
339
+ continue
340
+ case <- time .After (defaultRetryWaitTime ):
341
+ count --
342
+ }
324
343
}
325
344
326
345
if err != nil {
0 commit comments