Skip to content

Commit

Permalink
Add default constraints for cpu, memory all nodes (#407)
Browse files Browse the repository at this point in the history
Co-authored-by: Neha Manjunath <[email protected]>
  • Loading branch information
NehaManjunath and Neha Manjunath authored Jul 27, 2023
1 parent 4c246ee commit f8fbd7d
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 19 deletions.
20 changes: 14 additions & 6 deletions topo/node/arista/arista.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,7 @@ func defaults(pb *tpb.Node) *tpb.Node {
Name: "default_ceos_node",
}
}
if pb.Constraints == nil {
pb.Constraints = map[string]string{
"cpu": "0.5",
"memory": "1Gi",
}
}
pb = constraints(pb)
if pb.Services == nil {
pb.Services = map[uint32]*tpb.Service{
443: {
Expand Down Expand Up @@ -394,6 +389,19 @@ func defaults(pb *tpb.Node) *tpb.Node {
return pb
}

func constraints(pb *tpb.Node) *tpb.Node {
if pb.Constraints == nil {
pb.Constraints = map[string]string{}
}
if pb.Constraints["cpu"] == "" {
pb.Constraints["cpu"] = "0.5"
}
if pb.Constraints["memory"] == "" {
pb.Constraints["memory"] = "1Gi"
}
return pb
}

func (n *Node) FixInterfaces() error {
for k, v := range n.Proto.Interfaces {
switch {
Expand Down
22 changes: 14 additions & 8 deletions topo/node/juniper/juniper.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,13 @@ func defaults(pb *tpb.Node) *tpb.Node {
switch pb.Model {
case ModelNCPTX:
if pb.Constraints == nil {
pb.Constraints = map[string]string{
"cpu": "4",
"memory": "4Gi",
}
pb.Constraints = map[string]string{}
}
if pb.Constraints["cpu"] == "" {
pb.Constraints["cpu"] = "4"
}
if pb.Constraints["memory"] == "" {
pb.Constraints["memory"] = "4Gi"
}
if len(pb.Config.GetCommand()) == 0 {
pb.Config.Command = []string{
Expand All @@ -522,10 +525,13 @@ func defaults(pb *tpb.Node) *tpb.Node {
}
default:
if pb.Constraints == nil {
pb.Constraints = map[string]string{
"cpu": "8",
"memory": "8Gi",
}
pb.Constraints = map[string]string{}
}
if pb.Constraints["cpu"] == "" {
pb.Constraints["cpu"] = "8"
}
if pb.Constraints["memory"] == "" {
pb.Constraints["memory"] = "8Gi"
}
if len(pb.Config.GetCommand()) == 0 {
pb.Config.Command = []string{
Expand Down
9 changes: 9 additions & 0 deletions topo/node/nokia/nokia.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,15 @@ func defaults(pb *tpb.Node) *tpb.Node {

pb.Config.ConfigFile = "config" + ext
}
if pb.Constraints == nil {
pb.Constraints = map[string]string{}
}
if pb.Constraints["cpu"] == "" {
pb.Constraints["cpu"] = "0.5"
}
if pb.Constraints["memory"] == "" {
pb.Constraints["memory"] = "1Gi"
}
return pb
}

Expand Down
8 changes: 8 additions & 0 deletions topo/node/nokia/nokia_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ func TestNew(t *testing.T) {
Inside: 9559,
},
},
Constraints: map[string]string{
"cpu": "0.5",
"memory": "1Gi",
},
},
}, {
desc: "json config file",
Expand Down Expand Up @@ -188,6 +192,10 @@ func TestNew(t *testing.T) {
Inside: 9559,
},
},
Constraints: map[string]string{
"cpu": "0.5",
"memory": "1Gi",
},
},
},
}
Expand Down
11 changes: 7 additions & 4 deletions topo/node/openconfig/openconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,13 @@ func lemmingDefaults(pb *tpb.Node) *tpb.Node {
}
}
if pb.Constraints == nil {
pb.Constraints = map[string]string{
"cpu": "0.5",
"memory": "1Gi",
}
pb.Constraints = map[string]string{}
}
if pb.Constraints["cpu"] == "" {
pb.Constraints["cpu"] = "0.5"
}
if pb.Constraints["memory"] == "" {
pb.Constraints["memory"] = "1Gi"
}
if pb.Labels == nil {
pb.Labels = map[string]string{}
Expand Down
3 changes: 2 additions & 1 deletion topo/node/openconfig/openconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ func TestNew(t *testing.T) {
Cert: &tpb.CertificateCfg{},
},
Constraints: map[string]string{
"cpu": "10",
"cpu": "10",
"memory": "1Gi",
},
Labels: map[string]string{
"custom": "value",
Expand Down

0 comments on commit f8fbd7d

Please sign in to comment.