Skip to content

Commit 0e8e8c5

Browse files
authored
Limit concurrency in phases (#431)
* Limit concurrency in phases Signed-off-by: Kimmo Lehto <[email protected]>
1 parent 8d64a66 commit 0e8e8c5

24 files changed

+92
-23
lines changed

cmd/apply.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ var applyCommand = &cli.Command{
1818
Usage: "Apply a k0sctl configuration",
1919
Flags: []cli.Flag{
2020
configFlag,
21+
concurrencyFlag,
22+
concurrentUploadsFlag,
2123
&cli.BoolFlag{
2224
Name: "no-wait",
2325
Usage: "Do not wait for worker nodes to join",
@@ -57,7 +59,7 @@ var applyCommand = &cli.Command{
5759
start := time.Now()
5860
phase.NoWait = ctx.Bool("no-wait")
5961

60-
manager := phase.Manager{Config: ctx.Context.Value(ctxConfigKey{}).(*v1beta1.Cluster)}
62+
manager := phase.Manager{Config: ctx.Context.Value(ctxConfigKey{}).(*v1beta1.Cluster), Concurrency: ctx.Int("concurrency"), ConcurrentUploads: ctx.Int("concurrent-uploads")}
6163
lockPhase := &phase.Lock{}
6264

6365
manager.AddPhase(

cmd/backup.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var backupCommand = &cli.Command{
1616
Usage: "Take backup of existing clusters state",
1717
Flags: []cli.Flag{
1818
configFlag,
19+
concurrencyFlag,
1920
debugFlag,
2021
traceFlag,
2122
redactFlag,
@@ -27,7 +28,7 @@ var backupCommand = &cli.Command{
2728
Action: func(ctx *cli.Context) error {
2829
start := time.Now()
2930

30-
manager := phase.Manager{Config: ctx.Context.Value(ctxConfigKey{}).(*v1beta1.Cluster)}
31+
manager := phase.Manager{Config: ctx.Context.Value(ctxConfigKey{}).(*v1beta1.Cluster), Concurrency: ctx.Int("concurrency")}
3132
lockPhase := &phase.Lock{}
3233

3334
manager.AddPhase(

cmd/flags.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ var (
7171
EnvVars: []string{"DISABLE_UPGRADE_CHECK"},
7272
}
7373

74+
concurrencyFlag = &cli.IntFlag{
75+
Name: "concurrency",
76+
Usage: "Maximum number of hosts to configure in parallel, set to 0 for unlimited",
77+
Value: 30,
78+
}
79+
80+
concurrentUploadsFlag = &cli.IntFlag{
81+
Name: "concurrent-uploads",
82+
Usage: "Maximum number of files to upload in parallel, set to 0 for unlimited",
83+
Value: 5,
84+
}
85+
7486
Colorize = aurora.NewAurora(false)
7587
)
7688

cmd/kubeconfig.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var kubeconfigCommand = &cli.Command{
2020
Value: "",
2121
},
2222
configFlag,
23+
concurrencyFlag,
2324
debugFlag,
2425
traceFlag,
2526
redactFlag,
@@ -36,7 +37,7 @@ var kubeconfigCommand = &cli.Command{
3637
// Change so that the internal config has only single controller host as we
3738
// do not need to connect to all nodes
3839
c.Spec.Hosts = cluster.Hosts{c.Spec.K0sLeader()}
39-
manager := phase.Manager{Config: c}
40+
manager := phase.Manager{Config: c, Concurrency: ctx.Int("concurrency")}
4041

4142
manager.AddPhase(
4243
&phase.Connect{},

cmd/reset.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var resetCommand = &cli.Command{
2020
Usage: "Remove traces of k0s from all of the hosts",
2121
Flags: []cli.Flag{
2222
configFlag,
23+
concurrencyFlag,
2324
debugFlag,
2425
traceFlag,
2526
redactFlag,
@@ -50,7 +51,7 @@ var resetCommand = &cli.Command{
5051

5152
start := time.Now()
5253

53-
manager := phase.Manager{Config: ctx.Context.Value(ctxConfigKey{}).(*v1beta1.Cluster)}
54+
manager := phase.Manager{Config: ctx.Context.Value(ctxConfigKey{}).(*v1beta1.Cluster), Concurrency: ctx.Int("concurrency")}
5455
for _, h := range manager.Config.Spec.Hosts {
5556
h.Reset = true
5657
}

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ require (
2828
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18
2929
github.com/sirupsen/logrus v1.8.1
3030
github.com/stretchr/testify v1.8.0
31-
github.com/urfave/cli/v2 v2.3.0
31+
github.com/urfave/cli/v2 v2.23.6
3232
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
3333
golang.org/x/crypto v0.3.0 // indirect
3434
golang.org/x/net v0.2.0 // indirect
@@ -82,6 +82,7 @@ require (
8282
github.com/pmezard/go-difflib v1.0.0 // indirect
8383
github.com/russross/blackfriday/v2 v2.1.0 // indirect
8484
github.com/spf13/pflag v1.0.5 // indirect
85+
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
8586
golang.org/x/mod v0.7.0 // indirect
8687
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
8788
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PK
343343
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
344344
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
345345
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
346+
github.com/urfave/cli/v2 v2.23.6 h1:iWmtKD+prGo1nKUtLO0Wg4z9esfBM4rAV4QRLQiEmJ4=
347+
github.com/urfave/cli/v2 v2.23.6/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
348+
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
349+
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
346350
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c h1:3lbZUMbMiGUW/LMkfsEABsc5zNT9+b1CvsJx47JzJ8g=
347351
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c/go.mod h1:UrdRz5enIKZ63MEE3IF9l2/ebyx59GyGgPi+tICQdmM=
348352
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

phase/arm_prepare.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (p *PrepareArm) ShouldRun() bool {
4040

4141
// Run the phase
4242
func (p *PrepareArm) Run() error {
43-
return p.hosts.ParallelEach(p.etcdUnsupportedArch)
43+
return p.parallelDo(p.hosts, p.etcdUnsupportedArch)
4444
}
4545

4646
func (p *PrepareArm) etcdUnsupportedArch(h *cluster.Host) error {

phase/configure_k0s.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (p *ConfigureK0s) Run() error {
5959
}
6060

6161
controllers := p.Config.Spec.Hosts.Controllers()
62-
return controllers.ParallelEach(p.configureK0s)
62+
return p.parallelDo(controllers, p.configureK0s)
6363
}
6464

6565
func (p *ConfigureK0s) validateConfig(h *cluster.Host) error {

phase/connect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var retries = uint(60)
2424

2525
// Run the phase
2626
func (p *Connect) Run() error {
27-
return p.Config.Spec.Hosts.ParallelEach(func(h *cluster.Host) error {
27+
return p.parallelDo(p.Config.Spec.Hosts, func(h *cluster.Host) error {
2828
err := retry.Do(
2929
func() error {
3030
return h.Connect()

0 commit comments

Comments
 (0)