Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require --force to remove the only peer from a stream #843

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions cli/stream_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ Finding streams with certain subjects configured:
strClusterRemovePeer := strCluster.Command("peer-remove", "Removes a peer from the Stream cluster").Alias("pr").Action(c.removePeer)
strClusterRemovePeer.Arg("stream", "The stream to act on").StringVar(&c.stream)
strClusterRemovePeer.Arg("peer", "The name of the peer to remove").StringVar(&c.peerName)
strClusterRemovePeer.Flag("force", "Force sealing without prompting").Short('f').UnNegatableBoolVar(&c.force)
}

func init() {
Expand Down Expand Up @@ -647,12 +648,16 @@ func (c *streamCmd) removePeer(_ *fisk.ParseContext) error {
return fmt.Errorf("stream %q is not clustered", stream.Name())
}

if c.peerName == "" {
peerNames := []string{info.Cluster.Leader}
for _, r := range info.Cluster.Replicas {
peerNames = append(peerNames, r.Name)
}
peerNames := []string{info.Cluster.Leader}
for _, r := range info.Cluster.Replicas {
peerNames = append(peerNames, r.Name)
}

if len(peerNames) == 1 && !c.force {
return fmt.Errorf("removing the only peer on a stream will result in data loss, use --force to force")
}

if c.peerName == "" {
err = askOne(&survey.Select{
Message: "Select a Peer",
Options: peerNames,
Expand Down
Loading