Files
ilkerandClaude Opus 5.5 090719fc74
ci / derle (push) Successful in 30s
hpcod: clusters across the nodes of a Proxmox cluster
Discovery already saw every node of a Proxmox cluster and placement could
put a VM on any of them, but the template, the snippets and a simple SDN
zone only worked on PVE_NODE, so a cluster could land where it could not
be built.

- Setup asks which nodes clusters may use (PVE_NODES; a multi-select in
  the TUI when Proxmox has more than one). Discovery offers only those.
- Heads are placed on PVE_NODE only (head_node), where the template is, so
  no shared storage is needed; diskless compute nodes spread.
- PVE_SDN_ZONE_TYPE (auto|simple|vxlan): more than one node makes the zone
  vxlan, every node a peer, MTU 1450. A zone of the wrong type is remade
  only while no cluster has a vnet in it. Guest fabric NICs take the
  bridge MTU through virtio (mtu = 1).
- setup keeps nodes and head_node of its own site in sites.yaml, leaving
  the rest of the file as the operator wrote it.
- verify checks the nodes are online and the zone matches.

Run on the simulated Proxmox with the zone forced to vxlan: setup remade
the zone, a two-node selftest passed, both compute NICs came up at 1450,
and a DF ping of 1422 bytes passed between them while 1423 did not. Two
real Proxmox nodes have not been tested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 19:51:35 +01:00

89 lines
2.5 KiB
Go

package setup
import (
"bytes"
"fmt"
"sort"
"gopkg.in/yaml.v3"
)
// syncSiteSettings sets settings on one site of a sites.yaml, leaving
// everything else - other sites, other settings, comments - as it was.
//
// sites.yaml is written once and then belongs to the operator, who may
// add sites to it. The nodes a site uses and the node its heads go on are
// the exception: they come from the site's own answers, and a sites.yaml
// that disagreed with them would place heads where there is no template.
// So setup owns exactly these keys of exactly its own site.
func syncSiteSettings(raw []byte, id string, want map[string]string) ([]byte, bool, error) {
var doc yaml.Node
if err := yaml.Unmarshal(raw, &doc); err != nil {
return nil, false, err
}
if len(doc.Content) == 0 || doc.Content[0].Kind != yaml.MappingNode {
return nil, false, fmt.Errorf("not a mapping")
}
sites := mapValue(doc.Content[0], "sites")
if sites == nil || sites.Kind != yaml.SequenceNode {
return nil, false, fmt.Errorf("no sites list")
}
for _, site := range sites.Content {
if v := mapValue(site, "id"); v == nil || v.Value != id {
continue
}
settings := mapValue(site, "settings")
if settings == nil {
settings = &yaml.Node{Kind: yaml.MappingNode, Tag: "!!map"}
site.Content = append(site.Content,
&yaml.Node{Kind: yaml.ScalarNode, Tag: "!!str", Value: "settings"}, settings)
}
changed := false
for _, k := range sortedKeys(want) {
if v := mapValue(settings, k); v != nil {
if v.Value != want[k] {
v.Value, v.Tag, v.Style = want[k], "!!str", yaml.DoubleQuotedStyle
changed = true
}
continue
}
settings.Content = append(settings.Content,
&yaml.Node{Kind: yaml.ScalarNode, Tag: "!!str", Value: k},
&yaml.Node{Kind: yaml.ScalarNode, Tag: "!!str", Value: want[k], Style: yaml.DoubleQuotedStyle})
changed = true
}
if !changed {
return raw, false, nil
}
var b bytes.Buffer
enc := yaml.NewEncoder(&b)
enc.SetIndent(2)
if err := enc.Encode(&doc); err != nil {
return nil, false, err
}
return b.Bytes(), true, nil
}
return nil, false, fmt.Errorf("no site with id %q", id)
}
func mapValue(m *yaml.Node, key string) *yaml.Node {
if m == nil || m.Kind != yaml.MappingNode {
return nil
}
for i := 0; i+1 < len(m.Content); i += 2 {
if m.Content[i].Value == key {
return m.Content[i+1]
}
}
return nil
}
func sortedKeys(m map[string]string) []string {
out := make([]string, 0, len(m))
for k := range m {
out = append(out, k)
}
sort.Strings(out)
return out
}