// checkStatus returns an error if the cluster is degraded.
checkStatus returns an error if the cluster is degraded.
// checkStatus returns an error if the cluster is degraded .
func checkStatus(ctx context.Context, env *localenv.LocalEnvironment, ignoreWarnings bool) error {
	operator, err := env.SiteOperator()
	if err != nil {
		return trace.Wrap(err)
	}
	cluster, err := operator.GetLocalSite(ctx)
	if err != nil {
		return trace.Wrap(err)
	}
	status, err := statusapi.FromCluster(ctx, operator, *cluster, "")
	if err != nil {
		return trace.Wrap(err)
	}
	var failedProbes []string
	var warningProbes []string
	for _, node := range status.Agent.Nodes {
		failedProbes = append(failedProbes, node.FailedProbes...)
		warningProbes = append(warningProbes, node.WarnProbes...)
	}
	w := new(tabwriter.Writer)
	w.Init(os.Stdout, 0, 8, 1, '\t', 0)
	if len(failedProbes) > 0 {
		fmt.Println("The upgrade is prohibited because some cluster nodes are currently degraded.")
		printAgentStatus(*status.Agent, w)
		if err := w.Flush(); err != nil {
			log.WithError(err).Warn("Failed to flush to stdout.")
		}
		fmt.Println("Please make sure the cluster is healthy before re-attempting the upgrade.")
		return trace.BadParameter("failed to start upgrade operation")
	}
	if len(warningProbes) > 0 {
		if ignoreWarnings {
			log.WithField("nodes", status.Agent).Info("Upgrade forced with active warnings.")
			return nil
		}
		fmt.Println("Some cluster nodes have active warnings:")
		printAgentStatus(*status.Agent, w)
		if err := w.Flush(); err != nil {
			log.WithError(err).Warn("Failed to flush to stdout.")
		}
		fmt.Println("You can provide the --force flag to suppress this message and launch the upgrade anyways.")
		return trace.BadParameter("failed to start upgrade operation")
	}
	return nil
}
func checkStatus ( ctx context . Context , env * localenv . LocalEnvironment , ignoreWarnings bool ) error { operator , err := env . SiteOperator ( ) if err != nil { return trace . Wrap ( err ) } cluster , err := operator . GetLocalSite ( ctx ) if err != nil { return trace . Wrap ( err ) } status , err := statusapi . FromCluster ( ctx , operator , * cluster , " " ) if err != nil { return trace . Wrap ( err ) } var failedProbes [ ] string var warningProbes [ ] string for _ , node := range status . Agent . Nodes { failedProbes = append ( failedProbes , node . FailedProbes ... ) warningProbes = append ( warningProbes , node . WarnProbes ... ) } w := new ( tabwriter . Writer ) w . Init ( os . Stdout , 0 , 8 , 1 , '\t' , 0 ) if len ( failedProbes ) > 0 { fmt . Println ( " " ) printAgentStatus ( * status . Agent , w ) if err := w . Flush ( ) ; err != nil { log . WithError ( err ) . Warn ( " " ) } fmt . Println ( " " ) return trace . BadParameter ( " " ) } if len ( warningProbes ) > 0 { if ignoreWarnings { log . WithField ( " " , status . Agent ) . Info ( " " ) return nil } fmt . Println ( " " ) printAgentStatus ( * status . Agent , w ) if err := w . Flush ( ) ; err != nil { log . WithError ( err ) . Warn ( " " ) } fmt . Println ( " " ) return trace . BadParameter ( " " ) } return nil }
checkStatus returns an error if the cluster is degraded.
checkStatus returns an error if the cluster is degraded .