Skip to content

Commit 670308e

Browse files
committed
1
Signed-off-by: Manuel de Brito Fontes <[email protected]>
1 parent 454d502 commit 670308e

File tree

1 file changed

+13
-31
lines changed
  • components/node-labeler/cmd

1 file changed

+13
-31
lines changed

components/node-labeler/cmd/run.go

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ func (r *PodReconciler) Reconcile(ctx context.Context, req reconcile.Request) (r
160160
port string
161161
component string
162162
labelToUpdate string
163-
164-
waitTimeout time.Duration = 5 * time.Second
165163
)
166164

167165
switch {
@@ -210,14 +208,15 @@ func (r *PodReconciler) Reconcile(ctx context.Context, req reconcile.Request) (r
210208
return reconcile.Result{}, fmt.Errorf("obtaining node %s: %w", nodeName, err)
211209
}
212210

213-
if node.Labels[labelToUpdate] == "true" {
214-
// Label already exists.
211+
if labelValue, exists := node.Labels[labelToUpdate]; exists && labelValue == "true" {
212+
// label already exists.
215213
return reconcile.Result{}, nil
216214
}
217215

218-
err = waitForTCPPortToBeReachable(ipAddress, port, 30*time.Second)
216+
err = checkTCPPortIsReachable(ipAddress, port)
219217
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
221220
}
222221

223222
if component == registryFacade {
@@ -228,7 +227,7 @@ func (r *PodReconciler) Reconcile(ctx context.Context, req reconcile.Request) (r
228227
}
229228
}
230229

231-
time.Sleep(waitTimeout)
230+
time.Sleep(5 * time.Second)
232231

233232
err = updateLabel(labelToUpdate, true, nodeName, r)
234233
if err != nil {
@@ -275,31 +274,14 @@ func updateLabel(label string, add bool, nodeName string, client client.Client)
275274
})
276275
}
277276

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
302281
}
282+
defer conn.Close()
283+
284+
return nil
303285
}
304286

305287
func checkRegistryFacade(host, port string) error {

0 commit comments

Comments
 (0)