Skip to content

Commit

Permalink
add ss2 in dctest
Browse files Browse the repository at this point in the history
  • Loading branch information
YZ775 committed Dec 13, 2024
1 parent 8d43b67 commit b2c03fb
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 2 deletions.
9 changes: 9 additions & 0 deletions dctest/menu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ spec:
rack:
- cs: 2
ss: 1
ss2: 1
- cs: 2
- cs: 1
- cs: 1
Expand Down Expand Up @@ -58,3 +59,11 @@ spec:
memory: 10G
disk-count: 4
tpm: true
---
kind: Node
type: ss2
spec:
cpu: 2
memory: 10G
disk-count: 4
tpm: true
5 changes: 5 additions & 0 deletions menu/assets/bird_rack-tor1.conf
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,8 @@ protocol bgp '{{$rackName}}-{{$ss.Name}}' from bgpnode {
neighbor {{$ss.Node1Address}} as {{$asnRack}};
}
{{end -}}
{{range $ss2 := .Rack.SS2List -}}
protocol bgp '{{$rackName}}-{{$ss2.Name}}' from bgpnode {
neighbor {{$ss2.Node2Address}} as {{$asnRack}};
}
{{end -}}
5 changes: 5 additions & 0 deletions menu/assets/bird_rack-tor2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,8 @@ protocol bgp '{{$rackName}}-{{$ss.Name}}' from bgpnode {
neighbor {{$ss.Node2Address}} as {{$asnRack}};
}
{{end -}}
{{range $ss2 := .Rack.SS2List -}}
protocol bgp '{{$rackName}}-{{$ss2.Name}}' from bgpnode {
neighbor {{$ss2.Node2Address}} as {{$asnRack}};
}
{{end -}}
1 change: 1 addition & 0 deletions menu/assets/machines.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ racks:
workers:
cs: {{len $rack.CSList }}
ss: {{len $rack.SSList }}
ss2: {{len $rack.SS2List }}
boot:
bastion: {{$rack.BootNode.BastionAddress}}
{{end -}}
18 changes: 18 additions & 0 deletions menu/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type rack struct {
bootNode *bootNode
csList []*node
ssList []*node
ss2List []*node
node0Network *net.IPNet
node1Network *net.IPNet
node2Network *net.IPNet
Expand Down Expand Up @@ -307,6 +308,23 @@ func NewCluster(menu *menu) (*Cluster, error) {
rack.ssList = append(rack.ssList, node)
}

for ss2Idx := 0; ss2Idx < rackMenu.Ss2; ss2Idx++ {
name := fmt.Sprintf("ss2%d", ss2Idx+1)
fullName := fmt.Sprintf("%s-%s", rack.name, name)
node := &node{
name: name,
fullName: fullName,
spec: nodeSpecs[nodeTypeSS2],
serial: fmt.Sprintf("%x", sha1.Sum([]byte(fullName))),
node0Address: addToIP(node0Network.IP, offsetNodenetServers+ss2Idx+rackMenu.Cs+rackMenu.Ss, 32),
node1Address: addToIPNet(node1Network, offsetNodenetServers+ss2Idx+rackMenu.Cs+rackMenu.Ss),
node2Address: addToIPNet(node2Network, offsetNodenetServers+ss2Idx+rackMenu.Cs+rackMenu.Ss),
tor1Address: rack.bootNode.tor1Address,
tor2Address: rack.bootNode.tor2Address,
}
rack.ss2List = append(rack.ss2List, node)
}

rack.tor1 = &tor{
name: fmt.Sprintf("rack%d-tor%d", rackIdx, 1),
nodeAddress: addToIPNet(rack.node1Network, offsetNodenetToR),
Expand Down
24 changes: 24 additions & 0 deletions menu/cluster_conf_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type RackArgs struct {
BootNode NodeArgs
CSList []*NodeArgs
SSList []*NodeArgs
SS2List []*NodeArgs
}

type NodeArgs struct {
Expand Down Expand Up @@ -244,6 +245,19 @@ func (c *Cluster) generateSeedYaml(inputDir, outputDir string) error {
}
}
}
for _, ss2 := range rack.ss2List {
if ss2.spec.CloudInitTemplate != "" {
args := &SeedYamlArgs{
Name: fmt.Sprintf("%s-%s", rack.name, ss2.name),
Rack: rackArgs,
}
err := exportFile(filepath.Join(inputDir, ss2.spec.CloudInitTemplate),
filepath.Join(outputDir, fmt.Sprintf("seed_%s-%s.yml", rack.name, ss2.name)), args)
if err != nil {
return err
}
}
}
}

return nil
Expand Down Expand Up @@ -332,6 +346,9 @@ func (c *Cluster) generateSabakanData(outputDir string) error {
for _, ss := range rack.ssList {
ms = append(ms, sabakanMachine(ss.serial, rack.index, "ss"))
}
for _, ss2 := range rack.ss2List {
ms = append(ms, sabakanMachine(ss2.serial, rack.index, "ss2"))
}
}

sabakanDir := filepath.Join(outputDir, sabakanDir)
Expand Down Expand Up @@ -413,6 +430,13 @@ func newRackArgs(rack *rack) *RackArgs {
Node2Address: ss.node2Address.IP.String(),
})
}
for _, ss2 := range rack.ss2List {
args.SS2List = append(args.SS2List, &NodeArgs{
Name: ss2.name,
Node1Address: ss2.node1Address.IP.String(),
Node2Address: ss2.node2Address.IP.String(),
})
}

return args
}
Expand Down
3 changes: 3 additions & 0 deletions menu/cluster_yaml_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ func (c *Cluster) appendNodes(spec *types.ClusterSpec, sabakanDir string) {
for _, ss := range rack.ssList {
spec.Nodes = append(spec.Nodes, createWorkerNode(rack, ss, ss.spec))
}
for _, ss2 := range rack.ss2List {
spec.Nodes = append(spec.Nodes, createWorkerNode(rack, ss2, ss2.spec))
}
}

spec.Nodes = append(spec.Nodes, createChronyNode())
Expand Down
6 changes: 4 additions & 2 deletions menu/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ type inventorySpec struct {
}

type rackMenu struct {
Cs int `json:"cs"`
Ss int `json:"ss"`
Cs int `json:"cs"`
Ss int `json:"ss"`
Ss2 int `json:"ss2"`
}

type nodeMenu struct {
Expand Down Expand Up @@ -247,6 +248,7 @@ const (
nodeTypeBoot = nodeType("boot")
nodeTypeCS = nodeType("cs")
nodeTypeSS = nodeType("ss")
nodeTypeSS2 = nodeType("ss2")
)

type menu struct {
Expand Down

0 comments on commit b2c03fb

Please sign in to comment.