Skip to content

Commit cf0b5b7

Browse files
committed
cleanup devstack options
1 parent 3a7e2f2 commit cf0b5b7

File tree

3 files changed

+34
-58
lines changed

3 files changed

+34
-58
lines changed

cmd/cli/devstack/devstack.go

+33-16
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,45 @@ var (
4545
`))
4646
)
4747

48-
func newDevStackOptions() *devstack.DevStackOptions {
49-
return &devstack.DevStackOptions{
48+
type options struct {
49+
NumberOfHybridNodes int // Number of nodes to start in the cluster
50+
NumberOfRequesterOnlyNodes int // Number of nodes to start in the cluster
51+
NumberOfComputeOnlyNodes int // Number of nodes to start in the cluster
52+
NumberOfBadComputeActors int // Number of compute nodes to be bad actors
53+
CPUProfilingFile string
54+
MemoryProfilingFile string
55+
BasePath string
56+
WebUIListen string
57+
}
58+
59+
func (o *options) devstackOptions() []devstack.ConfigOption {
60+
opts := []devstack.ConfigOption{
61+
devstack.WithNumberOfHybridNodes(o.NumberOfHybridNodes),
62+
devstack.WithNumberOfRequesterOnlyNodes(o.NumberOfRequesterOnlyNodes),
63+
devstack.WithNumberOfComputeOnlyNodes(o.NumberOfComputeOnlyNodes),
64+
devstack.WithNumberOfBadComputeActors(o.NumberOfBadComputeActors),
65+
devstack.WithCPUProfilingFile(o.CPUProfilingFile),
66+
devstack.WithMemoryProfilingFile(o.MemoryProfilingFile),
67+
devstack.WithBasePath(o.BasePath),
68+
}
69+
return opts
70+
}
71+
72+
func newOptions() *options {
73+
return &options{
5074
NumberOfRequesterOnlyNodes: 1,
5175
NumberOfComputeOnlyNodes: 3,
5276
NumberOfBadComputeActors: 0,
53-
Peer: "",
5477
CPUProfilingFile: "",
5578
MemoryProfilingFile: "",
5679
BasePath: "",
80+
WebUIListen: config.Default.WebUI.Listen,
5781
}
5882
}
5983

6084
//nolint:funlen,gocyclo
6185
func NewCmd() *cobra.Command {
62-
ODs := newDevStackOptions()
63-
var webUIListen string
86+
ODs := newOptions()
6487
devstackFlags := map[string][]configflags.Definition{
6588
"job-selection": configflags.JobSelectionFlags,
6689
"disable-features": configflags.DisabledFeatureFlags,
@@ -83,7 +106,7 @@ func NewCmd() *cobra.Command {
83106
if err := logger.ConfigureLogging(string(logger.LogModeDefault), "debug"); err != nil {
84107
return fmt.Errorf("failed to configure logging: %w", err)
85108
}
86-
return runDevstack(cmd, ODs, webUIListen)
109+
return runDevstack(cmd, ODs)
87110
},
88111
}
89112

@@ -108,13 +131,9 @@ func NewCmd() *cobra.Command {
108131
`How many compute nodes should be bad actors`,
109132
)
110133
devstackCmd.PersistentFlags().StringVar(
111-
&webUIListen, "webui-address", config.Default.WebUI.Listen,
134+
&ODs.WebUIListen, "webui-address", ODs.WebUIListen,
112135
`Listen address for the web UI server`,
113136
)
114-
devstackCmd.PersistentFlags().StringVar(
115-
&ODs.Peer, "peer", ODs.Peer,
116-
`Connect node 0 to another network node`,
117-
)
118137
devstackCmd.PersistentFlags().StringVar(
119138
&ODs.CPUProfilingFile, "cpu-profiling-file", ODs.CPUProfilingFile,
120139
"File to save CPU profiling to",
@@ -131,7 +150,7 @@ func NewCmd() *cobra.Command {
131150
}
132151

133152
//nolint:gocyclo,funlen
134-
func runDevstack(cmd *cobra.Command, ODs *devstack.DevStackOptions, webUIListen string) error {
153+
func runDevstack(cmd *cobra.Command, ODs *options) error {
135154
ctx := cmd.Context()
136155

137156
cm := util.GetCleanupManager(ctx)
@@ -164,9 +183,7 @@ func runDevstack(cmd *cobra.Command, ODs *devstack.DevStackOptions, webUIListen
164183
defer os.RemoveAll(baseRepoPath)
165184
}
166185

167-
options := ODs.Options()
168-
169-
stack, err := devstack.Setup(ctx, cm, options...)
186+
stack, err := devstack.Setup(ctx, cm, ODs.devstackOptions()...)
170187
if err != nil {
171188
return err
172189
}
@@ -177,7 +194,7 @@ func runDevstack(cmd *cobra.Command, ODs *devstack.DevStackOptions, webUIListen
177194
if n.IsRequesterNode() {
178195
webuiConfig := webui.Config{
179196
APIEndpoint: n.APIServer.GetURI().String(),
180-
Listen: webUIListen,
197+
Listen: ODs.WebUIListen,
181198
}
182199
webuiServer, err := webui.NewServer(webuiConfig)
183200
if err != nil {

pkg/devstack/devstack.go

-28
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,6 @@ import (
2222
"github.com/bacalhau-project/bacalhau/pkg/system"
2323
)
2424

25-
type DevStackOptions struct {
26-
NumberOfHybridNodes int // Number of nodes to start in the cluster
27-
NumberOfRequesterOnlyNodes int // Number of nodes to start in the cluster
28-
NumberOfComputeOnlyNodes int // Number of nodes to start in the cluster
29-
NumberOfBadComputeActors int // Number of compute nodes to be bad actors
30-
Peer string // Connect node 0 to another network node
31-
CPUProfilingFile string
32-
MemoryProfilingFile string
33-
BasePath string
34-
}
35-
36-
func (o *DevStackOptions) Options() []ConfigOption {
37-
opts := []ConfigOption{
38-
WithNumberOfHybridNodes(o.NumberOfHybridNodes),
39-
WithNumberOfRequesterOnlyNodes(o.NumberOfRequesterOnlyNodes),
40-
WithNumberOfComputeOnlyNodes(o.NumberOfComputeOnlyNodes),
41-
WithNumberOfBadComputeActors(o.NumberOfBadComputeActors),
42-
WithCPUProfilingFile(o.CPUProfilingFile),
43-
WithMemoryProfilingFile(o.MemoryProfilingFile),
44-
WithBasePath(o.BasePath),
45-
}
46-
return opts
47-
}
48-
49-
func (o *DevStackOptions) NumberOfNodes() int {
50-
return o.NumberOfHybridNodes + o.NumberOfRequesterOnlyNodes + o.NumberOfComputeOnlyNodes
51-
}
52-
5325
type DevStack struct {
5426
Nodes []*node.Node
5527
}

pkg/test/teststack/stack.go

+1-14
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@ import (
2020
"github.com/bacalhau-project/bacalhau/pkg/system"
2121
)
2222

23-
func testDevStackConfig() *devstack.DevStackOptions {
24-
return &devstack.DevStackOptions{
25-
NumberOfHybridNodes: 0,
26-
NumberOfRequesterOnlyNodes: 0,
27-
NumberOfComputeOnlyNodes: 0,
28-
NumberOfBadComputeActors: 0,
29-
Peer: "",
30-
CPUProfilingFile: "",
31-
MemoryProfilingFile: "",
32-
}
33-
}
34-
3523
func Setup(
3624
ctx context.Context,
3725
t testing.TB,
@@ -42,8 +30,7 @@ func Setup(
4230
cm.Cleanup(ctx)
4331
})
4432

45-
options := testDevStackConfig().Options()
46-
options = append(options, devstack.WithBasePath(t.TempDir()))
33+
options := []devstack.ConfigOption{devstack.WithBasePath(t.TempDir())}
4734
options = append(options, opts...)
4835
stack, err := devstack.Setup(ctx, cm, options...)
4936
if err != nil {

0 commit comments

Comments
 (0)