Skip to content

Commit cd71f6f

Browse files
cli: skip cluster config for the few commands
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
1 parent a5bd414 commit cd71f6f

19 files changed

+100
-59
lines changed

cli/cmd/build.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ func NewBuildCmd() *cobra.Command {
3030
args []string,
3131
toComplete string) ([]string, cobra.ShellCompDirective) {
3232
var runningCtx running.RunningCtx
33-
if err := running.FillCtx(cliOpts, &cmdCtx, &runningCtx, nil, false); err != nil {
33+
err := running.FillCtx(cliOpts, &cmdCtx, &runningCtx, nil, running.ConfigLoadSkip)
34+
if err != nil {
3435
return nil, cobra.ShellCompDirectiveNoFileComp
3536
}
3637
return running.ExtractAppNames(runningCtx.Instances),

cli/cmd/check.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ func internalCheckModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
3232
}
3333

3434
var runningCtx running.RunningCtx
35-
if err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, true); err != nil {
35+
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadAll)
36+
if err != nil {
3637
return err
3738
}
3839

cli/cmd/clean.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ func internalCleanModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
104104
}
105105

106106
var runningCtx running.RunningCtx
107-
if err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, false); err != nil {
107+
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadCluster)
108+
if err != nil {
108109
return err
109110
}
110111

cli/cmd/cluster.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,8 @@ func parseAppStr(cmdCtx *cmdcontext.CmdCtx, appStr string) (string, string, stri
673673
// Fill context for the entire application.
674674
// publish app:inst can work even if the `inst` instance doesn't exist right now.
675675
var runningCtx running.RunningCtx
676-
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, []string{appName}, false)
676+
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, []string{appName},
677+
running.ConfigLoadCluster)
677678
if err != nil {
678679
return "", "", "", err
679680
}

cli/cmd/connect.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ func resolveConnectOpts(cmdCtx *cmdcontext.CmdCtx, cliOpts *config.CliOpts,
138138

139139
// FillCtx returns error if no instances found.
140140
var runningCtx running.RunningCtx
141-
fillErr := running.FillCtx(cliOpts, cmdCtx, &runningCtx, []string{target}, false)
141+
fillErr := running.FillCtx(cliOpts, cmdCtx, &runningCtx, []string{target},
142+
running.ConfigLoadCluster)
142143
if fillErr == nil {
143144
if len(runningCtx.Instances) > 1 {
144145
err = fmt.Errorf("specify instance name")

cli/cmd/internal/completion.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ func ValidArgsFunction(
2626
directive = cobra.ShellCompDirectiveNoFileComp
2727

2828
var runningCtx running.RunningCtx
29-
if err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, nil, false); err != nil {
29+
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, nil, running.ConfigLoadSkip)
30+
if err != nil {
3031
return
3132
}
3233

cli/cmd/kill.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ func internalKillModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
7878

7979
if confirm {
8080
var runningCtx running.RunningCtx
81-
if err = running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, false); err != nil {
81+
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadSkip)
82+
if err != nil {
8283
return err
8384
}
8485

cli/cmd/log.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ func internalLogModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
133133

134134
var err error
135135
var runningCtx running.RunningCtx
136-
if err = running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, false); err != nil {
136+
err = running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadCluster)
137+
if err != nil {
137138
return err
138139
}
139140

cli/cmd/logrotate.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ func internalLogrotateModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
4242
}
4343

4444
var runningCtx running.RunningCtx
45-
if err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, false); err != nil {
45+
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadSkip)
46+
if err != nil {
4647
return err
4748
}
4849

cli/cmd/play.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ func internalPlayModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
9898

9999
// FillCtx returns error if no instances found.
100100
var runningCtx running.RunningCtx
101-
102-
if err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, []string{args[0]}, false); err == nil {
101+
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, []string{args[0]}, running.ConfigLoadAll)
102+
if err == nil {
103103
if len(runningCtx.Instances) > 1 {
104104
return util.InternalError(
105105
"Internal error: specify instance name",

cli/cmd/replicaset.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ type replicasetCtx struct {
475475

476476
// replicasetFillCtx fills the replicaset command context.
477477
func replicasetFillCtx(cmdCtx *cmdcontext.CmdCtx, ctx *replicasetCtx, target string,
478-
isRunningCtxRequired bool) error {
478+
isRunningCtxRequired bool, loadConfig running.ConfigLoad) error {
479479
var err error
480480
ctx.Orchestrator, err = getOrchestrator()
481481
if err != nil {
@@ -491,8 +491,7 @@ func replicasetFillCtx(cmdCtx *cmdcontext.CmdCtx, ctx *replicasetCtx, target str
491491
SslCiphers: replicasetSslCiphers,
492492
}
493493
var connOpts connector.ConnectOpts
494-
495-
err = running.FillCtx(cliOpts, cmdCtx, &ctx.RunningCtx, []string{target}, false)
494+
err = running.FillCtx(cliOpts, cmdCtx, &ctx.RunningCtx, []string{target}, loadConfig)
496495
if err == nil {
497496
ctx.IsApplication = true
498497
if len(ctx.RunningCtx.Instances) == 1 {
@@ -514,7 +513,8 @@ func replicasetFillCtx(cmdCtx *cmdcontext.CmdCtx, ctx *replicasetCtx, target str
514513
}
515514
// Re-fill context for an application.
516515
ctx.InstName = instName
517-
err := running.FillCtx(cliOpts, cmdCtx, &ctx.RunningCtx, []string{appName}, false)
516+
err := running.FillCtx(cliOpts, cmdCtx, &ctx.RunningCtx, []string{appName},
517+
loadConfig)
518518
if err != nil {
519519
// Should not happen.
520520
return err
@@ -572,7 +572,7 @@ func replicasetFillCtx(cmdCtx *cmdcontext.CmdCtx, ctx *replicasetCtx, target str
572572
// internalReplicasetUpgradeModule is a "upgrade" command for the replicaset module.
573573
func internalReplicasetUpgradeModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
574574
var ctx replicasetCtx
575-
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false); err != nil {
575+
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
576576
return err
577577
}
578578
if ctx.IsInstanceConnect {
@@ -607,7 +607,7 @@ func internalReplicasetDowngradeModule(cmdCtx *cmdcontext.CmdCtx, args []string)
607607
downgradeVersion := args[1]
608608

609609
var ctx replicasetCtx
610-
if err := replicasetFillCtx(cmdCtx, &ctx, target, false); err != nil {
610+
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
611611
return err
612612
}
613613
if ctx.IsInstanceConnect {
@@ -640,7 +640,7 @@ func internalReplicasetDowngradeModule(cmdCtx *cmdcontext.CmdCtx, args []string)
640640
// internalReplicasetPromoteModule is a "promote" command for the replicaset module.
641641
func internalReplicasetPromoteModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
642642
var ctx replicasetCtx
643-
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false); err != nil {
643+
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
644644
return err
645645
}
646646
if !ctx.IsInstanceConnect {
@@ -670,7 +670,7 @@ func internalReplicasetPromoteModule(cmdCtx *cmdcontext.CmdCtx, args []string) e
670670
// internalReplicasetDemoteModule is a "demote" command for the replicaset module.
671671
func internalReplicasetDemoteModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
672672
var ctx replicasetCtx
673-
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true); err != nil {
673+
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true, running.ConfigLoadAll); err != nil {
674674
return err
675675
}
676676
if !ctx.IsApplication {
@@ -702,7 +702,7 @@ func internalReplicasetDemoteModule(cmdCtx *cmdcontext.CmdCtx, args []string) er
702702
// internalReplicasetStatusModule is a "status" command for the replicaset module.
703703
func internalReplicasetStatusModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
704704
var ctx replicasetCtx
705-
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false); err != nil {
705+
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadSkip); err != nil {
706706
return err
707707
}
708708
if ctx.IsInstanceConnect {
@@ -722,7 +722,7 @@ func internalReplicasetExpelModule(cmdCtx *cmdcontext.CmdCtx, args []string) err
722722
return fmt.Errorf("the command expects argument application_name:instance_name")
723723
}
724724
var ctx replicasetCtx
725-
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true); err != nil {
725+
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true, running.ConfigLoadAll); err != nil {
726726
return err
727727
}
728728
if ctx.IsInstanceConnect {
@@ -749,7 +749,7 @@ func internalReplicasetExpelModule(cmdCtx *cmdcontext.CmdCtx, args []string) err
749749
// the "replicaset vshard" module.
750750
func internalReplicasetBootstrapVShardModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
751751
var ctx replicasetCtx
752-
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false); err != nil {
752+
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
753753
return err
754754
}
755755
if ctx.IsInstanceConnect {
@@ -776,7 +776,7 @@ func internalReplicasetBootstrapModule(cmdCtx *cmdcontext.CmdCtx, args []string)
776776
_, instName, found := strings.Cut(args[0], string(running.InstanceDelimiter))
777777

778778
var ctx replicasetCtx
779-
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true); err != nil {
779+
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true, running.ConfigLoadAll); err != nil {
780780
return err
781781
}
782782
if ctx.IsInstanceConnect {
@@ -838,7 +838,7 @@ func internalReplicasetRebootstrapModule(cmdCtx *cmdcontext.CmdCtx, args []strin
838838
// internalReplicasetRolesAddModule is a "roles add" command for the replicaset module.
839839
func internalReplicasetRolesAddModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
840840
var ctx replicasetCtx
841-
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false); err != nil {
841+
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
842842
return err
843843
}
844844
defer ctx.Conn.Close()
@@ -881,7 +881,7 @@ func internalReplicasetRolesAddModule(cmdCtx *cmdcontext.CmdCtx, args []string)
881881
// internalReplicasetRolesRemoveModule is a "roles remove" command for the replicaset module.
882882
func internalReplicasetRolesRemoveModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
883883
var ctx replicasetCtx
884-
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false); err != nil {
884+
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
885885
return err
886886
}
887887
defer ctx.Conn.Close()

cli/cmd/start.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ func internalStartModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
127127
}
128128

129129
var runningCtx running.RunningCtx
130-
if err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, true); err != nil {
130+
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadAll)
131+
if err != nil {
131132
return err
132133
}
133134

cli/cmd/status.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ func internalStatusModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
6262
}
6363

6464
var runningCtx running.RunningCtx
65-
if err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, false); err != nil {
65+
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadSkip)
66+
if err != nil {
6667
return err
6768
}
6869

69-
err := status.Status(runningCtx, opts)
70+
err = status.Status(runningCtx, opts)
7071
return err
7172
}

cli/cmd/stop.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package cmd
22

33
import (
44
"fmt"
5+
"os"
6+
57
"github.com/apex/log"
68
"github.com/spf13/cobra"
79
"github.com/tarantool/tt/cli/cmd/internal"
810
"github.com/tarantool/tt/cli/cmdcontext"
911
"github.com/tarantool/tt/cli/modules"
1012
"github.com/tarantool/tt/cli/running"
1113
"github.com/tarantool/tt/cli/util"
12-
"os"
1314
)
1415

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

8081
var runningCtx running.RunningCtx
81-
var err error
82-
if err = running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, false); err != nil {
82+
var err error = running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadSkip)
83+
if err != nil {
8384
return err
8485
}
8586

cli/instances/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func ListInstances(cmdCtx *cmdcontext.CmdCtx, cliOpts *config.CliOpts) error {
3131
fmt.Printf("instances enabled directory: %s\n", cliOpts.Env.InstancesEnabled)
3232

3333
applications, err := running.CollectInstancesForApps(appList, cliOpts, cmdCtx.Cli.ConfigDir,
34-
cmdCtx.Integrity, false)
34+
cmdCtx.Integrity, running.ConfigLoadSkip)
3535
if err != nil {
3636
return err
3737
}

cli/pack/opts.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func initAppsInfo(cliOpts *config.CliOpts, cmdCtx *cmdcontext.CmdCtx, packCtx *P
4949
}
5050
packCtx.AppList = appList
5151
packCtx.AppsInfo, err = running.CollectInstancesForApps(packCtx.AppList, cliOpts,
52-
cmdCtx.Cli.ConfigDir, cmdCtx.Integrity, false)
52+
cmdCtx.Cli.ConfigDir, cmdCtx.Integrity, running.ConfigLoadSkip)
5353
if err != nil {
5454
return fmt.Errorf("failed to collect applications info: %s", err)
5555
}

cli/replicaset/rebootstrap.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func cleanDataFiles(instCtx running.InstanceCtx) error {
6060
// and starting it again.
6161
func Rebootstrap(cmdCtx cmdcontext.CmdCtx, cliOpts config.CliOpts, rbCtx RebootstrapCtx) error {
6262
apps, err := running.CollectInstancesForApps([]string{rbCtx.AppName}, &cliOpts,
63-
cmdCtx.Cli.ConfigDir, cmdCtx.Integrity, true)
63+
cmdCtx.Cli.ConfigDir, cmdCtx.Integrity, running.ConfigLoadAll)
6464
if err != nil {
6565
return fmt.Errorf("cannot collect application instances info: %s", err)
6666
}

0 commit comments

Comments
 (0)