Add Cloud Map seeder discovery with VPC Lattice operator templates.
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Agents poll AETHERFORGE_CLOUD_MAP_ENDPOINT to sync know_node gossip; deploy plans attach route_via DNS hints for standalone operator registries.
This commit is contained in:
42
server/internal/api/deploy_plan_cloudmap_test.go
Normal file
42
server/internal/api/deploy_plan_cloudmap_test.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"crypto-miner-server/internal/spreadrouter"
|
||||
)
|
||||
|
||||
func TestAttachCloudMapRouteVia(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
cfg := map[string]interface{}{
|
||||
"server": map[string]interface{}{
|
||||
"cloud_map_namespace": "prod.local",
|
||||
"cloud_map_service": "seeder",
|
||||
},
|
||||
}
|
||||
data, _ := json.Marshal(cfg)
|
||||
if err := os.WriteFile(filepath.Join(dir, "config.json"), data, 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
h := &DeployPlanHandler{dataDir: dir}
|
||||
body := DeployPlanBody{}
|
||||
h.attachCloudMapRouteVia(&body)
|
||||
if body.SpreadRouteHint == nil || body.SpreadRouteHint.RouteVia != "seeder.svc.prod.local" {
|
||||
t.Fatalf("hint=%+v", body.SpreadRouteHint)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAttachCloudMapRouteViaPreservesExisting(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
h := &DeployPlanHandler{dataDir: dir}
|
||||
body := DeployPlanBody{
|
||||
SpreadRouteHint: &spreadrouter.SpreadRouteHint{RouteVia: "custom.svc.lab.local"},
|
||||
}
|
||||
h.attachCloudMapRouteVia(&body)
|
||||
if body.SpreadRouteHint.RouteVia != "custom.svc.lab.local" {
|
||||
t.Fatalf("route_via=%q", body.SpreadRouteHint.RouteVia)
|
||||
}
|
||||
}
|
||||
@@ -38,4 +38,28 @@ func NormalizeRegistryDocument(doc RegistryDocument) (RegistryDocument, bool) {
|
||||
doc.Service = "seeder"
|
||||
}
|
||||
return doc, doc.Namespace != "" && doc.Service != ""
|
||||
}
|
||||
}
|
||||
|
||||
func KnowNodeTargets(doc RegistryDocument) []string {
|
||||
doc, ok := NormalizeRegistryDocument(doc)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
seen := make(map[string]bool)
|
||||
var out []string
|
||||
for _, inst := range doc.Instances {
|
||||
if !inst.Healthy {
|
||||
continue
|
||||
}
|
||||
id := strings.TrimSpace(inst.AgentID)
|
||||
if id == "" {
|
||||
id = strings.TrimSpace(inst.DNSName)
|
||||
}
|
||||
if id == "" || seen[id] {
|
||||
continue
|
||||
}
|
||||
seen[id] = true
|
||||
out = append(out, id)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package cloudmap
|
||||
package cloudmap
|
||||
|
||||
import "testing"
|
||||
|
||||
@@ -7,3 +7,19 @@ func TestSeederDNSName(t *testing.T) {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestKnowNodeTargets(t *testing.T) {
|
||||
doc := RegistryDocument{
|
||||
Namespace: "prod.local",
|
||||
Service: "seeder",
|
||||
Instances: []RegistryInstance{
|
||||
{AgentID: "a1", Healthy: true},
|
||||
{AgentID: "a2", Healthy: false},
|
||||
{DNSName: "seeder.svc.prod.local", Healthy: true},
|
||||
},
|
||||
}
|
||||
got := KnowNodeTargets(doc)
|
||||
if len(got) != 2 || got[0] != "a1" || got[1] != "seeder.svc.prod.local" {
|
||||
t.Fatalf("got=%v", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user