github.com/openshift/installer@v1.4.17/cmd/openshift-install/waitfor.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"path/filepath"
     6  
     7  	"github.com/pkg/errors"
     8  	"github.com/sirupsen/logrus"
     9  	"github.com/spf13/cobra"
    10  	"k8s.io/client-go/tools/clientcmd"
    11  
    12  	"github.com/openshift/installer/cmd/openshift-install/command"
    13  	timer "github.com/openshift/installer/pkg/metrics/timer"
    14  )
    15  
    16  func newWaitForCmd() *cobra.Command {
    17  	cmd := &cobra.Command{
    18  		Use:   "wait-for",
    19  		Short: "Wait for install-time events",
    20  		Long: `Wait for install-time events.
    21  
    22  'create cluster' has a few stages that wait for cluster events.  But
    23  these waits can also be useful on their own.  This subcommand exposes
    24  them directly.`,
    25  		RunE: func(cmd *cobra.Command, args []string) error {
    26  			return cmd.Help()
    27  		},
    28  	}
    29  	cmd.AddCommand(newWaitForBootstrapCompleteCmd())
    30  	cmd.AddCommand(newWaitForInstallCompleteCmd())
    31  	return cmd
    32  }
    33  
    34  func newWaitForBootstrapCompleteCmd() *cobra.Command {
    35  	return &cobra.Command{
    36  		Use:   "bootstrap-complete",
    37  		Short: "Wait until cluster bootstrapping has completed",
    38  		Args:  cobra.ExactArgs(0),
    39  		Run: func(_ *cobra.Command, _ []string) {
    40  			timer.StartTimer(timer.TotalTimeElapsed)
    41  			ctx := context.Background()
    42  
    43  			cleanup := command.SetupFileHook(command.RootOpts.Dir)
    44  			defer cleanup()
    45  
    46  			config, err := clientcmd.BuildConfigFromFlags("", filepath.Join(command.RootOpts.Dir, "auth", "kubeconfig"))
    47  			if err != nil {
    48  				logrus.Fatal(errors.Wrap(err, "loading kubeconfig"))
    49  			}
    50  			timer.StartTimer("Bootstrap Complete")
    51  			if err := waitForBootstrapComplete(ctx, config); err != nil {
    52  				if err2 := logClusterOperatorConditions(ctx, config); err2 != nil {
    53  					logrus.Error("Attempted to gather ClusterOperator status after wait failure: ", err2)
    54  				}
    55  
    56  				logrus.Info("Use the following commands to gather logs from the cluster")
    57  				logrus.Info("openshift-install gather bootstrap --help")
    58  				logrus.Error("Bootstrap failed to complete: ", err.Unwrap())
    59  				logrus.Error(err.Error())
    60  				logrus.Exit(exitCodeBootstrapFailed)
    61  			}
    62  
    63  			logrus.Info("It is now safe to remove the bootstrap resources")
    64  			timer.StopTimer("Bootstrap Complete")
    65  			timer.StopTimer(timer.TotalTimeElapsed)
    66  			timer.LogSummary()
    67  		},
    68  	}
    69  }
    70  
    71  func newWaitForInstallCompleteCmd() *cobra.Command {
    72  	return &cobra.Command{
    73  		Use:   "install-complete",
    74  		Short: "Wait until the cluster is ready",
    75  		Args:  cobra.ExactArgs(0),
    76  		Run: func(cmd *cobra.Command, args []string) {
    77  			timer.StartTimer(timer.TotalTimeElapsed)
    78  			ctx := context.Background()
    79  
    80  			cleanup := command.SetupFileHook(command.RootOpts.Dir)
    81  			defer cleanup()
    82  
    83  			config, err := clientcmd.BuildConfigFromFlags("", filepath.Join(command.RootOpts.Dir, "auth", "kubeconfig"))
    84  			if err != nil {
    85  				logrus.Fatal(errors.Wrap(err, "loading kubeconfig"))
    86  			}
    87  
    88  			err = waitForInstallComplete(ctx, config, command.RootOpts.Dir)
    89  			if err != nil {
    90  				if err2 := logClusterOperatorConditions(ctx, config); err2 != nil {
    91  					logrus.Error("Attempted to gather ClusterOperator status after wait failure: ", err2)
    92  				}
    93  				logTroubleshootingLink()
    94  				logrus.Error(err)
    95  				logrus.Exit(exitCodeInstallFailed)
    96  			}
    97  			timer.StopTimer(timer.TotalTimeElapsed)
    98  			timer.LogSummary()
    99  		},
   100  	}
   101  }