Skip to content

Commit

Permalink
chore: drop deprecated method EtcdRemoveMember
Browse files Browse the repository at this point in the history
It was deprecated 16 months ago, time to cleanup.

(This is to prepare for the first v1.7 release)

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
  • Loading branch information
smira committed Feb 1, 2024
1 parent 17567f1 commit 9d8cd4d
Show file tree
Hide file tree
Showing 11 changed files with 278 additions and 423 deletions.
Binary file modified api/api.descriptors
Binary file not shown.
6 changes: 0 additions & 6 deletions api/machine/machine.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ service MachineService {
rpc Dmesg(DmesgRequest) returns (stream common.Data);
rpc Events(EventsRequest) returns (stream Event);
rpc EtcdMemberList(EtcdMemberListRequest) returns (EtcdMemberListResponse);
// EtcdRemoveMember removes a member from the etcd cluster by hostname.
// Please use EtcdRemoveMemberByID instead.
rpc EtcdRemoveMember(EtcdRemoveMemberRequest) returns (EtcdRemoveMemberResponse) {
option (common.remove_deprecated_method) = "v1.7";
option deprecated = true;
}
// EtcdRemoveMemberByID removes a member from the etcd cluster identified by member ID.
// This API should be used to remove members which don't have an associated Talos node anymore.
// To remove a member with a running Talos node, use EtcdLeaveCluster API on the node to be removed.
Expand Down
24 changes: 7 additions & 17 deletions cmd/talosctl/cmd/talos/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/siderolabs/gen/xslices"
"github.com/spf13/cobra"
snapshot "go.etcd.io/etcd/etcdutl/v3/snapshot"
"google.golang.org/grpc/codes"

"github.com/siderolabs/talos/cmd/talosctl/pkg/talos/helpers"
"github.com/siderolabs/talos/pkg/cli"
Expand Down Expand Up @@ -162,30 +161,21 @@ var etcdLeaveCmd = &cobra.Command{
}

var etcdMemberRemoveCmd = &cobra.Command{
Use: "remove-member <member ID>|<hostname>",
Use: "remove-member <member ID>",
Short: "Remove the node from etcd cluster",
Long: `Use this command only if you want to remove a member which is in broken state.
If there is no access to the node, or the node can't access etcd to call etcd leave.
Always prefer etcd leave over this command.
It's always better to use member ID than hostname, as hostname might not be set consistently.`,
Always prefer etcd leave over this command.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return WithClient(func(ctx context.Context, c *client.Client) error {
// first, try to parse argument as member ID
if memberID, err := etcdresource.ParseMemberID(args[0]); err == nil {
err = c.EtcdRemoveMemberByID(ctx, &machine.EtcdRemoveMemberByIDRequest{
MemberId: memberID,
})

// in the unlikely event that the hostname parses as member ID, try to proceed with remove by hostname
if client.StatusCode(err) != codes.NotFound {
return err
}
memberID, err := etcdresource.ParseMemberID(args[0])
if err != nil {
return fmt.Errorf("error parsing member ID: %w", err)
}

// try to remove by hostname
return c.EtcdRemoveMember(ctx, &machine.EtcdRemoveMemberRequest{ //nolint:staticcheck // deprecated method, remove in v1.7
Member: args[0],
return c.EtcdRemoveMemberByID(ctx, &machine.EtcdRemoveMemberByIDRequest{
MemberId: memberID,
})
})
},
Expand Down
26 changes: 0 additions & 26 deletions internal/app/machined/internal/server/v1alpha1/v1alpha1_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1730,32 +1730,6 @@ func (s *Server) EtcdMemberList(ctx context.Context, in *machine.EtcdMemberListR
}, nil
}

// EtcdRemoveMember implements the machine.MachineServer interface.
func (s *Server) EtcdRemoveMember(ctx context.Context, in *machine.EtcdRemoveMemberRequest) (*machine.EtcdRemoveMemberResponse, error) {
if err := s.checkControlplane("etcd remove member"); err != nil {
return nil, err
}

client, err := etcd.NewClientFromControlPlaneIPs(ctx, s.Controller.Runtime().State().V1Alpha2().Resources())
if err != nil {
return nil, fmt.Errorf("failed to create etcd client: %w", err)
}

defer client.Close() //nolint:errcheck

ctx = clientv3.WithRequireLeader(ctx)

if err = client.RemoveMemberByHostname(ctx, in.Member); err != nil { //nolint:staticcheck // deprecated, remove in v1.7
return nil, fmt.Errorf("failed to remove member: %w", err)
}

return &machine.EtcdRemoveMemberResponse{
Messages: []*machine.EtcdRemoveMember{
{},
},
}, nil
}

// EtcdRemoveMemberByID implements the machine.MachineServer interface.
func (s *Server) EtcdRemoveMemberByID(ctx context.Context, in *machine.EtcdRemoveMemberByIDRequest) (*machine.EtcdRemoveMemberByIDResponse, error) {
if err := s.checkControlplane("etcd remove member"); err != nil {
Expand Down
1 change: 0 additions & 1 deletion internal/app/machined/pkg/system/services/machined.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ var rules = map[string]role.Set{
"/machine.MachineService/EtcdLeaveCluster": role.MakeSet(role.Admin),
"/machine.MachineService/EtcdMemberList": role.MakeSet(role.Admin, role.Operator, role.Reader),
"/machine.MachineService/EtcdRecover": role.MakeSet(role.Admin),
"/machine.MachineService/EtcdRemoveMember": role.MakeSet(role.Admin),
"/machine.MachineService/EtcdRemoveMemberByID": role.MakeSet(role.Admin),
"/machine.MachineService/EtcdSnapshot": role.MakeSet(role.Admin, role.Operator, role.EtcdBackup),
"/machine.MachineService/EtcdStatus": role.MakeSet(role.Admin, role.Operator),
Expand Down
34 changes: 0 additions & 34 deletions internal/pkg/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,40 +199,6 @@ func (c *Client) GetMemberID(ctx context.Context) (uint64, error) {
return resp.Header.MemberId, nil
}

func (c *Client) getMemberIDByHostname(ctx context.Context, hostname string) (uint64, error) {
resp, err := c.MemberList(ctx)
if err != nil {
return 0, err
}

for _, member := range resp.Members {
if member.Name == hostname {
member := member

return member.ID, nil
}
}

return 0, fmt.Errorf("could not get member ID for hostname %q", hostname)
}

// RemoveMemberByHostname removes the member from the etcd cluster.
//
// Deprecated: use RemoveMemberByMemberID instead.
func (c *Client) RemoveMemberByHostname(ctx context.Context, hostname string) error {
id, err := c.getMemberIDByHostname(ctx, hostname)
if err != nil {
return err
}

err = c.RemoveMemberByMemberID(ctx, id)
if err != nil {
return fmt.Errorf("failed to remove member %d: %w", id, err)
}

return nil
}

// RemoveMemberByMemberID removes the member from the etcd cluster.
func (c *Client) RemoveMemberByMemberID(ctx context.Context, memberID uint64) error {
_, err := c.MemberRemove(ctx, memberID)
Expand Down
Loading

0 comments on commit 9d8cd4d

Please sign in to comment.