Skip to content

Commit

Permalink
config: allow configuration of node CPU and memory resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasell committed May 28, 2024
1 parent ed1113b commit 1b69886
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ config file in [HCL](https://github.com/hashicorp/hcl) format.

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

- `resources` - (block) - The CPU and Memory configuration that will be given to the simulated
node.

- `cpu_compute` - (`10_000`) - The CPU value that the simulated node will be configured with and
will represent the total allocatable CPU of the client.

- `memory_mb` - (`10_000`) - The memory MB value that the simulated node will be configured with and
will represent the total allocatable memory of the client.

- `options` - (`"map[string]string"`) - Specifies a key-value mapping of internal configuration for
`nomad-nodesim` clients, such as for driver configuration.

Expand Down
21 changes: 21 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ type Node struct {
// required, or which have lengthy timeouts which can slow client startup
// times.
Options map[string]string `hcl:"options,optional"`

Resources *NodeResource `hcl:"resources,block"`
}

// NodeResource is the CPU and Memory configuration that will be given to the
// simulated node.
type NodeResource struct {
CPUCompute uint64 `hcl:"cpu_compute,optional"`
MemoryMB uint64 `hcl:"memory_mb,optional"`
}

// Default returns a default configuration object with all parameters set to
Expand All @@ -96,6 +105,10 @@ func Default() *Config {
NodePool: "default",
NodeClass: "",
Options: map[string]string{},
Resources: &NodeResource{
CPUCompute: 10_000,
MemoryMB: 10_000,
},
},
}
}
Expand Down Expand Up @@ -156,6 +169,14 @@ func (n *Node) merge(z *Node) *Node {
result.Options[k] = v
}
}
if z.Resources != nil {
if z.Resources.CPUCompute != 0 {
result.Resources.CPUCompute = z.Resources.CPUCompute
}
if z.Resources.MemoryMB != 0 {
result.Resources.MemoryMB = z.Resources.MemoryMB
}
}

return &result
}
Expand Down
10 changes: 6 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ func main() {
defer stop()

flagConfig := internalConfig.Config{
Log: &internalConfig.Log{},
Node: &internalConfig.Node{},
Log: &internalConfig.Log{},
Node: &internalConfig.Node{
Resources: &internalConfig.NodeResource{},
},
}

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

// Fake resources
clientCfg.NetworkSpeed = 1_000
clientCfg.CpuCompute = 10_000
clientCfg.MemoryMB = 10_000
clientCfg.CpuCompute = int(cfg.Node.Resources.CPUCompute)
clientCfg.MemoryMB = int(cfg.Node.Resources.MemoryMB)

clientCfg.MaxKillTimeout = time.Minute

Expand Down

0 comments on commit 1b69886

Please sign in to comment.