From 436671457d65c3a9db7fd6716b6a0daf278cb2ec Mon Sep 17 00:00:00 2001 From: Pasha Sviderski Date: Fri, 19 Dec 2025 18:51:49 +1000 Subject: [PATCH] chore: pass current store DB version when adding new machine to cluster --- internal/cli/cli.go | 18 ++++++++++++++++-- pkg/client/machine.go | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/internal/cli/cli.go b/internal/cli/cli.go index aa35f22a..9fd352c1 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -333,6 +333,7 @@ func (cli *CLI) AddMachine(ctx context.Context, opts AddMachineOptions) (*client }() // Check if the machine is already initialised as a cluster member and prompt the user to reset it first. + // TODO: refactor to use client.InspectMachine. minfo, err := machineClient.Inspect(ctx, &emptypb.Empty{}) if err != nil { return nil, nil, fmt.Errorf("inspect machine: %w", err) @@ -405,6 +406,18 @@ func (cli *CLI) AddMachine(ctx context.Context, opts AddMachineOptions) (*client return nil, nil, fmt.Errorf("add machine to cluster (context '%s'): %w", contextName, err) } + // Get the current store DB version from the cluster to pass to the join request. + var storeDBVersion int64 + inspectResp, err := c.MachineClient.InspectMachine(ctx, &emptypb.Empty{}) + if err != nil { + // TODO(lhf): remove Unimplemented check when v0.17.0 is released. + if status.Convert(err).Code() != codes.Unimplemented { + return nil, nil, fmt.Errorf("inspect current cluster machine: %w", err) + } + } else { + storeDBVersion = inspectResp.Machines[0].StoreDbVersion + } + // Get the most up-to-date list of other machines in the cluster to include them in the join request. machines, err := c.ListMachines(ctx, nil) if err != nil { @@ -419,8 +432,9 @@ func (cli *CLI) AddMachine(ctx context.Context, opts AddMachineOptions) (*client // Configure the remote machine to join the cluster. joinReq := &pb.JoinClusterRequest{ - Machine: addResp.Machine, - OtherMachines: otherMachines, + Machine: addResp.Machine, + OtherMachines: otherMachines, + MinStoreDbVersion: storeDBVersion, } if _, err = machineClient.JoinCluster(ctx, joinReq); err != nil { return nil, nil, fmt.Errorf("join cluster: %w", err) diff --git a/pkg/client/machine.go b/pkg/client/machine.go index 534800a6..151c9edc 100644 --- a/pkg/client/machine.go +++ b/pkg/client/machine.go @@ -13,6 +13,7 @@ import ( ) func (cli *Client) InspectMachine(ctx context.Context, nameOrID string) (*pb.MachineMember, error) { + // TODO: refactor to use MachineClient.InspectMachine. machines, err := cli.ListMachines(ctx, nil) if err != nil { return nil, err