Skip to content

Commit

Permalink
exposed CPU/RAM in YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
networkop committed Jul 27, 2021
1 parent 8d6de8e commit de6d186
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
2 changes: 2 additions & 0 deletions clab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ func (c *CLab) createNodeCfg(nodeName string, nodeDef *types.NodeDefinition, idx
Sandbox: c.Config.Topology.GetNodeSandbox(nodeName),
Kernel: c.Config.Topology.GetNodeKernel(nodeName),
Runtime: c.Config.Topology.GetNodeRuntime(nodeName),
CPU: c.Config.Topology.GetNodeCPU(nodeName),
RAM: c.Config.Topology.GetNodeRAM(nodeName),
}

log.Debugf("node config: %+v", nodeCfg)
Expand Down
15 changes: 9 additions & 6 deletions nodes/cvx/cvx.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ func (c *cvx) Init(cfg *types.NodeConfig, opts ...nodes.NodeOption) error {
return fmt.Errorf("failed to parse OCI image ref %q: %s", cfg.Image, err)
}

ram, ok := memoryReqs[ociRef.Ref().Tag()]
cfg.RAM = ram

// by default setting the limit to 768MB
if !ok {
cfg.RAM = "768MB"
// if RAM is not statically set, apply the defaults
if cfg.RAM == "" {
ram, ok := memoryReqs[ociRef.Ref().Tag()]
cfg.RAM = ram

// by default setting the limit to 768MB
if !ok {
cfg.RAM = "768MB"
}
}

return nil
Expand Down
18 changes: 18 additions & 0 deletions types/node_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ type NodeDefinition struct {
Kernel string `yaml:"kernel,omitempty"`
// Override container runtime
Runtime string `yaml:"runtime,omitempty"`
// Set node CPU (cgroup or hypervisor)
CPU string `yaml:"cpu,omitempty"`
// Set node RAM (cgroup or hypervisor)
RAM string `yaml:"ram,omitempty"`
}

func (n *NodeDefinition) GetKind() string {
Expand Down Expand Up @@ -182,3 +186,17 @@ func (n *NodeDefinition) GetNodeRuntime() string {
}
return n.Runtime
}

func (n *NodeDefinition) GetNodeCPU() string {
if n == nil {
return ""
}
return n.CPU
}

func (n *NodeDefinition) GetNodeRAM() string {
if n == nil {
return ""
}
return n.RAM
}
26 changes: 26 additions & 0 deletions types/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,32 @@ func (t *Topology) GetNodeRuntime(name string) string {
return ""
}

func (t *Topology) GetNodeCPU(name string) string {
if ndef, ok := t.Nodes[name]; ok {
if ndef.GetNodeCPU() != "" {
return ndef.GetNodeCPU()
}
if t.GetKind(t.GetNodeKind(name)).GetNodeCPU() != "" {
return t.GetKind(t.GetNodeKind(name)).GetNodeCPU()
}
return t.GetDefaults().GetNodeCPU()
}
return ""
}

func (t *Topology) GetNodeRAM(name string) string {
if ndef, ok := t.Nodes[name]; ok {
if ndef.GetNodeRAM() != "" {
return ndef.GetNodeRAM()
}
if t.GetKind(t.GetNodeKind(name)).GetNodeRAM() != "" {
return t.GetKind(t.GetNodeKind(name)).GetNodeRAM()
}
return t.GetDefaults().GetNodeRAM()
}
return ""
}

//resolvePath resolves a string path by expanding `~` to home dir or getting Abs path for the given path
func resolvePath(p string) (string, error) {
if p == "" {
Expand Down

0 comments on commit de6d186

Please sign in to comment.