From 22550bb2749f76604194c4c648e81d64888ef71a Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Wed, 12 Feb 2025 09:28:00 +0100 Subject: [PATCH] Fix vtcombo parsing flags incorrectly (#17743) Signed-off-by: Dirkjan Bussink --- go/cmd/vtcombo/cli/main.go | 18 +++++++++--------- go/cmd/vtctldclient/command/root.go | 21 ++++++++++----------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/go/cmd/vtcombo/cli/main.go b/go/cmd/vtcombo/cli/main.go index 5f27e581a24..52e29044268 100644 --- a/go/cmd/vtcombo/cli/main.go +++ b/go/cmd/vtcombo/cli/main.go @@ -126,15 +126,6 @@ func init() { // user know about this flag. Main.Flags().MarkHidden("tablet_protocol") - var err error - env, err = vtenv.New(vtenv.Options{ - MySQLServerVersion: servenv.MySQLServerVersion(), - TruncateUILen: servenv.TruncateUILen, - TruncateErrLen: servenv.TruncateErrLen, - }) - if err != nil { - log.Fatalf("unable to initialize env: %v", err) - } srvTopoCounts = stats.NewCountersWithSingleLabel("ResilientSrvTopoServer", "Resilient srvtopo server operations", "type") } @@ -189,6 +180,15 @@ func run(cmd *cobra.Command, args []string) (err error) { cmd.Flags().Set("log_dir", "$VTDATAROOT/tmp") } + env, err = vtenv.New(vtenv.Options{ + MySQLServerVersion: servenv.MySQLServerVersion(), + TruncateUILen: servenv.TruncateUILen, + TruncateErrLen: servenv.TruncateErrLen, + }) + if err != nil { + log.Fatalf("unable to initialize env: %v", err) + } + ctx, cancel := context.WithCancel(cmd.Context()) defer cancel() if externalTopoServer { diff --git a/go/cmd/vtctldclient/command/root.go b/go/cmd/vtctldclient/command/root.go index 3ebe019f94d..b998c8711a7 100644 --- a/go/cmd/vtctldclient/command/root.go +++ b/go/cmd/vtctldclient/command/root.go @@ -29,7 +29,6 @@ import ( "github.com/spf13/cobra" "vitess.io/vitess/go/trace" - "vitess.io/vitess/go/vt/log" "vitess.io/vitess/go/vt/logutil" "vitess.io/vitess/go/vt/servenv" "vitess.io/vitess/go/vt/topo" @@ -106,6 +105,15 @@ connect directly to the topo server(s).`, useInternalVtctld), // We use PersistentPreRun to set up the tracer, grpc client, and // command context for every command. PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) { + env, err = vtenv.New(vtenv.Options{ + MySQLServerVersion: servenv.MySQLServerVersion(), + TruncateUILen: servenv.TruncateUILen, + TruncateErrLen: servenv.TruncateErrLen, + }) + if err != nil { + return fmt.Errorf("failed to initialize vtenv: %w", err) + } + logutil.PurgeLogs() traceCloser = trace.StartTracing("vtctldclient") client, err = getClientForCommand(cmd) @@ -119,6 +127,7 @@ connect directly to the topo server(s).`, useInternalVtctld), } vreplcommon.SetClient(client) vreplcommon.SetCommandCtx(commandCtx) + return err }, // Similarly, PersistentPostRun cleans up the resources spawned by @@ -229,14 +238,4 @@ func init() { Root.PersistentFlags().StringSliceVar(&topoOptions.globalServerAddresses, "topo-global-server-address", topoOptions.globalServerAddresses, "the address of the global topology server(s)") Root.PersistentFlags().StringVar(&topoOptions.globalRoot, "topo-global-root", topoOptions.globalRoot, "the path of the global topology data in the global topology server") vreplcommon.RegisterCommands(Root) - - var err error - env, err = vtenv.New(vtenv.Options{ - MySQLServerVersion: servenv.MySQLServerVersion(), - TruncateUILen: servenv.TruncateUILen, - TruncateErrLen: servenv.TruncateErrLen, - }) - if err != nil { - log.Fatalf("failed to initialize vtenv: %v", err) - } }