provisioning-catalog/components/fip_controller/cluster/vars.nu

33 lines
1 KiB
Text

#!/usr/bin/env nu
# Derived variables for fip_controller bundle rendering.
# Validates FIPs exist and serializes the fips array as JSON for the ConfigMap.
def resolve_fip_ip [fip_name: string]: nothing -> string {
let result = (do { ^hcloud floating-ip list -o json } | complete)
if $result.exit_code != 0 { return "" }
let matched = ($result.stdout | from json | where name == $fip_name)
if ($matched | is-empty) { return "" }
$matched | first | get ip
}
def main [component_json: string]: nothing -> nothing {
let d = ($component_json | from json)
let fips = ($d | get -o fips | default [])
# Validate each referenced FIP exists in Hetzner.
for fip in $fips {
let name = ($fip | get fip_name)
let ip = resolve_fip_ip $name
if ($ip | is-empty) {
error make {
msg: $"fip_controller prerequisite: floating IP '($name)' not found. Provision it before deploying.",
}
}
}
{
fips_json: ($fips | to json --raw),
}
| to json --raw
| print
}