Skip to content

Commit

Permalink
Merge pull request #843 from ripienaar/r1_peer_remove_warn
Browse files Browse the repository at this point in the history
require --force to remove the only peer from a stream
  • Loading branch information
ripienaar authored Aug 14, 2023
2 parents 11b9165 + f5a72ac commit 0cc2c45
Showing 1 changed file with 10 additions and 5 deletions.
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

0 comments on commit 0cc2c45

Please sign in to comment.