Skip to content

Commit

Permalink
cluster: Improve cluster restart messaging (#2442)
Browse files Browse the repository at this point in the history
Cluster restart messaging indicates to user that the:
  - Cluster will be unavailable
    (https://github.com/pingcap/tiup/blob/654b087a1d293128424c0bd04e1ba216b064ffd1/pkg/cluster/manager/basic.go#L235)

This message is confusing when the command run only requests a single
node restart, especially monitoring nodes or ones in an HA deployment.

Commit changes the messaging so that users performing full cluster
restart retain the same message as before. But users only restarting
selected nodes or roles will have that replaced with a more detailed warning message:

`Cluster functionality related to nodes: %s and roles: % will be
unavailable`
  • Loading branch information
zph committed Jul 22, 2024
1 parent 654b087 commit 8d7cb71
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions pkg/cluster/manager/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,26 @@ func (m *Manager) RestartCluster(name string, gOpt operator.Options, skipConfirm
}

if !skipConfirm {
if err := tui.PromptForConfirmOrAbortError(
fmt.Sprintf("Will restart the cluster %s with nodes: %s roles: %s.\nCluster will be unavailable\nDo you want to continue? [y/N]:",
color.HiYellowString(name),
color.HiYellowString(strings.Join(gOpt.Nodes, ",")),
color.HiYellowString(strings.Join(gOpt.Roles, ",")),
),
); err != nil {
var availabilityMessage string
var rolesToRestart string
var nodesToRestart string
if len(gOpt.Nodes) == 0 && len(gOpt.Roles) == 0 {
availabilityMessage = "Cluster will be unavailable"
rolesToRestart = "all"
nodesToRestart = "all"
} else {
availabilityMessage = fmt.Sprintf("Cluster functionality related to nodes: %s roles: %s will be unavailable", strings.Join(gOpt.Nodes, ","), strings.Join(gOpt.Roles, ","))
nodesToRestart = strings.Join(gOpt.Nodes, ",")
rolesToRestart = strings.Join(gOpt.Roles, ",")
}

confirmationMessage := fmt.Sprintf("Will restart the cluster %s with nodes: %s roles: %s.\n%s\nDo you want to continue? [y/N]:",
color.HiYellowString(name),
color.HiYellowString(nodesToRestart),
color.HiYellowString(rolesToRestart),
availabilityMessage,
)
if err := tui.PromptForConfirmOrAbortError(confirmationMessage); err != nil {
return err
}
}
Expand Down

0 comments on commit 8d7cb71

Please sign in to comment.