Skip to content

Commit 1ec277c

Browse files
committed
fix: ensure MaxWorkers is fully configurable without default value (#1279)
- exec/model/parallelizer.go: remove default value from MaxWorkers (64 → no default) - pkg/runtime/runtime.go: add Init() function to sync MaxWorkers after flag parsing - cmd/manager/main.go: call operator.Init() after pflag.Parse() - pkg/controller/chaosblade/daemonset.go: already has resource config from previous commit This ensures MaxWorkers is only set via --max-workers flag, not hardcoded. Change-Id: I Change-Id: I95c7c99a978d799c851271bb51f65ad6ef1e4ea8
1 parent 76ed617 commit 1ec277c

4 files changed

Lines changed: 13 additions & 1 deletion

File tree

cmd/manager/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ func main() {
7979
showVersion := pflag.Bool("version", false, "显示版本信息")
8080
pflag.Parse()
8181

82+
// Initialize runtime after flag parsing to sync MaxWorkers to parallelizer
83+
operator.Init()
84+
8285
// 如果只是查看版本,则显示后退出
8386
if *showVersion {
8487
printVersion()

exec/model/parallelizer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import "sync"
2020

2121
var (
2222
// MaxWorkers can be configured via environment variable or flag
23-
MaxWorkers = 64
23+
MaxWorkers int
2424
)
2525

2626
type DoWorkFunc func(workID int)

manager

66.6 MB
Binary file not shown.

pkg/runtime/runtime.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package runtime
1919
import (
2020
"github.com/spf13/pflag"
2121

22+
"github.com/chaosblade-io/chaosblade-operator/exec/model"
2223
"github.com/chaosblade-io/chaosblade-operator/pkg/runtime/chaosblade"
2324
"github.com/chaosblade-io/chaosblade-operator/pkg/runtime/product/aliyun"
2425
_ "github.com/chaosblade-io/chaosblade-operator/pkg/runtime/product/community"
@@ -48,6 +49,14 @@ func init() {
4849

4950
func initRuntimeData() {
5051
chaosblade.Constant = chaosblade.Products[version.Product]
52+
// Set default value for parallelizer.MaxWorkers
53+
model.MaxWorkers = MaxWorkers
54+
}
55+
56+
// Init initializes the runtime by syncing flag values to dependent packages.
57+
// This should be called after flag.Parse() in main().
58+
func Init() {
59+
model.MaxWorkers = MaxWorkers
5160
}
5261

5362
func FlagSet() *pflag.FlagSet {

0 commit comments

Comments
 (0)