@@ -6,8 +6,10 @@ package cmd
6
6
7
7
import (
8
8
"context"
9
+ "crypto/tls"
9
10
"fmt"
10
11
"net"
12
+ "net/http"
11
13
"strconv"
12
14
"strings"
13
15
"time"
@@ -164,7 +166,7 @@ func (r *PodReconciler) Reconcile(ctx context.Context, req reconcile.Request) (r
164
166
component string
165
167
labelToUpdate string
166
168
167
- waitTimeout time.Duration = 1 * time .Second
169
+ waitTimeout time.Duration = 5 * time .Second
168
170
)
169
171
170
172
switch {
@@ -173,8 +175,6 @@ func (r *PodReconciler) Reconcile(ctx context.Context, req reconcile.Request) (r
173
175
labelToUpdate = fmt .Sprintf (registryFacadeLabel , namespace )
174
176
ipAddress = pod .Status .HostIP
175
177
port = strconv .Itoa (registryFacadePort )
176
- // wait for kube-proxy sync to avoid connection refused due to missing nodeport rules
177
- waitTimeout = 15 * time .Second
178
178
case strings .HasPrefix (pod .Name , wsDaemon ):
179
179
component = wsDaemon
180
180
labelToUpdate = fmt .Sprintf (wsdaemonLabel , namespace )
@@ -197,7 +197,7 @@ func (r *PodReconciler) Reconcile(ctx context.Context, req reconcile.Request) (r
197
197
return reconcile.Result {}, nil
198
198
}
199
199
200
- log .WithError (err ).Error ("unexpected error removing node label" )
200
+ log .WithError (err ).Error ("removing node label" )
201
201
return reconcile.Result {RequeueAfter : time .Second * 10 }, err
202
202
}
203
203
@@ -206,14 +206,13 @@ func (r *PodReconciler) Reconcile(ctx context.Context, req reconcile.Request) (r
206
206
207
207
if ! IsPodReady (& pod ) {
208
208
// not ready. Wait until the next update.
209
- log .WithField ("pod" , pod .Name ).Info ("pod is not yet ready" )
210
209
return reconcile.Result {}, nil
211
210
}
212
211
213
212
var node corev1.Node
214
213
err = r .Get (ctx , types.NamespacedName {Name : nodeName }, & node )
215
214
if err != nil {
216
- return reconcile.Result {}, fmt .Errorf ("failed to get node %s: %w" , nodeName , err )
215
+ return reconcile.Result {}, fmt .Errorf ("obtaining node %s: %w" , nodeName , err )
217
216
}
218
217
219
218
if node .Labels [labelToUpdate ] == "true" {
@@ -223,14 +222,22 @@ func (r *PodReconciler) Reconcile(ctx context.Context, req reconcile.Request) (r
223
222
224
223
err = waitForTCPPortToBeReachable (ipAddress , port , 30 * time .Second )
225
224
if err != nil {
226
- return reconcile.Result {}, fmt .Errorf ("Unexpected error waiting for probe URL: %v" , err )
225
+ return reconcile.Result {}, fmt .Errorf ("waiting for TCP port: %v" , err )
226
+ }
227
+
228
+ if component == registryFacade {
229
+ err = checkRegistryFacade (ipAddress , port )
230
+ if err != nil {
231
+ log .WithError (err ).Error ("checking registry-facade" )
232
+ return reconcile.Result {RequeueAfter : time .Second * 10 }, nil
233
+ }
227
234
}
228
235
229
236
time .Sleep (waitTimeout )
230
237
231
238
err = updateLabel (labelToUpdate , true , nodeName , r )
232
239
if err != nil {
233
- return reconcile.Result {}, fmt .Errorf ("Unexpected error while trying to add the label: %v" , err )
240
+ return reconcile.Result {}, fmt .Errorf ("trying to add the label: %v" , err )
234
241
}
235
242
236
243
readyIn := time .Since (pod .Status .StartTime .Time )
@@ -299,3 +306,48 @@ func waitForTCPPortToBeReachable(host string, port string, timeout time.Duration
299
306
}
300
307
}
301
308
}
309
+
310
+ func checkRegistryFacade (host , port string ) error {
311
+ transport := newDefaultTransport ()
312
+ transport .TLSClientConfig = & tls.Config {
313
+ InsecureSkipVerify : true ,
314
+ }
315
+
316
+ client := & http.Client {
317
+ Transport : transport ,
318
+ }
319
+
320
+ dummyURL := fmt .Sprintf ("https://%v:%v/v2/remote/not-a-valid-image/manifests/latest" , host , port )
321
+ req , err := http .NewRequest (http .MethodGet , dummyURL , nil )
322
+ if err != nil {
323
+ return fmt .Errorf ("building HTTP request: %v" , err )
324
+ }
325
+
326
+ req .Header .Set ("Accept" , "application/vnd.oci.image.manifest.v1+json, application/vnd.oci.image.index.v1+json" )
327
+ resp , err := client .Do (req )
328
+ if err != nil {
329
+ return fmt .Errorf ("unexpected error during HTTP request: %v" , err )
330
+ }
331
+ resp .Body .Close ()
332
+
333
+ if resp .StatusCode == http .StatusNotFound {
334
+ return nil
335
+ }
336
+
337
+ return fmt .Errorf ("registry-facade is not ready yet" )
338
+ }
339
+
340
+ func newDefaultTransport () * http.Transport {
341
+ return & http.Transport {
342
+ DialContext : (& net.Dialer {
343
+ Timeout : 1 * time .Second ,
344
+ KeepAlive : 1 * time .Second ,
345
+ DualStack : false ,
346
+ }).DialContext ,
347
+ MaxIdleConns : 0 ,
348
+ MaxIdleConnsPerHost : 1 ,
349
+ IdleConnTimeout : 5 * time .Second ,
350
+ ExpectContinueTimeout : 5 * time .Second ,
351
+ DisableKeepAlives : true ,
352
+ }
353
+ }
0 commit comments