Placement seat: the tunnel found on a node is a typed record, not a free object (ADR 0634 §1; issue 1966)
This commit is contained in:
@@ -343,6 +343,25 @@ func DecodeSeatHoldersBySeatNodeValue(raw []byte) (SeatHoldersBySeatNodeValue, e
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// FoundTunnel is a tunnel found on the machine when it was adopted: everything but its private key.
|
||||
type FoundTunnel struct {
|
||||
Address string `json:"address,omitempty"`
|
||||
Config string `json:"config,omitempty"`
|
||||
Interface string `json:"interface"`
|
||||
Mtu int64 `json:"mtu,omitempty"`
|
||||
Peers []FoundTunnelPeer `json:"peers,omitempty"`
|
||||
Port int64 `json:"port,omitempty"`
|
||||
PublicKey string `json:"public-key,omitempty"`
|
||||
Range string `json:"range,omitempty"`
|
||||
Unit string `json:"unit,omitempty"`
|
||||
}
|
||||
|
||||
// FoundTunnelPeer is one peer of a found tunnel.
|
||||
type FoundTunnelPeer struct {
|
||||
Address string `json:"address,omitempty"`
|
||||
PublicKey string `json:"public-key"`
|
||||
}
|
||||
|
||||
// Holding is one seat a module placed on the node holds.
|
||||
type Holding struct {
|
||||
Claim string `json:"claim"`
|
||||
@@ -368,7 +387,7 @@ type NodeDecided struct {
|
||||
Site string `json:"site,omitempty"`
|
||||
Taken []string `json:"taken,omitempty"`
|
||||
// the tunnel found on the node when it was adopted
|
||||
Tunnel map[string]any `json:"tunnel,omitempty"`
|
||||
Tunnel *FoundTunnel `json:"tunnel,omitempty"`
|
||||
}
|
||||
|
||||
// PlacedModule is one module placed on a node.
|
||||
|
||||
@@ -25,6 +25,12 @@ func TestFixtures(t *testing.T) {
|
||||
err := json.Unmarshal(b, &v)
|
||||
return v, err
|
||||
}, subjectIs: nil},
|
||||
{name: "a node that came with a tunnel", subject: "", given: "{\"decided\":{\"tunnel\":{\"interface\":\"wg0\",\"peers\":[{\"address\":\"10.77.0.9/32\",\"public-key\":\"k2\"}],\"port\":51820,\"public-key\":\"k1\"}},\"modules\":[],\"node\":\"ace\",\"v\":1}", wire: "{\"decided\":{\"tunnel\":{\"interface\":\"wg0\",\"peers\":[{\"address\":\"10.77.0.9/32\",\"public-key\":\"k2\"}],\"port\":51820,\"public-key\":\"k1\"}},\"modules\":[],\"node\":\"ace\",\"v\":1}",
|
||||
decode: func(b []byte) (any, error) {
|
||||
var v PlacementByNodeNodeValue
|
||||
err := json.Unmarshal(b, &v)
|
||||
return v, err
|
||||
}, subjectIs: nil},
|
||||
{name: "a module's key", subject: "", given: "{\"node\":\"ace\",\"placed\":{\"bindings\":{\"database\":{\"module\":\"postgres\",\"node\":\"ace\"}},\"module\":\"plex\",\"ports\":{\"32400\":32400}},\"v\":1}", wire: "{\"node\":\"ace\",\"placed\":{\"bindings\":{\"database\":{\"module\":\"postgres\",\"node\":\"ace\"}},\"module\":\"plex\",\"ports\":{\"32400\":32400}},\"v\":1}",
|
||||
decode: func(b []byte) (any, error) {
|
||||
var v PlacementByNodeModuleValue
|
||||
|
||||
@@ -16,6 +16,28 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "a node that came with a tunnel",
|
||||
"of": "state:placement/<node>.node",
|
||||
"given": {
|
||||
"v": 1,
|
||||
"node": "ace",
|
||||
"decided": {
|
||||
"tunnel": {
|
||||
"interface": "wg0",
|
||||
"port": 51820,
|
||||
"public-key": "k1",
|
||||
"peers": [
|
||||
{
|
||||
"public-key": "k2",
|
||||
"address": "10.77.0.9/32"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"modules": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "a module's key",
|
||||
"of": "state:placement/<node>.<module>",
|
||||
|
||||
@@ -514,7 +514,7 @@
|
||||
}
|
||||
},
|
||||
"tunnel": {
|
||||
"type": "object",
|
||||
"$ref": "#/defs/FoundTunnel",
|
||||
"description": "the tunnel found on the node when it was adopted"
|
||||
},
|
||||
"peer-names": {
|
||||
@@ -526,6 +526,60 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"FoundTunnel": {
|
||||
"type": "object",
|
||||
"description": "a tunnel found on the machine when it was adopted: everything but its private key",
|
||||
"properties": {
|
||||
"interface": {
|
||||
"type": "string"
|
||||
},
|
||||
"unit": {
|
||||
"type": "string"
|
||||
},
|
||||
"config": {
|
||||
"type": "string"
|
||||
},
|
||||
"port": {
|
||||
"type": "integer"
|
||||
},
|
||||
"mtu": {
|
||||
"type": "integer"
|
||||
},
|
||||
"address": {
|
||||
"type": "string"
|
||||
},
|
||||
"range": {
|
||||
"type": "string"
|
||||
},
|
||||
"public-key": {
|
||||
"type": "string"
|
||||
},
|
||||
"peers": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/defs/FoundTunnelPeer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"interface"
|
||||
]
|
||||
},
|
||||
"FoundTunnelPeer": {
|
||||
"type": "object",
|
||||
"description": "one peer of a found tunnel",
|
||||
"properties": {
|
||||
"public-key": {
|
||||
"type": "string"
|
||||
},
|
||||
"address": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"public-key"
|
||||
]
|
||||
},
|
||||
"Placement": {
|
||||
"type": "object",
|
||||
"description": "one node's placement assembled",
|
||||
|
||||
@@ -178,6 +178,25 @@ export function parseSeatHoldersBySeatNodeKey(key: string): { seat: string; node
|
||||
return { seat, node };
|
||||
}
|
||||
|
||||
/** a tunnel found on the machine when it was adopted: everything but its private key */
|
||||
export interface FoundTunnel {
|
||||
"address"?: string;
|
||||
"config"?: string;
|
||||
"interface": string;
|
||||
"mtu"?: number;
|
||||
"peers"?: FoundTunnelPeer[];
|
||||
"port"?: number;
|
||||
"public-key"?: string;
|
||||
"range"?: string;
|
||||
"unit"?: string;
|
||||
}
|
||||
|
||||
/** one peer of a found tunnel */
|
||||
export interface FoundTunnelPeer {
|
||||
"address"?: string;
|
||||
"public-key": string;
|
||||
}
|
||||
|
||||
/** one seat a module placed on the node holds */
|
||||
export interface Holding {
|
||||
"claim": string;
|
||||
@@ -203,7 +222,7 @@ export interface NodeDecided {
|
||||
"site"?: string;
|
||||
"taken"?: string[];
|
||||
/** the tunnel found on the node when it was adopted */
|
||||
"tunnel"?: Record<string, unknown>;
|
||||
"tunnel"?: FoundTunnel;
|
||||
}
|
||||
|
||||
/** one module placed on a node */
|
||||
|
||||
Reference in New Issue
Block a user