@@ -16,6 +16,7 @@ import (
16
16
apierrors "k8s.io/apimachinery/pkg/api/errors"
17
17
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18
18
"k8s.io/apimachinery/pkg/fields"
19
+ utilerrors "k8s.io/apimachinery/pkg/util/errors"
19
20
"k8s.io/apimachinery/pkg/util/wait"
20
21
"k8s.io/apimachinery/pkg/watch"
21
22
"k8s.io/client-go/kubernetes"
@@ -370,7 +371,7 @@ func waitForInitializedCluster(ctx context.Context, config *rest.Config) error {
370
371
}
371
372
372
373
// waitForConsole returns the console URL from the route 'console' in namespace openshift-console
373
- func waitForConsole (ctx context.Context , config * rest.Config , directory string ) (string , error ) {
374
+ func waitForConsole (ctx context.Context , config * rest.Config , directory string , oneShot bool ) (string , error ) {
374
375
url := ""
375
376
// Need to keep these updated if they change
376
377
consoleNamespace := "openshift-console"
@@ -381,9 +382,13 @@ func waitForConsole(ctx context.Context, config *rest.Config, directory string)
381
382
}
382
383
383
384
consoleRouteTimeout := 10 * time .Minute
384
- logrus .Infof ("Waiting up to %v for the openshift-console route to be created..." , consoleRouteTimeout )
385
385
consoleRouteContext , cancel := context .WithTimeout (ctx , consoleRouteTimeout )
386
386
defer cancel ()
387
+ if oneShot {
388
+ logrus .Infof ("Checking for the %s route..." , consoleNamespace )
389
+ } else {
390
+ logrus .Infof ("Waiting up to %v for the %s route to be created..." , consoleRouteTimeout , consoleNamespace )
391
+ }
387
392
// Poll quickly but only log when the response
388
393
// when we've seen 15 of the same errors or output of
389
394
// no route in a row (to show we're still alive).
@@ -393,39 +398,40 @@ func waitForConsole(ctx context.Context, config *rest.Config, directory string)
393
398
consoleRoutes , err := rc .RouteV1 ().Routes (consoleNamespace ).List (metav1.ListOptions {})
394
399
if err == nil && len (consoleRoutes .Items ) > 0 {
395
400
for _ , route := range consoleRoutes .Items {
396
- logrus .Debugf ("Route found in openshift-console namespace: %s" , route .Name )
401
+ logrus .Debugf ("Route found in %s namespace: %s" , consoleNamespace , route .Name )
397
402
if route .Name == consoleRouteName {
398
403
url = fmt .Sprintf ("https://%s" , route .Spec .Host )
399
404
}
400
405
}
401
406
logrus .Debug ("OpenShift console route is created" )
402
407
cancel ()
403
- } else if err != nil {
404
- silenceRemaining --
405
- if silenceRemaining == 0 {
406
- logrus .Debugf ("Still waiting for the console route: %v" , err )
407
- silenceRemaining = logDownsample
408
- }
409
- } else if len (consoleRoutes .Items ) == 0 {
410
- silenceRemaining --
411
- if silenceRemaining == 0 {
412
- logrus .Debug ("Still waiting for the console route..." )
413
- silenceRemaining = logDownsample
408
+ return
409
+ }
410
+ silenceRemaining --
411
+ if silenceRemaining == 0 {
412
+ silenceRemaining = logDownsample
413
+ if err == nil {
414
+ logrus .Debugf ("Still waiting for the %s route..." , consoleRouteName )
415
+ } else {
416
+ logrus .Debugf ("Still waiting for the %s route: %v" , consoleRouteName , err )
414
417
}
415
418
}
419
+ if oneShot {
420
+ cancel ()
421
+ }
416
422
}, 2 * time .Second , consoleRouteContext .Done ())
417
423
err = consoleRouteContext .Err ()
418
424
if err != nil && err != context .Canceled {
419
- return url , errors .Wrap (err , "waiting for openshift-console URL" )
425
+ return url , errors .Wrapf (err , "waiting for the %s route" , consoleNamespace )
420
426
}
421
427
if url == "" {
422
- return url , errors .New ("could not get openshift-console URL" )
428
+ return url , errors .Errorf ("could not get the %s route" , consoleNamespace )
423
429
}
424
430
return url , nil
425
431
}
426
432
427
433
// logComplete prints info upon completion
428
- func logComplete (directory , consoleURL string ) error {
434
+ func logComplete (config * rest. Config , directory , consoleURL string , complete bool ) error {
429
435
absDir , err := filepath .Abs (directory )
430
436
if err != nil {
431
437
return err
@@ -436,26 +442,36 @@ func logComplete(directory, consoleURL string) error {
436
442
if err != nil {
437
443
return err
438
444
}
439
- logrus .Info ("Install complete!" )
445
+ if complete {
446
+ logrus .Info ("Install complete!" )
447
+ }
440
448
logrus .Infof ("To access the cluster as the system:admin user when using 'oc', run 'export KUBECONFIG=%s'" , kubeconfig )
441
- logrus .Infof ("Access the OpenShift web-console here: %s" , consoleURL )
442
- logrus .Infof ("Login to the console with user: kubeadmin, password: %s" , pw )
449
+ if consoleURL != "" {
450
+ logrus .Infof ("Access the OpenShift web-console here: %s" , consoleURL )
451
+ logrus .Infof ("Login to the console with user: kubeadmin, password: %s" , pw )
452
+ }
443
453
return nil
444
454
}
445
455
446
456
func waitForInstallComplete (ctx context.Context , config * rest.Config , directory string ) error {
447
- if err := waitForInitializedCluster (ctx , config ); err != nil {
448
- return err
457
+ errs := []error {}
458
+ err := waitForInitializedCluster (ctx , config )
459
+ if err != nil {
460
+ errs = append (errs , err )
449
461
}
450
462
451
- consoleURL , err := waitForConsole (ctx , config , rootOpts .dir )
463
+ consoleURL , err := waitForConsole (ctx , config , rootOpts .dir , err != nil )
452
464
if err != nil {
453
- return err
465
+ errs = append ( errs , err )
454
466
}
455
467
456
468
if err = addRouterCAToClusterCA (config , rootOpts .dir ); err != nil {
457
- return err
469
+ errs = append (errs , err )
470
+ }
471
+
472
+ if err = logComplete (config , rootOpts .dir , consoleURL , utilerrors .NewAggregate (errs ) == nil ); err != nil {
473
+ errs = append (errs , err )
458
474
}
459
475
460
- return logComplete ( rootOpts . dir , consoleURL )
476
+ return utilerrors . NewAggregate ( errs )
461
477
}
0 commit comments