Skip to content

Commit 9fb2685

Browse files
committed
Requeue instead of waiting 0.blocking
Signed-off-by: Manuel de Brito Fontes <[email protected]>
1 parent b115922 commit 9fb2685

File tree

1 file changed

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

1 file changed

+17
-31
lines changed

components/node-labeler/cmd/run.go

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ func (r *PodReconciler) Reconcile(ctx context.Context, req reconcile.Request) (r
226226
}
227227

228228
if component == registryFacade {
229-
err = waitForRegistryFacade(ipAddress, port, 30*time.Second)
229+
err = checkegistryFacade(ipAddress, port)
230230
if err != nil {
231-
return reconcile.Result{}, fmt.Errorf("waiting for registry-facade: %v", err)
231+
return reconcile.Result{RequeueAfter: time.Second * 10}, err
232232
}
233233
}
234234

@@ -306,13 +306,7 @@ func waitForTCPPortToBeReachable(host string, port string, timeout time.Duration
306306
}
307307
}
308308

309-
func waitForRegistryFacade(host, port string, timeout time.Duration) error {
310-
ctx, cancel := context.WithTimeout(context.Background(), timeout)
311-
defer cancel()
312-
313-
ticker := time.NewTicker(1 * time.Second)
314-
defer ticker.Stop()
315-
309+
func checkRegistryFacade(host, port string) error {
316310
transport := newDefaultTransport()
317311
transport.TLSClientConfig = &tls.Config{
318312
InsecureSkipVerify: true,
@@ -323,31 +317,23 @@ func waitForRegistryFacade(host, port string, timeout time.Duration) error {
323317
}
324318

325319
dummyURL := fmt.Sprintf("https://%v:%v/v2/remote/not-a-valid-image/manifests/latest", host, port)
320+
req, err := http.NewRequest(http.MethodGet, dummyURL, nil)
321+
if err != nil {
322+
return fmt.Errorf("unexpected error building HTTP request: %v", err)
323+
}
326324

327-
for {
328-
select {
329-
case <-ctx.Done():
330-
return fmt.Errorf("port %v on host %v never reachable", port, host)
331-
case <-ticker.C:
332-
req, err := http.NewRequest(http.MethodGet, dummyURL, nil)
333-
if err != nil {
334-
log.WithError(err).Error("unexpected error building HTTP request")
335-
continue
336-
}
337-
338-
req.Header.Set("Accept", "application/vnd.oci.image.manifest.v1+json, application/vnd.oci.image.index.v1+json")
339-
resp, err := client.Do(req)
340-
if err != nil {
341-
log.WithError(err).Error("unexpected error during HTTP request")
342-
continue
343-
}
344-
resp.Body.Close()
325+
req.Header.Set("Accept", "application/vnd.oci.image.manifest.v1+json, application/vnd.oci.image.index.v1+json")
326+
resp, err := client.Do(req)
327+
if err != nil {
328+
return fmt.Errorf("unexpected error during HTTP request: %v", err)
329+
}
330+
resp.Body.Close()
345331

346-
if resp.StatusCode == http.StatusNotFound {
347-
return nil
348-
}
349-
}
332+
if resp.StatusCode == http.StatusNotFound {
333+
return nil
350334
}
335+
336+
return fmt.Errorf("registry-facade is not ready yet")
351337
}
352338

353339
func newDefaultTransport() *http.Transport {

0 commit comments

Comments
 (0)