Skip to content

Commit

Permalink
cli: skip cluster config for the few commands
Browse files Browse the repository at this point in the history
From now on `build`, `completion`, `kill`, `log`, `logrotate`, `stop`,
`list`, `pack` commands skip instance config generation from local,
etcs/tcs and env sources.

Closes #1038
  • Loading branch information
patapenka-alexey committed Jan 15, 2025
1 parent a5bd414 commit cd71f6f
Show file tree
Hide file tree
Showing 19 changed files with 100 additions and 59 deletions.
3 changes: 2 additions & 1 deletion cli/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func NewBuildCmd() *cobra.Command {
args []string,
toComplete string) ([]string, cobra.ShellCompDirective) {
var runningCtx running.RunningCtx
if err := running.FillCtx(cliOpts, &cmdCtx, &runningCtx, nil, false); err != nil {
err := running.FillCtx(cliOpts, &cmdCtx, &runningCtx, nil, running.ConfigLoadSkip)
if err != nil {
return nil, cobra.ShellCompDirectiveNoFileComp
}
return running.ExtractAppNames(runningCtx.Instances),
Expand Down
3 changes: 2 additions & 1 deletion cli/cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func internalCheckModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
}

var runningCtx running.RunningCtx
if err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, true); err != nil {
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadAll)
if err != nil {
return err
}

Expand Down
3 changes: 2 additions & 1 deletion cli/cmd/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ func internalCleanModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
}

var runningCtx running.RunningCtx
if err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, false); err != nil {
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadCluster)
if err != nil {
return err
}

Expand Down
3 changes: 2 additions & 1 deletion cli/cmd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,8 @@ func parseAppStr(cmdCtx *cmdcontext.CmdCtx, appStr string) (string, string, stri
// Fill context for the entire application.
// publish app:inst can work even if the `inst` instance doesn't exist right now.
var runningCtx running.RunningCtx
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, []string{appName}, false)
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, []string{appName},
running.ConfigLoadCluster)
if err != nil {
return "", "", "", err
}
Expand Down
3 changes: 2 additions & 1 deletion cli/cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ func resolveConnectOpts(cmdCtx *cmdcontext.CmdCtx, cliOpts *config.CliOpts,

// FillCtx returns error if no instances found.
var runningCtx running.RunningCtx
fillErr := running.FillCtx(cliOpts, cmdCtx, &runningCtx, []string{target}, false)
fillErr := running.FillCtx(cliOpts, cmdCtx, &runningCtx, []string{target},
running.ConfigLoadCluster)
if fillErr == nil {
if len(runningCtx.Instances) > 1 {
err = fmt.Errorf("specify instance name")
Expand Down
3 changes: 2 additions & 1 deletion cli/cmd/internal/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func ValidArgsFunction(
directive = cobra.ShellCompDirectiveNoFileComp

var runningCtx running.RunningCtx
if err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, nil, false); err != nil {
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, nil, running.ConfigLoadSkip)
if err != nil {
return
}

Expand Down
3 changes: 2 additions & 1 deletion cli/cmd/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ func internalKillModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {

if confirm {
var runningCtx running.RunningCtx
if err = running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, false); err != nil {
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadSkip)
if err != nil {
return err
}

Expand Down
3 changes: 2 additions & 1 deletion cli/cmd/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ func internalLogModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {

var err error
var runningCtx running.RunningCtx
if err = running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, false); err != nil {
err = running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadCluster)
if err != nil {
return err
}

Expand Down
3 changes: 2 additions & 1 deletion cli/cmd/logrotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func internalLogrotateModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
}

var runningCtx running.RunningCtx
if err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, false); err != nil {
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadSkip)
if err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ func internalPlayModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {

// FillCtx returns error if no instances found.
var runningCtx running.RunningCtx

if err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, []string{args[0]}, false); err == nil {
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, []string{args[0]}, running.ConfigLoadAll)
if err == nil {
if len(runningCtx.Instances) > 1 {
return util.InternalError(
"Internal error: specify instance name",
Expand Down
28 changes: 14 additions & 14 deletions cli/cmd/replicaset.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ type replicasetCtx struct {

// replicasetFillCtx fills the replicaset command context.
func replicasetFillCtx(cmdCtx *cmdcontext.CmdCtx, ctx *replicasetCtx, target string,
isRunningCtxRequired bool) error {
isRunningCtxRequired bool, loadConfig running.ConfigLoad) error {
var err error
ctx.Orchestrator, err = getOrchestrator()
if err != nil {
Expand All @@ -491,8 +491,7 @@ func replicasetFillCtx(cmdCtx *cmdcontext.CmdCtx, ctx *replicasetCtx, target str
SslCiphers: replicasetSslCiphers,
}
var connOpts connector.ConnectOpts

err = running.FillCtx(cliOpts, cmdCtx, &ctx.RunningCtx, []string{target}, false)
err = running.FillCtx(cliOpts, cmdCtx, &ctx.RunningCtx, []string{target}, loadConfig)
if err == nil {
ctx.IsApplication = true
if len(ctx.RunningCtx.Instances) == 1 {
Expand All @@ -514,7 +513,8 @@ func replicasetFillCtx(cmdCtx *cmdcontext.CmdCtx, ctx *replicasetCtx, target str
}
// Re-fill context for an application.
ctx.InstName = instName
err := running.FillCtx(cliOpts, cmdCtx, &ctx.RunningCtx, []string{appName}, false)
err := running.FillCtx(cliOpts, cmdCtx, &ctx.RunningCtx, []string{appName},
loadConfig)
if err != nil {
// Should not happen.
return err
Expand Down Expand Up @@ -572,7 +572,7 @@ func replicasetFillCtx(cmdCtx *cmdcontext.CmdCtx, ctx *replicasetCtx, target str
// internalReplicasetUpgradeModule is a "upgrade" command for the replicaset module.
func internalReplicasetUpgradeModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
var ctx replicasetCtx
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false); err != nil {
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
return err
}
if ctx.IsInstanceConnect {
Expand Down Expand Up @@ -607,7 +607,7 @@ func internalReplicasetDowngradeModule(cmdCtx *cmdcontext.CmdCtx, args []string)
downgradeVersion := args[1]

var ctx replicasetCtx
if err := replicasetFillCtx(cmdCtx, &ctx, target, false); err != nil {
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
return err
}
if ctx.IsInstanceConnect {
Expand Down Expand Up @@ -640,7 +640,7 @@ func internalReplicasetDowngradeModule(cmdCtx *cmdcontext.CmdCtx, args []string)
// internalReplicasetPromoteModule is a "promote" command for the replicaset module.
func internalReplicasetPromoteModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
var ctx replicasetCtx
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false); err != nil {
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
return err
}
if !ctx.IsInstanceConnect {
Expand Down Expand Up @@ -670,7 +670,7 @@ func internalReplicasetPromoteModule(cmdCtx *cmdcontext.CmdCtx, args []string) e
// internalReplicasetDemoteModule is a "demote" command for the replicaset module.
func internalReplicasetDemoteModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
var ctx replicasetCtx
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true); err != nil {
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true, running.ConfigLoadAll); err != nil {
return err
}
if !ctx.IsApplication {
Expand Down Expand Up @@ -702,7 +702,7 @@ func internalReplicasetDemoteModule(cmdCtx *cmdcontext.CmdCtx, args []string) er
// internalReplicasetStatusModule is a "status" command for the replicaset module.
func internalReplicasetStatusModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
var ctx replicasetCtx
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false); err != nil {
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadSkip); err != nil {
return err
}
if ctx.IsInstanceConnect {
Expand All @@ -722,7 +722,7 @@ func internalReplicasetExpelModule(cmdCtx *cmdcontext.CmdCtx, args []string) err
return fmt.Errorf("the command expects argument application_name:instance_name")
}
var ctx replicasetCtx
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true); err != nil {
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true, running.ConfigLoadAll); err != nil {
return err
}
if ctx.IsInstanceConnect {
Expand All @@ -749,7 +749,7 @@ func internalReplicasetExpelModule(cmdCtx *cmdcontext.CmdCtx, args []string) err
// the "replicaset vshard" module.
func internalReplicasetBootstrapVShardModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
var ctx replicasetCtx
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false); err != nil {
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
return err
}
if ctx.IsInstanceConnect {
Expand All @@ -776,7 +776,7 @@ func internalReplicasetBootstrapModule(cmdCtx *cmdcontext.CmdCtx, args []string)
_, instName, found := strings.Cut(args[0], string(running.InstanceDelimiter))

var ctx replicasetCtx
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true); err != nil {
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true, running.ConfigLoadAll); err != nil {
return err
}
if ctx.IsInstanceConnect {
Expand Down Expand Up @@ -838,7 +838,7 @@ func internalReplicasetRebootstrapModule(cmdCtx *cmdcontext.CmdCtx, args []strin
// internalReplicasetRolesAddModule is a "roles add" command for the replicaset module.
func internalReplicasetRolesAddModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
var ctx replicasetCtx
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false); err != nil {
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
return err
}
defer ctx.Conn.Close()
Expand Down Expand Up @@ -881,7 +881,7 @@ func internalReplicasetRolesAddModule(cmdCtx *cmdcontext.CmdCtx, args []string)
// internalReplicasetRolesRemoveModule is a "roles remove" command for the replicaset module.
func internalReplicasetRolesRemoveModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
var ctx replicasetCtx
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false); err != nil {
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
return err
}
defer ctx.Conn.Close()
Expand Down
3 changes: 2 additions & 1 deletion cli/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ func internalStartModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
}

var runningCtx running.RunningCtx
if err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, true); err != nil {
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadAll)
if err != nil {
return err
}

Expand Down
5 changes: 3 additions & 2 deletions cli/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ func internalStatusModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
}

var runningCtx running.RunningCtx
if err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, false); err != nil {
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadSkip)
if err != nil {
return err
}

err := status.Status(runningCtx, opts)
err = status.Status(runningCtx, opts)
return err
}
7 changes: 4 additions & 3 deletions cli/cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package cmd

import (
"fmt"
"os"

"github.com/apex/log"
"github.com/spf13/cobra"
"github.com/tarantool/tt/cli/cmd/internal"
"github.com/tarantool/tt/cli/cmdcontext"
"github.com/tarantool/tt/cli/modules"
"github.com/tarantool/tt/cli/running"
"github.com/tarantool/tt/cli/util"
"os"
)

// NewStopCmd creates stop command.
Expand Down Expand Up @@ -78,8 +79,8 @@ func internalStopModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
}

var runningCtx running.RunningCtx
var err error
if err = running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, false); err != nil {
var err error = running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadSkip)
if err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion cli/instances/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func ListInstances(cmdCtx *cmdcontext.CmdCtx, cliOpts *config.CliOpts) error {
fmt.Printf("instances enabled directory: %s\n", cliOpts.Env.InstancesEnabled)

applications, err := running.CollectInstancesForApps(appList, cliOpts, cmdCtx.Cli.ConfigDir,
cmdCtx.Integrity, false)
cmdCtx.Integrity, running.ConfigLoadSkip)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/pack/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func initAppsInfo(cliOpts *config.CliOpts, cmdCtx *cmdcontext.CmdCtx, packCtx *P
}
packCtx.AppList = appList
packCtx.AppsInfo, err = running.CollectInstancesForApps(packCtx.AppList, cliOpts,
cmdCtx.Cli.ConfigDir, cmdCtx.Integrity, false)
cmdCtx.Cli.ConfigDir, cmdCtx.Integrity, running.ConfigLoadSkip)
if err != nil {
return fmt.Errorf("failed to collect applications info: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cli/replicaset/rebootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func cleanDataFiles(instCtx running.InstanceCtx) error {
// and starting it again.
func Rebootstrap(cmdCtx cmdcontext.CmdCtx, cliOpts config.CliOpts, rbCtx RebootstrapCtx) error {
apps, err := running.CollectInstancesForApps([]string{rbCtx.AppName}, &cliOpts,
cmdCtx.Cli.ConfigDir, cmdCtx.Integrity, true)
cmdCtx.Cli.ConfigDir, cmdCtx.Integrity, running.ConfigLoadAll)
if err != nil {
return fmt.Errorf("cannot collect application instances info: %s", err)
}
Expand Down
Loading

0 comments on commit cd71f6f

Please sign in to comment.