@@ -160,8 +160,6 @@ func (r *PodReconciler) Reconcile(ctx context.Context, req reconcile.Request) (r
160
160
port string
161
161
component string
162
162
labelToUpdate string
163
-
164
- waitTimeout time.Duration = 5 * time .Second
165
163
)
166
164
167
165
switch {
@@ -210,14 +208,15 @@ func (r *PodReconciler) Reconcile(ctx context.Context, req reconcile.Request) (r
210
208
return reconcile.Result {}, fmt .Errorf ("obtaining node %s: %w" , nodeName , err )
211
209
}
212
210
213
- if node .Labels [labelToUpdate ] == "true" {
214
- // Label already exists.
211
+ if labelValue , exists := node .Labels [labelToUpdate ]; exists && labelValue == "true" {
212
+ // label already exists.
215
213
return reconcile.Result {}, nil
216
214
}
217
215
218
- err = waitForTCPPortToBeReachable (ipAddress , port , 30 * time . Second )
216
+ err = checkTCPPortIsReachable (ipAddress , port )
219
217
if err != nil {
220
- return reconcile.Result {}, fmt .Errorf ("waiting for TCP port: %v" , err )
218
+ log .WithField ("host" , ipAddress ).WithField ("port" , port ).WithField ("component" , component ).WithError (err ).Error ("checking TCP port is open" )
219
+ return reconcile.Result {RequeueAfter : time .Second * 5 }, nil
221
220
}
222
221
223
222
if component == registryFacade {
@@ -228,7 +227,7 @@ func (r *PodReconciler) Reconcile(ctx context.Context, req reconcile.Request) (r
228
227
}
229
228
}
230
229
231
- time .Sleep (waitTimeout )
230
+ time .Sleep (5 * time . Second )
232
231
233
232
err = updateLabel (labelToUpdate , true , nodeName , r )
234
233
if err != nil {
@@ -275,31 +274,14 @@ func updateLabel(label string, add bool, nodeName string, client client.Client)
275
274
})
276
275
}
277
276
278
- func waitForTCPPortToBeReachable (host string , port string , timeout time.Duration ) error {
279
- ctx , cancel := context .WithTimeout (context .Background (), timeout )
280
- defer cancel ()
281
-
282
- ticker := time .NewTicker (1 * time .Second )
283
- defer ticker .Stop ()
284
-
285
- for {
286
- select {
287
- case <- ctx .Done ():
288
- return fmt .Errorf ("port %v on host %v never reachable" , port , host )
289
- case <- ticker .C :
290
- conn , err := net .DialTimeout ("tcp" , net .JoinHostPort (host , port ), 500 * time .Millisecond )
291
- if err != nil {
292
- continue
293
- }
294
-
295
- if conn != nil {
296
- conn .Close ()
297
- return nil
298
- }
299
-
300
- continue
301
- }
277
+ func checkTCPPortIsReachable (host string , port string ) error {
278
+ conn , err := net .DialTimeout ("tcp" , net .JoinHostPort (host , port ), 1 * time .Second )
279
+ if err != nil {
280
+ return err
302
281
}
282
+ defer conn .Close ()
283
+
284
+ return nil
303
285
}
304
286
305
287
func checkRegistryFacade (host , port string ) error {
0 commit comments