Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tfrobot support mycelium #1080

Merged
merged 3 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tfrobot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ vms:
mem: 2 # amount of memory in GB
public_ip4: false
public_ip6: false
ygg_ip: false
mycelium_ip: true
flist: "https://hub.grid.tf/tf-official-apps/threefoldtech-ubuntu-22.04.flist"
entry_point: '/sbin/zinit init'
root_size: 0 # root size in GB, 0 is the default
Expand Down Expand Up @@ -115,7 +117,8 @@ tfrobot deploy -c path/to/your/config.yaml
| node_group | name of node_group the vm belongs to | should be defined in node_groups |
| cpu | number of cpu for vm | nonzero positive integer max = 32 |
| mem | free memory in the vm in GB | min = 0.25, max 256 |
| planetary | should the vm have yggdrasil ip | `true` or `false` |
| ygg_ip | should the vm have yggdrasil ip | `true` or `false` |
| mycelium_ip | should the vm have mycelium ip | `true` or `false` |
| public_ip4 | should the vm have free ip v4 | `true` or `false` |
| public_ip6 | should the vm have free ip v6 | `true` or `false` |
| flist | should be a link to valid flist | valid flist url with `.flist` or `.fl` extension |
Expand Down
1 change: 1 addition & 0 deletions tfrobot/example/conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ vms:
mount_point: /mnt/ssd
public_ip4: false
public_ip6: false
mycelium_ip: true
flist: https://hub.grid.tf/tf-official-apps/base:latest.flist
entry_point: /sbin/zinit init
root_size: 0 # root size in GB, 0 for default root size, max 10TB
Expand Down
1 change: 1 addition & 0 deletions tfrobot/example/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ vms:
- name: example_b #test deployment of vms with ssd storage
vms_count: 20
node_group: group_b
mycelium_ip: true
cpu: 1
mem: 4
ssd:
Expand Down
102 changes: 67 additions & 35 deletions tfrobot/pkg/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,6 @@ func buildDeployments(vms []Vms, nodesIDs []int, sshKeys map[string]string) grou
// we loop over all it's vms and create network and vm deployment for it
// the nodesIDsIdx is a counter used to get nodeID to be able to distribute load over all nodes
for _, vmGroup := range vms {
envVars := vmGroup.EnvVars
if envVars == nil {
envVars = map[string]string{}
}
envVars["SSH_KEY"] = sshKeys[vmGroup.SSHKey]
solutionType := fmt.Sprintf("vm/%s", vmGroup.NodeGroup)

for i := 0; i < int(vmGroup.Count); i++ {
Expand All @@ -244,37 +239,9 @@ func buildDeployments(vms []Vms, nodesIDs []int, sshKeys map[string]string) grou
vmName := fmt.Sprintf("%s%d", vmGroup.Name, i)
disks, mounts := parseDisks(vmName, vmGroup.SSDDisks)

network := workloads.ZNet{
Name: fmt.Sprintf("%s_network", vmName),
Description: "network for mass deployment",
Nodes: []uint32{nodeID},
IPRange: gridtypes.NewIPNet(net.IPNet{
IP: net.IPv4(10, 20, 0, 0),
Mask: net.CIDRMask(16, 32),
}),
AddWGAccess: false,
SolutionType: solutionType,
}

if !vmGroup.PublicIP4 && !vmGroup.Planetary {
log.Warn().Str("vms group", vmGroup.Name).Msg("Planetary and public IP options are false. Setting planetary IP to true")
vmGroup.Planetary = true
}
network := buildNetworkDeployment(vmGroup, nodeID, vmName, solutionType)
vm := buildVMDeployment(vmGroup, vmName, network.Name, sshKeys[vmGroup.SSHKey], mounts)

vm := workloads.VM{
Name: vmName,
NetworkName: network.Name,
Flist: vmGroup.Flist,
CPU: int(vmGroup.FreeCPU),
Memory: int(vmGroup.FreeMRU * 1024), // Memory is in MB
PublicIP: vmGroup.PublicIP4,
PublicIP6: vmGroup.PublicIP6,
Planetary: vmGroup.Planetary,
RootfsSize: int(vmGroup.RootSize * 1024), // RootSize is in MB
Entrypoint: vmGroup.Entrypoint,
EnvVars: envVars,
Mounts: mounts,
}
deployment := workloads.NewDeployment(vm.Name, nodeID, solutionType, nil, network.Name, disks, nil, []workloads.VM{vm}, nil)

vmDeployments = append(vmDeployments, &deployment)
Expand Down Expand Up @@ -338,3 +305,68 @@ func getBlockedNodes(groupDeployments groupDeploymentsInfo) []uint64 {

return blockedNodes
}

func buildNetworkDeployment(vm Vms, nodeID uint32, name, solutionType string) workloads.ZNet {
// set up mycelium keys
myceliumKeys := make(map[uint32][]byte)
if vm.Mycelium {
key, err := workloads.RandomMyceliumKey()
if err != nil {
log.Debug().Err(err).Send()
}

myceliumKeys[nodeID] = key
}

return workloads.ZNet{
Name: fmt.Sprintf("%s_network", name),
Description: "network for mass deployment",
Nodes: []uint32{nodeID},
IPRange: gridtypes.NewIPNet(net.IPNet{
IP: net.IPv4(10, 20, 0, 0),
Mask: net.CIDRMask(16, 32),
}),
AddWGAccess: false,
MyceliumKeys: myceliumKeys,
SolutionType: solutionType,
}
}

func buildVMDeployment(vm Vms, name, networkName, sshKey string, mounts []workloads.Mount) workloads.VM {
envVars := vm.EnvVars
if envVars == nil {
envVars = map[string]string{}
}
envVars["SSH_KEY"] = sshKey

// get random mycelium seeds
var myceliumSeed []byte
var err error
if vm.Mycelium {
myceliumSeed, err = workloads.RandomMyceliumIPSeed()
if err != nil {
log.Debug().Err(err).Send()
}
}

if !vm.PublicIP4 && !vm.Ygg && !vm.Mycelium {
log.Warn().Str("vms group", vm.Name).Msg("ygg ip, mycelium ip and public IP options are false. Setting ygg IP to true")
vm.Ygg = true
}

return workloads.VM{
Name: name,
NetworkName: networkName,
Flist: vm.Flist,
CPU: int(vm.FreeCPU),
Memory: int(vm.FreeMRU * 1024), // Memory is in MB
PublicIP: vm.PublicIP4,
PublicIP6: vm.PublicIP6,
MyceliumIPSeed: myceliumSeed,
Planetary: vm.Ygg,
RootfsSize: int(vm.RootSize * 1024), // RootSize is in MB
Entrypoint: vm.Entrypoint,
EnvVars: envVars,
Mounts: mounts,
}
}
3 changes: 2 additions & 1 deletion tfrobot/pkg/deployer/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ func loadGroupDeployments(ctx context.Context, tfPluginClient deployer.TFPluginC
ContractID: deployment.ContractID,
PublicIP4: vm.ComputedIP,
PublicIP6: vm.ComputedIP6,
PlanetaryIP: vm.PlanetaryIP,
YggIP: vm.PlanetaryIP,
MyceliumIP: vm.MyceliumIP,
IP: vm.IP,
Mounts: vm.Mounts,
}
Expand Down
6 changes: 4 additions & 2 deletions tfrobot/pkg/deployer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ type Vms struct {
SSDDisks []Disk `yaml:"ssd" json:"ssd"`
PublicIP4 bool `yaml:"public_ip4" json:"public_ip4"`
PublicIP6 bool `yaml:"public_ip6" json:"public_ip6"`
Planetary bool `yaml:"planetary" json:"planetary"`
Ygg bool `yaml:"ygg_ip" json:"ygg_ip"`
Mycelium bool `yaml:"mycelium_ip" json:"mycelium_ip"`
Flist string `yaml:"flist" validate:"required" json:"flist"`
RootSize uint64 `yaml:"root_size" validate:"max=10240" json:"root_size"` // max 10 TB
Entrypoint string `yaml:"entry_point" validate:"required" json:"entry_point"`
Expand All @@ -59,7 +60,8 @@ type vmOutput struct {
NetworkName string
PublicIP4 string
PublicIP6 string
PlanetaryIP string
YggIP string
MyceliumIP string
IP string
Mounts []workloads.Mount
NodeID uint32
Expand Down
Loading