5
5
"crypto/x509"
6
6
"fmt"
7
7
"io/ioutil"
8
+ "os"
8
9
"path/filepath"
9
10
"strings"
10
11
"time"
@@ -317,17 +318,18 @@ func waitForBootstrapConfigMap(ctx context.Context, client *kubernetes.Clientset
317
318
318
319
// waitForInitializedCluster watches the ClusterVersion waiting for confirmation
319
320
// that the cluster has been initialized.
320
- func waitForInitializedCluster (ctx context.Context , config * rest.Config ) error {
321
+ func waitForInitializedCluster (ctx context.Context , config * rest.Config ) (configv1.ClusterStatusConditionType , error ) {
322
+ failing := configv1 .ClusterStatusConditionType ("Failing" )
323
+ status := failing
321
324
timeout := 30 * time .Minute
322
325
logrus .Infof ("Waiting up to %v for the cluster at %s to initialize..." , timeout , config .Host )
323
326
cc , err := configclient .NewForConfig (config )
324
327
if err != nil {
325
- return errors .Wrap (err , "failed to create a config client" )
328
+ return status , errors .Wrap (err , "failed to create a config client" )
326
329
}
327
330
clusterVersionContext , cancel := context .WithTimeout (ctx , timeout )
328
331
defer cancel ()
329
332
330
- failing := configv1 .ClusterStatusConditionType ("Failing" )
331
333
var lastError string
332
334
_ , err = clientwatch .UntilWithSync (
333
335
clusterVersionContext ,
@@ -343,11 +345,14 @@ func waitForInitializedCluster(ctx context.Context, config *rest.Config) error {
343
345
return false , nil
344
346
}
345
347
if cov1helpers .IsStatusConditionTrue (cv .Status .Conditions , configv1 .OperatorAvailable ) {
348
+ status = configv1 .OperatorAvailable
346
349
return true , nil
347
350
}
348
351
if cov1helpers .IsStatusConditionTrue (cv .Status .Conditions , failing ) {
352
+ status = failing
349
353
lastError = cov1helpers .FindStatusCondition (cv .Status .Conditions , failing ).Message
350
354
} else if cov1helpers .IsStatusConditionTrue (cv .Status .Conditions , configv1 .OperatorProgressing ) {
355
+ status = configv1 .OperatorProgressing
351
356
lastError = cov1helpers .FindStatusCondition (cv .Status .Conditions , configv1 .OperatorProgressing ).Message
352
357
}
353
358
logrus .Debugf ("Still waiting for the cluster to initialize: %s" , lastError )
@@ -360,14 +365,17 @@ func waitForInitializedCluster(ctx context.Context, config *rest.Config) error {
360
365
361
366
if err == nil {
362
367
logrus .Debug ("Cluster is initialized" )
363
- return nil
368
+ return status , nil
364
369
}
365
370
366
371
if lastError != "" {
367
- return errors .Wrapf (err , "failed to initialize the cluster: %s" , lastError )
372
+ if status == configv1 .OperatorProgressing {
373
+ return status , errors .Wrapf (err , "the cluster is still initializing: %s" , lastError )
374
+ }
375
+ return status , errors .Wrapf (err , "failed to initialize the cluster: %s" , lastError )
368
376
}
369
377
370
- return errors .Wrap (err , "failed to initialize the cluster" )
378
+ return status , errors .Wrap (err , "failed to initialize the cluster" )
371
379
}
372
380
373
381
// waitForConsole returns the console URL from the route 'console' in namespace openshift-console
@@ -431,7 +439,7 @@ func waitForConsole(ctx context.Context, config *rest.Config, directory string,
431
439
}
432
440
433
441
// logComplete prints info upon completion
434
- func logComplete (config * rest.Config , directory , consoleURL string , complete bool ) error {
442
+ func logComplete (config * rest.Config , directory string , clusterStatus configv1. ClusterStatusConditionType , consoleURL string , complete bool ) error {
435
443
absDir , err := filepath .Abs (directory )
436
444
if err != nil {
437
445
return err
@@ -444,8 +452,10 @@ func logComplete(config *rest.Config, directory, consoleURL string, complete boo
444
452
}
445
453
if complete {
446
454
logrus .Info ("Install complete!" )
455
+ logrus .Infof ("To access the cluster as the system:admin user when using 'oc', run 'export KUBECONFIG=%s'" , kubeconfig )
456
+ } else if clusterStatus == configv1 .OperatorProgressing {
457
+ logrus .Infof ("To give the cluster more time to initialize, you can run '%s wait-for install-complete'." , os .Args [0 ])
447
458
}
448
- logrus .Infof ("To access the cluster as the system:admin user when using 'oc', run 'export KUBECONFIG=%s'" , kubeconfig )
449
459
if consoleURL != "" {
450
460
logrus .Infof ("Access the OpenShift web-console here: %s" , consoleURL )
451
461
logrus .Infof ("Login to the console with user: kubeadmin, password: %s" , pw )
@@ -455,7 +465,7 @@ func logComplete(config *rest.Config, directory, consoleURL string, complete boo
455
465
456
466
func waitForInstallComplete (ctx context.Context , config * rest.Config , directory string ) error {
457
467
errs := []error {}
458
- err := waitForInitializedCluster (ctx , config )
468
+ clusterStatus , err := waitForInitializedCluster (ctx , config )
459
469
if err != nil {
460
470
errs = append (errs , err )
461
471
}
@@ -469,7 +479,7 @@ func waitForInstallComplete(ctx context.Context, config *rest.Config, directory
469
479
errs = append (errs , err )
470
480
}
471
481
472
- if err = logComplete (config , rootOpts .dir , consoleURL , utilerrors .NewAggregate (errs ) == nil ); err != nil {
482
+ if err = logComplete (config , rootOpts .dir , clusterStatus , consoleURL , utilerrors .NewAggregate (errs ) == nil ); err != nil {
473
483
errs = append (errs , err )
474
484
}
475
485
0 commit comments