From ecea8a2cf1ae04b55e625140651c0e9856c26c1a Mon Sep 17 00:00:00 2001 From: Nick Van Wiggeren Date: Tue, 31 Mar 2026 13:09:45 +0000 Subject: [PATCH] Add list-tablets command to pscale branch vtctld Adds `pscale branch vtctld list-tablets ` which lists tablets grouped by keyspace and shard, showing each tablet's alias, role, and cell. This lets users discover tablet aliases needed for operations like planned-reparent-shard. Updates planetscale-go to v0.160.0 for ListTablets support. --- go.mod | 2 +- go.sum | 4 +- internal/cmd/branch/vtctld/list_tablets.go | 45 ++++++++++++++++++++++ internal/cmd/branch/vtctld/vtctld.go | 1 + internal/mock/vtctld_general.go | 8 ++++ 5 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 internal/cmd/branch/vtctld/list_tablets.go diff --git a/go.mod b/go.mod index 8e21e860..b46a6f64 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( github.com/mattn/go-shellwords v1.0.12 github.com/mitchellh/go-homedir v1.1.0 github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c - github.com/planetscale/planetscale-go v0.159.0 + github.com/planetscale/planetscale-go v0.160.0 github.com/planetscale/psdb v0.0.0-20250717190954-65c6661ab6e4 github.com/planetscale/psdbproxy v0.0.0-20250728082226-3f4ea3a74ec7 github.com/spf13/cobra v1.10.2 diff --git a/go.sum b/go.sum index 6220a740..b54b7ced 100644 --- a/go.sum +++ b/go.sum @@ -176,8 +176,8 @@ github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjL github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/planetscale/noglog v0.2.1-0.20210421230640-bea75fcd2e8e h1:MZ8D+Z3m2vvqGZLvoQfpaGg/j1fNDr4j03s3PRz4rVY= github.com/planetscale/noglog v0.2.1-0.20210421230640-bea75fcd2e8e/go.mod h1:hwAsSPQdvPa3WcfKfzTXxtEq/HlqwLjQasfO6QbGo4Q= -github.com/planetscale/planetscale-go v0.159.0 h1:qqyZjG/z5k/w5gihfSwxssVu+mIsRTKqXFIeVJa/7hI= -github.com/planetscale/planetscale-go v0.159.0/go.mod h1:paQCI5SgquuoewvMQM7R+r1XJO868bdP6/ihGidYRM0= +github.com/planetscale/planetscale-go v0.160.0 h1:nWgTrMJPk+FzV71OV+wKU17F6DCnSX0lHxHSUH6Yhn0= +github.com/planetscale/planetscale-go v0.160.0/go.mod h1:paQCI5SgquuoewvMQM7R+r1XJO868bdP6/ihGidYRM0= github.com/planetscale/psdb v0.0.0-20250717190954-65c6661ab6e4 h1:Xv5pj20Rhfty1Tv0OVcidg4ez4PvGrpKvb6rvUwQgDs= github.com/planetscale/psdb v0.0.0-20250717190954-65c6661ab6e4/go.mod h1:M52h5IWxAcbdQ1hSZrLAGQC4ZXslxEsK/Wh9nu3wdWs= github.com/planetscale/psdbproxy v0.0.0-20250728082226-3f4ea3a74ec7 h1:aRd6vdE1fyuSI4RVj7oCr8lFmgqXvpnPUmN85VbZCp8= diff --git a/internal/cmd/branch/vtctld/list_tablets.go b/internal/cmd/branch/vtctld/list_tablets.go new file mode 100644 index 00000000..f76a4701 --- /dev/null +++ b/internal/cmd/branch/vtctld/list_tablets.go @@ -0,0 +1,45 @@ +package vtctld + +import ( + "fmt" + + "github.com/planetscale/cli/internal/cmdutil" + ps "github.com/planetscale/planetscale-go/planetscale" + "github.com/spf13/cobra" +) + +func ListTabletsCmd(ch *cmdutil.Helper) *cobra.Command { + cmd := &cobra.Command{ + Use: "list-tablets ", + Short: "List tablets for a branch, grouped by keyspace and shard", + Args: cmdutil.RequiredArgs("database", "branch"), + RunE: func(cmd *cobra.Command, args []string) error { + ctx := cmd.Context() + database, branch := args[0], args[1] + + client, err := ch.Client() + if err != nil { + return err + } + + end := ch.Printer.PrintProgress( + fmt.Sprintf("Listing tablets on %s\u2026", + progressTarget(ch.Config.Organization, database, branch))) + defer end() + + groups, err := client.Vtctld.ListTablets(ctx, &ps.ListBranchTabletsRequest{ + Organization: ch.Config.Organization, + Database: database, + Branch: branch, + }) + if err != nil { + return cmdutil.HandleError(err) + } + + end() + return ch.Printer.PrintJSON(groups) + }, + } + + return cmd +} diff --git a/internal/cmd/branch/vtctld/vtctld.go b/internal/cmd/branch/vtctld/vtctld.go index 26a1331c..9ccf01a9 100644 --- a/internal/cmd/branch/vtctld/vtctld.go +++ b/internal/cmd/branch/vtctld/vtctld.go @@ -20,6 +20,7 @@ func VtctldCmd(ch *cmdutil.Helper) *cobra.Command { cmd.AddCommand(PlannedReparentShardCmd(ch)) cmd.AddCommand(ListWorkflowsCmd(ch)) cmd.AddCommand(ListKeyspacesCmd(ch)) + cmd.AddCommand(ListTabletsCmd(ch)) cmd.AddCommand(StartWorkflowCmd(ch)) cmd.AddCommand(StopWorkflowCmd(ch)) diff --git a/internal/mock/vtctld_general.go b/internal/mock/vtctld_general.go index 3a71f5f5..fe94b8d4 100644 --- a/internal/mock/vtctld_general.go +++ b/internal/mock/vtctld_general.go @@ -14,6 +14,9 @@ type VtctldService struct { ListKeyspacesFn func(context.Context, *ps.VtctldListKeyspacesRequest) (json.RawMessage, error) ListKeyspacesFnInvoked bool + ListTabletsFn func(context.Context, *ps.ListBranchTabletsRequest) ([]*ps.TabletGroup, error) + ListTabletsFnInvoked bool + StartWorkflowFn func(context.Context, *ps.VtctldStartWorkflowRequest) (json.RawMessage, error) StartWorkflowFnInvoked bool @@ -34,6 +37,11 @@ func (s *VtctldService) ListKeyspaces(ctx context.Context, req *ps.VtctldListKey return s.ListKeyspacesFn(ctx, req) } +func (s *VtctldService) ListTablets(ctx context.Context, req *ps.ListBranchTabletsRequest) ([]*ps.TabletGroup, error) { + s.ListTabletsFnInvoked = true + return s.ListTabletsFn(ctx, req) +} + func (s *VtctldService) StartWorkflow(ctx context.Context, req *ps.VtctldStartWorkflowRequest) (json.RawMessage, error) { s.StartWorkflowFnInvoked = true return s.StartWorkflowFn(ctx, req)