Skip to content

Commit d5f572d

Browse files
rewrite using two boolean variable to divide
cluster config and instance script loading
1 parent 45bf3b8 commit d5f572d

19 files changed

+64
-82
lines changed

cli/cmd/build.go

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

cli/cmd/check.go

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

3434
var runningCtx running.RunningCtx
35-
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadAll)
35+
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, true, true)
3636
if err != nil {
3737
return err
3838
}

cli/cmd/clean.go

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

106106
var runningCtx running.RunningCtx
107-
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadIgnoreErrors)
107+
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, false, false)
108108
if err != nil {
109109
return err
110110
}

cli/cmd/cluster.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,7 @@ 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(
677-
cliOpts, cmdCtx, &runningCtx, []string{appName}, running.ConfigLoadSkip)
676+
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, []string{appName}, false, false)
678677
if err != nil {
679678
return "", "", "", err
680679
}

cli/cmd/connect.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,8 +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-
if fillErr := running.FillCtx(
142-
cliOpts, cmdCtx, &runningCtx, []string{target}, running.ConfigLoadAll); fillErr == nil {
141+
fillErr := running.FillCtx(cliOpts, cmdCtx, &runningCtx, []string{target}, true, false)
142+
if fillErr == nil {
143143
if len(runningCtx.Instances) > 1 {
144144
err = fmt.Errorf("specify instance name")
145145
return

cli/cmd/internal/completion.go

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

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

cli/cmd/kill.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func internalKillModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
7979
if confirm {
8080
var runningCtx running.RunningCtx
8181
if err = running.FillCtx(
82-
cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadSkip); err != nil {
82+
cliOpts, cmdCtx, &runningCtx, args, false, false); err != nil {
8383
return err
8484
}
8585

cli/cmd/log.go

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

134134
var err error
135135
var runningCtx running.RunningCtx
136-
err = running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadAll)
136+
err = running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, true, false)
137137
if err != nil {
138138
return err
139139
}

cli/cmd/logrotate.go

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

4444
var runningCtx running.RunningCtx
45-
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadIgnoreErrors)
45+
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, false, false)
4646
if err != nil {
4747
return err
4848
}

cli/cmd/play.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func internalPlayModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
9999
// FillCtx returns error if no instances found.
100100
var runningCtx running.RunningCtx
101101
err := running.FillCtx(
102-
cliOpts, cmdCtx, &runningCtx, []string{args[0]}, running.ConfigLoadAll)
102+
cliOpts, cmdCtx, &runningCtx, []string{args[0]}, true, true)
103103
if err == nil {
104104
if len(runningCtx.Instances) > 1 {
105105
return util.InternalError(

cli/cmd/replicaset.go

+13-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, loadConfig running.ConfigLoad) error {
478+
isRunningCtxRequired bool, configRequired bool, scriptRequired bool) error {
479479
var err error
480480
ctx.Orchestrator, err = getOrchestrator()
481481
if err != nil {
@@ -493,7 +493,7 @@ func replicasetFillCtx(cmdCtx *cmdcontext.CmdCtx, ctx *replicasetCtx, target str
493493
var connOpts connector.ConnectOpts
494494

495495
if err := running.FillCtx(
496-
cliOpts, cmdCtx, &ctx.RunningCtx, []string{target}, loadConfig); err == nil {
496+
cliOpts, cmdCtx, &ctx.RunningCtx, []string{target}, configRequired, scriptRequired); err == nil {
497497
ctx.IsApplication = true
498498
if len(ctx.RunningCtx.Instances) == 1 {
499499
if connectCtx.Username != "" || connectCtx.Password != "" {
@@ -515,7 +515,7 @@ func replicasetFillCtx(cmdCtx *cmdcontext.CmdCtx, ctx *replicasetCtx, target str
515515
// Re-fill context for an application.
516516
ctx.InstName = instName
517517
err := running.FillCtx(
518-
cliOpts, cmdCtx, &ctx.RunningCtx, []string{appName}, loadConfig)
518+
cliOpts, cmdCtx, &ctx.RunningCtx, []string{appName}, true, true)
519519
if err != nil {
520520
// Should not happen.
521521
return err
@@ -573,7 +573,7 @@ func replicasetFillCtx(cmdCtx *cmdcontext.CmdCtx, ctx *replicasetCtx, target str
573573
// internalReplicasetUpgradeModule is a "upgrade" command for the replicaset module.
574574
func internalReplicasetUpgradeModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
575575
var ctx replicasetCtx
576-
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
576+
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, true, true); err != nil {
577577
return err
578578
}
579579
if ctx.IsInstanceConnect {
@@ -608,7 +608,7 @@ func internalReplicasetDowngradeModule(cmdCtx *cmdcontext.CmdCtx, args []string)
608608
downgradeVersion := args[1]
609609

610610
var ctx replicasetCtx
611-
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
611+
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, true, true); err != nil {
612612
return err
613613
}
614614
if ctx.IsInstanceConnect {
@@ -641,7 +641,7 @@ func internalReplicasetDowngradeModule(cmdCtx *cmdcontext.CmdCtx, args []string)
641641
// internalReplicasetPromoteModule is a "promote" command for the replicaset module.
642642
func internalReplicasetPromoteModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
643643
var ctx replicasetCtx
644-
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
644+
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, true, true); err != nil {
645645
return err
646646
}
647647
if !ctx.IsInstanceConnect {
@@ -671,7 +671,7 @@ func internalReplicasetPromoteModule(cmdCtx *cmdcontext.CmdCtx, args []string) e
671671
// internalReplicasetDemoteModule is a "demote" command for the replicaset module.
672672
func internalReplicasetDemoteModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
673673
var ctx replicasetCtx
674-
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true, running.ConfigLoadAll); err != nil {
674+
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true, true, true); err != nil {
675675
return err
676676
}
677677
if !ctx.IsApplication {
@@ -703,8 +703,7 @@ func internalReplicasetDemoteModule(cmdCtx *cmdcontext.CmdCtx, args []string) er
703703
// internalReplicasetStatusModule is a "status" command for the replicaset module.
704704
func internalReplicasetStatusModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
705705
var ctx replicasetCtx
706-
if err := replicasetFillCtx(
707-
cmdCtx, &ctx, args[0], false, running.ConfigLoadIgnoreErrors); err != nil {
706+
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, false, false); err != nil {
708707
return err
709708
}
710709
if ctx.IsInstanceConnect {
@@ -724,7 +723,7 @@ func internalReplicasetExpelModule(cmdCtx *cmdcontext.CmdCtx, args []string) err
724723
return fmt.Errorf("the command expects argument application_name:instance_name")
725724
}
726725
var ctx replicasetCtx
727-
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true, running.ConfigLoadAll); err != nil {
726+
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true, true, true); err != nil {
728727
return err
729728
}
730729
if ctx.IsInstanceConnect {
@@ -751,7 +750,7 @@ func internalReplicasetExpelModule(cmdCtx *cmdcontext.CmdCtx, args []string) err
751750
// the "replicaset vshard" module.
752751
func internalReplicasetBootstrapVShardModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
753752
var ctx replicasetCtx
754-
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
753+
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, true, true); err != nil {
755754
return err
756755
}
757756
if ctx.IsInstanceConnect {
@@ -778,7 +777,7 @@ func internalReplicasetBootstrapModule(cmdCtx *cmdcontext.CmdCtx, args []string)
778777
_, instName, found := strings.Cut(args[0], string(running.InstanceDelimiter))
779778

780779
var ctx replicasetCtx
781-
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true, running.ConfigLoadAll); err != nil {
780+
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true, true, true); err != nil {
782781
return err
783782
}
784783
if ctx.IsInstanceConnect {
@@ -840,7 +839,7 @@ func internalReplicasetRebootstrapModule(cmdCtx *cmdcontext.CmdCtx, args []strin
840839
// internalReplicasetRolesAddModule is a "roles add" command for the replicaset module.
841840
func internalReplicasetRolesAddModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
842841
var ctx replicasetCtx
843-
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
842+
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, true, true); err != nil {
844843
return err
845844
}
846845
defer ctx.Conn.Close()
@@ -883,7 +882,7 @@ func internalReplicasetRolesAddModule(cmdCtx *cmdcontext.CmdCtx, args []string)
883882
// internalReplicasetRolesRemoveModule is a "roles remove" command for the replicaset module.
884883
func internalReplicasetRolesRemoveModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
885884
var ctx replicasetCtx
886-
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
885+
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, true, true); err != nil {
887886
return err
888887
}
889888
defer ctx.Conn.Close()

cli/cmd/start.go

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

129129
var runningCtx running.RunningCtx
130-
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadAll)
130+
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, true, false)
131131
if err != nil {
132132
return err
133133
}

cli/cmd/status.go

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

6464
var runningCtx running.RunningCtx
65-
if err := running.FillCtx(
66-
cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadIgnoreErrors); err != nil {
65+
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, false, false)
66+
if err != nil {
6767
return err
6868
}
6969

70-
err := status.Status(runningCtx, opts)
70+
err = status.Status(runningCtx, opts)
7171
return err
7272
}

cli/cmd/stop.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ func internalStopModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
7979
}
8080

8181
var runningCtx running.RunningCtx
82-
var err error = running.FillCtx(
83-
cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadSkip)
82+
var err error = running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, false, false)
8483
if err != nil {
8584
return err
8685
}

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, running.ConfigLoadSkip)
34+
cmdCtx.Integrity, false, false)
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, running.ConfigLoadSkip)
52+
cmdCtx.Cli.ConfigDir, cmdCtx.Integrity, false, false)
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, running.ConfigLoadAll)
63+
cmdCtx.Cli.ConfigDir, cmdCtx.Integrity, true, true)
6464
if err != nil {
6565
return fmt.Errorf("cannot collect application instances info: %s", err)
6666
}

0 commit comments

Comments
 (0)