Merge pull request #141 from squat/fix_graph
pkg/mesh: fix panic in graph
This commit is contained in:
commit
9a6ec98343
@ -27,7 +27,7 @@ import (
|
||||
func (t *Topology) Dot() (string, error) {
|
||||
g := gographviz.NewGraph()
|
||||
g.Name = "kilo"
|
||||
if err := g.AddAttr("kilo", string(gographviz.Label), graphEscape(t.wireGuardCIDR.String())); err != nil {
|
||||
if err := g.AddAttr("kilo", string(gographviz.Label), graphEscape((&net.IPNet{IP: t.wireGuardCIDR.IP.Mask(t.wireGuardCIDR.Mask), Mask: t.wireGuardCIDR.Mask}).String())); err != nil {
|
||||
return "", fmt.Errorf("failed to add label to graph")
|
||||
}
|
||||
if err := g.AddAttr("kilo", string(gographviz.LabelLOC), "t"); err != nil {
|
||||
|
@ -477,7 +477,11 @@ func (m *Mesh) applyTopology() {
|
||||
return
|
||||
}
|
||||
// Update the node's WireGuard IP.
|
||||
m.wireGuardIP = t.wireGuardCIDR
|
||||
if t.leader {
|
||||
m.wireGuardIP = t.wireGuardCIDR
|
||||
} else {
|
||||
m.wireGuardIP = nil
|
||||
}
|
||||
conf := t.Conf()
|
||||
buf, err := conf.Bytes()
|
||||
if err != nil {
|
||||
|
@ -50,8 +50,10 @@ type Topology struct {
|
||||
// subnet is the Pod subnet of the local node.
|
||||
subnet *net.IPNet
|
||||
// wireGuardCIDR is the allocated CIDR of the WireGuard
|
||||
// interface of the local node. If the local node is not
|
||||
// the leader, then it is nil.
|
||||
// interface of the local node within the Kilo subnet.
|
||||
// If the local node is not the leader of a location, then
|
||||
// the IP is the 0th address in the subnet, i.e. the CIDR
|
||||
// is equal to the Kilo subnet.
|
||||
wireGuardCIDR *net.IPNet
|
||||
}
|
||||
|
||||
@ -104,7 +106,7 @@ func NewTopology(nodes map[string]*Node, peers map[string]*Peer, granularity Gra
|
||||
localLocation = nodeLocationPrefix + hostname
|
||||
}
|
||||
|
||||
t := Topology{key: key, port: port, hostname: hostname, location: localLocation, persistentKeepalive: persistentKeepalive, privateIP: nodes[hostname].InternalIP, subnet: nodes[hostname].Subnet}
|
||||
t := Topology{key: key, port: port, hostname: hostname, location: localLocation, persistentKeepalive: persistentKeepalive, privateIP: nodes[hostname].InternalIP, subnet: nodes[hostname].Subnet, wireGuardCIDR: subnet}
|
||||
for location := range topoMap {
|
||||
// Sort the location so the result is stable.
|
||||
sort.Slice(topoMap[location], func(i, j int) bool {
|
||||
|
@ -215,7 +215,7 @@ func TestNewTopology(t *testing.T) {
|
||||
location: logicalLocationPrefix + nodes["b"].Location,
|
||||
subnet: nodes["c"].Subnet,
|
||||
privateIP: nodes["c"].InternalIP,
|
||||
wireGuardCIDR: nil,
|
||||
wireGuardCIDR: DefaultKiloSubnet,
|
||||
segments: []*segment{
|
||||
{
|
||||
allowedIPs: []*net.IPNet{nodes["a"].Subnet, nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
||||
|
Loading…
Reference in New Issue
Block a user