WIP(tfgrid3deployer): Support deploying on hetzner nodes

- Add support for deploying VMs, ZDBs, and gateways on Hetzner nodes.
- Introduce `use_hetzner_node` flag to VM, ZDB, and WebName.
- Update `filter_nodes` to filter by Hetzner farm IDs if `on_hetzner` flag is set.
- Implement `get_hetzner_farm_ids` function (currently a placeholder).

Co-authored-by: mahmmoud.hassanein <mahmmoud.hassanein@gmail.com>
This commit is contained in:
2025-02-02 18:25:04 +02:00
parent 54cfd4c353
commit 17a67870ef
4 changed files with 30 additions and 4 deletions

View File

@@ -135,6 +135,7 @@ fn (mut self TFDeployment) set_nodes() ! {
has_ipv6: if vm.requirements.public_ip6 { vm.requirements.public_ip6 } else { none }
status: 'up'
features: if vm.requirements.public_ip4 { ['zmachine'] } else { [] }
on_hetzner: vm.requirements.use_hetzner_node
)!
if nodes.len == 0 {
@@ -160,6 +161,7 @@ fn (mut self TFDeployment) set_nodes() ! {
healthy: true
node_id: zdb.requirements.node_id
available_for: u64(self.deployer.twin_id)
on_hetzner: zdb.requirements.use_hetzner_node
)!
if nodes.len == 0 {
@@ -183,6 +185,7 @@ fn (mut self TFDeployment) set_nodes() ! {
node_id: webname.requirements.node_id
available_for: u64(self.deployer.twin_id)
features: ['zmachine']
on_hetzner: webname.requirements.use_hetzner_node
)!
if nodes.len == 0 {

View File

@@ -42,16 +42,36 @@ fn get_mycelium() grid_models.Mycelium {
}
}
pub fn filter_nodes(filter gridproxy_models.NodeFilter) ![]gridproxy_models.Node {
@[params]
pub struct FilterNodesArgs {
gridproxy_models.NodeFilter
pub:
on_hetzner bool
}
pub fn filter_nodes(args FilterNodesArgs) ![]gridproxy_models.Node {
// Resolve the network configuration
net := resolve_network()!
// Create grid proxy client and retrieve the matching nodes
mut gp_client := gridproxy.new(net: net, cache: true)!
nodes := gp_client.get_nodes(filter)!
mut filter := args.NodeFilter
if args.on_hetzner {
farm_ids := get_hetzner_farm_ids()!
filter.farm_ids = farm_ids
}
nodes := gp_client.get_nodes(args.NodeFilter)!
return nodes
}
fn get_hetzner_farm_ids() ![]u64 {
// get farm ids that are know to be hetzner's
// if we need to iterate over all farms, maybe we should use multi-threading
panic('Not implemented')
return []
}
fn convert_to_gigabytes(bytes u64) u64 {
return bytes * 1024 * 1024 * 1024
}

View File

@@ -26,7 +26,10 @@ pub mut:
flist string = 'https://hub.grid.tf/tf-official-vms/ubuntu-24.04-latest.flist'
entrypoint string = '/sbin/zinit init'
env map[string]string
nodes []u32 // if set will chose a node from the list to deploy on
// if set will chose a node from the list to deploy on
nodes []u32
// will deploy on one of hetzner nodes
use_hetzner_node bool
}
// MachineModel struct to represent a machine and its associat ed details

View File

@@ -8,9 +8,9 @@ pub mut:
name string @[required]
node_id ?u32
use_wireguard_network bool
use_hetzner_node bool
// must be in the format ip:port if tls_passthrough is set, otherwise the format should be http://ip[:port]
backend string @[required]
use_wireguard bool
tls_passthrough bool
}