Skip to content

Commit 3585a93

Browse files
committed
cmd/openshift-install/create: Make waitForInstallComplete() more robust
If the cluster failed to completely initialize, we may still have a router CA or console URL. With this commit, errors in finalization components are no longer immediately fatal; instead we hold any errors but continue to try the later components. We retain the first component component error, and log any later errors. To avoid waiting on a console URL when the cluster failed to initialize, I've added a oneShot argument to waitForConsole. When waitForInitializedCluster failed, we set oneShot true and only make a single attempt to resolve the console URL. I've also shuffled around the Until function to flatten some of its previous if/else blocks so I only have to add single oneShot-cancel block. Tangentially related, addRouterCAToClusterCA is idempotent, because AppendCertsFromPEM wraps AddCert [1] and AddCert checks to avoid duplicate certificates [2]. [1]: https://github.com/golang/go/blob/go1.12/src/crypto/x509/cert_pool.go#L144 [2]: https://github.com/golang/go/blob/go1.12/src/crypto/x509/cert_pool.go#L106-L109
1 parent b50ff5e commit 3585a93

File tree

1 file changed

+42
-26
lines changed

1 file changed

+42
-26
lines changed

cmd/openshift-install/create.go

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
apierrors "k8s.io/apimachinery/pkg/api/errors"
1717
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1818
"k8s.io/apimachinery/pkg/fields"
19+
utilerrors "k8s.io/apimachinery/pkg/util/errors"
1920
"k8s.io/apimachinery/pkg/util/wait"
2021
"k8s.io/apimachinery/pkg/watch"
2122
"k8s.io/client-go/kubernetes"
@@ -370,7 +371,7 @@ func waitForInitializedCluster(ctx context.Context, config *rest.Config) error {
370371
}
371372

372373
// 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) {
374375
url := ""
375376
// Need to keep these updated if they change
376377
consoleNamespace := "openshift-console"
@@ -381,9 +382,13 @@ func waitForConsole(ctx context.Context, config *rest.Config, directory string)
381382
}
382383

383384
consoleRouteTimeout := 10 * time.Minute
384-
logrus.Infof("Waiting up to %v for the openshift-console route to be created...", consoleRouteTimeout)
385385
consoleRouteContext, cancel := context.WithTimeout(ctx, consoleRouteTimeout)
386386
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+
}
387392
// Poll quickly but only log when the response
388393
// when we've seen 15 of the same errors or output of
389394
// 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)
393398
consoleRoutes, err := rc.RouteV1().Routes(consoleNamespace).List(metav1.ListOptions{})
394399
if err == nil && len(consoleRoutes.Items) > 0 {
395400
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)
397402
if route.Name == consoleRouteName {
398403
url = fmt.Sprintf("https://%s", route.Spec.Host)
399404
}
400405
}
401406
logrus.Debug("OpenShift console route is created")
402407
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)
414417
}
415418
}
419+
if oneShot {
420+
cancel()
421+
}
416422
}, 2*time.Second, consoleRouteContext.Done())
417423
err = consoleRouteContext.Err()
418424
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)
420426
}
421427
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)
423429
}
424430
return url, nil
425431
}
426432

427433
// logComplete prints info upon completion
428-
func logComplete(directory, consoleURL string) error {
434+
func logComplete(config *rest.Config, directory, consoleURL string, complete bool) error {
429435
absDir, err := filepath.Abs(directory)
430436
if err != nil {
431437
return err
@@ -436,26 +442,36 @@ func logComplete(directory, consoleURL string) error {
436442
if err != nil {
437443
return err
438444
}
439-
logrus.Info("Install complete!")
445+
if complete {
446+
logrus.Info("Install complete!")
447+
}
440448
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+
}
443453
return nil
444454
}
445455

446456
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)
449461
}
450462

451-
consoleURL, err := waitForConsole(ctx, config, rootOpts.dir)
463+
consoleURL, err := waitForConsole(ctx, config, rootOpts.dir, err != nil)
452464
if err != nil {
453-
return err
465+
errs = append(errs, err)
454466
}
455467

456468
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)
458474
}
459475

460-
return logComplete(rootOpts.dir, consoleURL)
476+
return utilerrors.NewAggregate(errs)
461477
}

0 commit comments

Comments
 (0)