Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make vtctldclient mount command more standard #14281

Merged
merged 4 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions go/cmd/vtctldclient/command/vreplication/mount/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
)

var (
// mount is the base command for all actions related to the mount action.
mount = &cobra.Command{
// base is the base command for all actions related to the mount action.
base = &cobra.Command{
Use: "Mount [command] [command-flags]",
Short: "Mount is used to link an external Vitess cluster in order to migrate data from it.",
DisableFlagsInUseLine: true,
Expand All @@ -40,6 +40,7 @@ var (
)

var mountOptions struct {
Name string
TopoType string
TopoServer string
TopoRoot string
Expand All @@ -48,7 +49,7 @@ var mountOptions struct {
var register = &cobra.Command{
Use: "register",
Short: "Register an external Vitess Cluster.",
Example: `vtctldclient --server localhost:15999 mount register --topo-type etcd2 --topo-server localhost:12379 --topo-root /vitess/global ext1`,
Example: `vtctldclient --server localhost:15999 mount register --name ext1 --topo-type etcd2 --topo-server localhost:12379 --topo-root /vitess/global`,
DisableFlagsInUseLine: true,
Aliases: []string{"Register"},
Args: cobra.ExactArgs(1),
Expand All @@ -59,10 +60,10 @@ func commandRegister(cmd *cobra.Command, args []string) error {
cli.FinishedParsing(cmd)

req := &vtctldatapb.MountRegisterRequest{
Name: mountOptions.Name,
TopoType: mountOptions.TopoType,
TopoServer: mountOptions.TopoServer,
TopoRoot: mountOptions.TopoRoot,
Name: cmd.Flags().Arg(0),
}
_, err := common.GetClient().MountRegister(common.GetCommandCtx(), req)
if err != nil {
Expand All @@ -75,7 +76,7 @@ func commandRegister(cmd *cobra.Command, args []string) error {
var unregister = &cobra.Command{
Use: "unregister",
Short: "Unregister a previously mounted external Vitess Cluster.",
Example: `vtctldclient --server localhost:15999 mount unregister ext1`,
Example: `vtctldclient --server localhost:15999 mount unregister --name ext1`,
DisableFlagsInUseLine: true,
Aliases: []string{"Unregister"},
Args: cobra.ExactArgs(1),
Expand All @@ -99,7 +100,7 @@ func commandUnregister(cmd *cobra.Command, args []string) error {
var show = &cobra.Command{
Use: "show",
Short: "Show attributes of a previously mounted external Vitess Cluster.",
Example: `vtctldclient --server localhost:15999 Mount Show ext1`,
Example: `vtctldclient --server localhost:15999 mount show --name ext1`,
DisableFlagsInUseLine: true,
Aliases: []string{"Show"},
Args: cobra.ExactArgs(1),
Expand Down Expand Up @@ -154,21 +155,27 @@ func commandList(cmd *cobra.Command, args []string) error {
}

func registerCommands(root *cobra.Command) {
root.AddCommand(mount)
addRegisterFlags(register)
mount.AddCommand(register)
mount.AddCommand(unregister)
mount.AddCommand(show)
mount.AddCommand(list)
}

func addRegisterFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&mountOptions.TopoType, "topo-type", "", "Topo server implementation to use.")
cmd.Flags().StringVar(&mountOptions.TopoServer, "topo-server", "", "Topo server address.")
cmd.Flags().StringVar(&mountOptions.TopoRoot, "topo-root", "", "Topo server root path.")
cmd.MarkFlagRequired("topo-type")
cmd.MarkFlagRequired("topo-server")
cmd.MarkFlagRequired("topo-root")
root.AddCommand(base)

register.Flags().StringVar(&mountOptions.Name, "name", "", "Name to use for the mount.")
register.MarkFlagRequired("name")
register.Flags().StringVar(&mountOptions.TopoType, "topo-type", "", "Topo server implementation to use.")
register.MarkFlagRequired("topo-type")
register.Flags().StringVar(&mountOptions.TopoServer, "topo-server", "", "Topo server address.")
register.MarkFlagRequired("topo-server")
register.Flags().StringVar(&mountOptions.TopoRoot, "topo-root", "", "Topo server root path.")
register.MarkFlagRequired("topo-root")
base.AddCommand(register)

unregister.Flags().StringVar(&mountOptions.Name, "name", "", "Name of the mount.")
unregister.MarkFlagRequired("name")
base.AddCommand(unregister)

show.Flags().StringVar(&mountOptions.Name, "name", "", "Name of the mount.")
show.MarkFlagRequired("name")
base.AddCommand(show)

base.AddCommand(list)
}

func init() {
Expand Down
14 changes: 7 additions & 7 deletions go/test/endtoend/vreplication/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,17 @@ func TestVtctldMigrate(t *testing.T) {
var output, expected string

t.Run("mount external cluster", func(t *testing.T) {
output, err := vc.VtctldClient.ExecuteCommandWithOutput("Mount", "Register", "--topo-type=etcd2",
fmt.Sprintf("--topo-server=localhost:%d", extVc.ClusterConfig.topoPort), "--topo-root=/vitess/global", "ext1")
output, err := vc.VtctldClient.ExecuteCommandWithOutput("Mount", "register", "--name=ext1", "--topo-type=etcd2",
fmt.Sprintf("--topo-server=localhost:%d", extVc.ClusterConfig.topoPort), "--topo-root=/vitess/global")
require.NoError(t, err, "Mount Register command failed with %s", output)

output, err = vc.VtctldClient.ExecuteCommandWithOutput("Mount", "List")
output, err = vc.VtctldClient.ExecuteCommandWithOutput("Mount", "list")
require.NoError(t, err, "Mount List command failed with %s", output)

names := gjson.Get(output, "names")
require.Equal(t, 1, len(names.Array()))
require.Equal(t, "ext1", names.Array()[0].String())
output, err = vc.VtctldClient.ExecuteCommandWithOutput("Mount", "Show", "ext1")
output, err = vc.VtctldClient.ExecuteCommandWithOutput("Mount", "show", "--name=ext1")
require.NoError(t, err, "Mount command failed with %s\n", output)

require.Equal(t, "etcd2", gjson.Get(output, "topo_type").String())
Expand Down Expand Up @@ -302,15 +302,15 @@ func TestVtctldMigrate(t *testing.T) {
})

t.Run("unmount external cluster", func(t *testing.T) {
output, err = vc.VtctldClient.ExecuteCommandWithOutput("Mount", "Unregister", "ext1")
output, err = vc.VtctldClient.ExecuteCommandWithOutput("Mount", "unregister", "--name=ext1")
require.NoError(t, err, "Mount command failed with %s\n", output)

output, err = vc.VtctldClient.ExecuteCommandWithOutput("Mount", "List")
output, err = vc.VtctldClient.ExecuteCommandWithOutput("Mount", "list")
require.NoError(t, err, "Mount command failed with %+v : %s\n", output)
expected = "{}\n"
require.Equal(t, expected, output)

output, err = vc.VtctldClient.ExecuteCommandWithOutput("Mount", "Show", "ext1")
output, err = vc.VtctldClient.ExecuteCommandWithOutput("Mount", "show", "--name=ext1")
require.Errorf(t, err, "there is no vitess cluster named ext1")
})
}
Loading