Skip to content

Commit

Permalink
fix: command etcd remove-member shouldn't remove etcd data directory
Browse files Browse the repository at this point in the history
There are two APIs and `talosctl` commands:

* `etcd leave` removes the member from the cluster and removes etcd
data directory for the called node
* `etcd remove-member <node>` removes some other node from the etcd
cluster, but it doesn't affect called node state

This fixes confusing naming of the methods vs. what they're doing.

Fixes #3340

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
  • Loading branch information
smira authored and talos-bot committed Mar 22, 2021
1 parent aab49a1 commit ce795f1
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions internal/pkg/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,27 @@ func validateMemberHealth(ctx context.Context, memberURIs []string) (err error)
return c.ValidateQuorum(ctx)
}

// LeaveCluster removes the current member from the etcd cluster.
// LeaveCluster removes the current member from the etcd cluster and nukes etcd data directory.
func (c *Client) LeaveCluster(ctx context.Context) error {
hostname, err := os.Hostname()
if err != nil {
return err
}

return c.RemoveMember(ctx, hostname)
if err = c.RemoveMember(ctx, hostname); err != nil {
return err
}

if err = system.Services(nil).Stop(ctx, "etcd"); err != nil {
return fmt.Errorf("failed to stop etcd: %w", err)
}

// Once the member is removed, the data is no longer valid.
if err = os.RemoveAll(constants.EtcdDataPath); err != nil {
return fmt.Errorf("failed to remove %s: %w", constants.EtcdDataPath, err)
}

return nil
}

// RemoveMember removes the member from the etcd cluster.
Expand Down Expand Up @@ -188,15 +201,6 @@ func (c *Client) RemoveMember(ctx context.Context, hostname string) error {
return fmt.Errorf("failed to remove member %d: %w", *id, err)
}

if err = system.Services(nil).Stop(ctx, "etcd"); err != nil {
return fmt.Errorf("failed to stop etcd: %w", err)
}

// Once the member is removed, the data is no longer valid.
if err = os.RemoveAll(constants.EtcdDataPath); err != nil {
return fmt.Errorf("failed to remove %s: %w", constants.EtcdDataPath, err)
}

return nil
}

Expand Down

0 comments on commit ce795f1

Please sign in to comment.