Skip to content

Commit 6cebba3

Browse files
authored
config: allow configuration of node CPU and memory resources. (#27)
1 parent ed1113b commit 6cebba3

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ config file in [HCL](https://github.com/hashicorp/hcl) format.
117117

118118
- `region` - (`"dc1"`) - Specifies the region of the `nomad-nodesim` clients.
119119

120+
- `resources` - (block) - The CPU and Memory configuration that will be given to the simulated
121+
node.
122+
123+
- `cpu_compute` - (`10_000`) - The CPU value that the simulated node will be configured with and
124+
will represent the total allocatable CPU of the client.
125+
126+
- `memory_mb` - (`10_000`) - The memory MB value that the simulated node will be configured with and
127+
will represent the total allocatable memory of the client.
128+
120129
- `options` - (`"map[string]string"`) - Specifies a key-value mapping of internal configuration for
121130
`nomad-nodesim` clients, such as for driver configuration.
122131

internal/config/config.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ type Node struct {
7373
// required, or which have lengthy timeouts which can slow client startup
7474
// times.
7575
Options map[string]string `hcl:"options,optional"`
76+
77+
Resources *NodeResource `hcl:"resources,block"`
78+
}
79+
80+
// NodeResource is the CPU and Memory configuration that will be given to the
81+
// simulated node.
82+
type NodeResource struct {
83+
CPUCompute uint64 `hcl:"cpu_compute,optional"`
84+
MemoryMB uint64 `hcl:"memory_mb,optional"`
7685
}
7786

7887
// Default returns a default configuration object with all parameters set to
@@ -96,6 +105,10 @@ func Default() *Config {
96105
NodePool: "default",
97106
NodeClass: "",
98107
Options: map[string]string{},
108+
Resources: &NodeResource{
109+
CPUCompute: 10_000,
110+
MemoryMB: 10_000,
111+
},
99112
},
100113
}
101114
}
@@ -156,6 +169,14 @@ func (n *Node) merge(z *Node) *Node {
156169
result.Options[k] = v
157170
}
158171
}
172+
if z.Resources != nil {
173+
if z.Resources.CPUCompute != 0 {
174+
result.Resources.CPUCompute = z.Resources.CPUCompute
175+
}
176+
if z.Resources.MemoryMB != 0 {
177+
result.Resources.MemoryMB = z.Resources.MemoryMB
178+
}
179+
}
159180

160181
return &result
161182
}

main.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ func main() {
3737
defer stop()
3838

3939
flagConfig := internalConfig.Config{
40-
Log: &internalConfig.Log{},
41-
Node: &internalConfig.Node{},
40+
Log: &internalConfig.Log{},
41+
Node: &internalConfig.Node{
42+
Resources: &internalConfig.NodeResource{},
43+
},
4244
}
4345

4446
flag.StringVar(&flagConfig.WorkDir, "work-dir", "", "working directory")
@@ -188,8 +190,8 @@ func startClient(logger hclog.Logger, buildInfo *internalSimnode.BuildInfo, cfg
188190

189191
// Fake resources
190192
clientCfg.NetworkSpeed = 1_000
191-
clientCfg.CpuCompute = 10_000
192-
clientCfg.MemoryMB = 10_000
193+
clientCfg.CpuCompute = int(cfg.Node.Resources.CPUCompute)
194+
clientCfg.MemoryMB = int(cfg.Node.Resources.MemoryMB)
193195

194196
clientCfg.MaxKillTimeout = time.Minute
195197

0 commit comments

Comments
 (0)