Shorten keepalive key
This commit is contained in:
parent
2082a42527
commit
dca1a2b5ae
@ -56,8 +56,8 @@ const (
|
|||||||
lastSeenAnnotationKey = "kilo.squat.ai/last-seen"
|
lastSeenAnnotationKey = "kilo.squat.ai/last-seen"
|
||||||
leaderAnnotationKey = "kilo.squat.ai/leader"
|
leaderAnnotationKey = "kilo.squat.ai/leader"
|
||||||
locationAnnotationKey = "kilo.squat.ai/location"
|
locationAnnotationKey = "kilo.squat.ai/location"
|
||||||
|
persistentKeepAliveKey = "kilo.squat.ai/persistent-keepalive"
|
||||||
wireGuardIPAnnotationKey = "kilo.squat.ai/wireguard-ip"
|
wireGuardIPAnnotationKey = "kilo.squat.ai/wireguard-ip"
|
||||||
wireGuardPersistentKeepAliveKey = "kilo.squat.ai/wireguard-persistent-keepalive"
|
|
||||||
|
|
||||||
regionLabelKey = "topology.kubernetes.io/region"
|
regionLabelKey = "topology.kubernetes.io/region"
|
||||||
jsonPatchSlash = "~1"
|
jsonPatchSlash = "~1"
|
||||||
@ -264,12 +264,12 @@ func translateNode(node *v1.Node) *mesh.Node {
|
|||||||
internalIP = node.ObjectMeta.Annotations[internalIPAnnotationKey]
|
internalIP = node.ObjectMeta.Annotations[internalIPAnnotationKey]
|
||||||
}
|
}
|
||||||
// Set Wireguard PersistentKeepAlive setting for the node.
|
// Set Wireguard PersistentKeepAlive setting for the node.
|
||||||
var wireGuardPersistentKeepAlive int64
|
var persistentKeepAlive int64
|
||||||
if wgKeepAlive, ok := node.ObjectMeta.Annotations[wireGuardPersistentKeepAliveKey]; !ok {
|
if keepAlive, ok := node.ObjectMeta.Annotations[persistentKeepAliveKey]; !ok {
|
||||||
wireGuardPersistentKeepAlive = 0
|
persistentKeepAlive = 0
|
||||||
} else {
|
} else {
|
||||||
if wireGuardPersistentKeepAlive, err = strconv.ParseInt(wgKeepAlive, 10, 64); err != nil {
|
if persistentKeepAlive, err = strconv.ParseInt(keepAlive, 10, 64); err != nil {
|
||||||
wireGuardPersistentKeepAlive = 0
|
persistentKeepAlive = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var lastSeen int64
|
var lastSeen int64
|
||||||
@ -292,12 +292,12 @@ func translateNode(node *v1.Node) *mesh.Node {
|
|||||||
Leader: leader,
|
Leader: leader,
|
||||||
Location: location,
|
Location: location,
|
||||||
Name: node.Name,
|
Name: node.Name,
|
||||||
|
PersistentKeepAlive: int(persistentKeepAlive),
|
||||||
Subnet: subnet,
|
Subnet: subnet,
|
||||||
// WireGuardIP can fail to parse if the node is not a leader or if
|
// WireGuardIP can fail to parse if the node is not a leader or if
|
||||||
// the node's agent has not yet reconciled. In either case, the IP
|
// the node's agent has not yet reconciled. In either case, the IP
|
||||||
// will parse as nil.
|
// will parse as nil.
|
||||||
WireGuardIP: normalizeIP(node.ObjectMeta.Annotations[wireGuardIPAnnotationKey]),
|
WireGuardIP: normalizeIP(node.ObjectMeta.Annotations[wireGuardIPAnnotationKey]),
|
||||||
WireGuardPersistentKeepAlive: int(wireGuardPersistentKeepAlive),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,10 +114,10 @@ func TestTranslateNode(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "wireguard persistent keepalive override",
|
name: "wireguard persistent keepalive override",
|
||||||
annotations: map[string]string{
|
annotations: map[string]string{
|
||||||
wireGuardPersistentKeepAliveKey: "25",
|
persistentKeepAliveKey: "25",
|
||||||
},
|
},
|
||||||
out: &mesh.Node{
|
out: &mesh.Node{
|
||||||
WireGuardPersistentKeepAlive: 25,
|
PersistentKeepAlive: 25,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -148,8 +148,8 @@ func TestTranslateNode(t *testing.T) {
|
|||||||
lastSeenAnnotationKey: "1000000000",
|
lastSeenAnnotationKey: "1000000000",
|
||||||
leaderAnnotationKey: "",
|
leaderAnnotationKey: "",
|
||||||
locationAnnotationKey: "b",
|
locationAnnotationKey: "b",
|
||||||
|
persistentKeepAliveKey: "25",
|
||||||
wireGuardIPAnnotationKey: "10.4.0.1/16",
|
wireGuardIPAnnotationKey: "10.4.0.1/16",
|
||||||
wireGuardPersistentKeepAliveKey: "25",
|
|
||||||
},
|
},
|
||||||
labels: map[string]string{
|
labels: map[string]string{
|
||||||
regionLabelKey: "a",
|
regionLabelKey: "a",
|
||||||
@ -161,9 +161,9 @@ func TestTranslateNode(t *testing.T) {
|
|||||||
LastSeen: 1000000000,
|
LastSeen: 1000000000,
|
||||||
Leader: true,
|
Leader: true,
|
||||||
Location: "b",
|
Location: "b",
|
||||||
|
PersistentKeepAlive: 25,
|
||||||
Subnet: &net.IPNet{IP: net.ParseIP("10.2.1.0"), Mask: net.CIDRMask(24, 32)},
|
Subnet: &net.IPNet{IP: net.ParseIP("10.2.1.0"), Mask: net.CIDRMask(24, 32)},
|
||||||
WireGuardIP: &net.IPNet{IP: net.ParseIP("10.4.0.1"), Mask: net.CIDRMask(16, 32)},
|
WireGuardIP: &net.IPNet{IP: net.ParseIP("10.4.0.1"), Mask: net.CIDRMask(16, 32)},
|
||||||
WireGuardPersistentKeepAlive: 25,
|
|
||||||
},
|
},
|
||||||
subnet: "10.2.1.0/24",
|
subnet: "10.2.1.0/24",
|
||||||
},
|
},
|
||||||
|
@ -82,9 +82,9 @@ type Node struct {
|
|||||||
Leader bool
|
Leader bool
|
||||||
Location string
|
Location string
|
||||||
Name string
|
Name string
|
||||||
|
PersistentKeepAlive int
|
||||||
Subnet *net.IPNet
|
Subnet *net.IPNet
|
||||||
WireGuardIP *net.IPNet
|
WireGuardIP *net.IPNet
|
||||||
WireGuardPersistentKeepAlive int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ready indicates whether or not the node is ready.
|
// Ready indicates whether or not the node is ready.
|
||||||
|
@ -64,14 +64,14 @@ type segment struct {
|
|||||||
hostnames []string
|
hostnames []string
|
||||||
// leader is the index of the leader of the segment.
|
// leader is the index of the leader of the segment.
|
||||||
leader int
|
leader int
|
||||||
|
// persistentKeepAlive is the interval in seconds of the emission
|
||||||
|
// of keepalive packets to the peer.
|
||||||
|
persistentKeepAlive int
|
||||||
// privateIPs is a slice of private IPs of all peers in the segment.
|
// privateIPs is a slice of private IPs of all peers in the segment.
|
||||||
privateIPs []net.IP
|
privateIPs []net.IP
|
||||||
// wireGuardIP is the allocated IP address of the WireGuard
|
// wireGuardIP is the allocated IP address of the WireGuard
|
||||||
// interface on the leader of the segment.
|
// interface on the leader of the segment.
|
||||||
wireGuardIP net.IP
|
wireGuardIP net.IP
|
||||||
// wireGuardPersistentKeepAlive is the interval in seconds of the emission
|
|
||||||
// of keepalive packets to the peer.
|
|
||||||
wireGuardPersistentKeepAlive int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTopology creates a new Topology struct from a given set of nodes and peers.
|
// NewTopology creates a new Topology struct from a given set of nodes and peers.
|
||||||
@ -128,7 +128,7 @@ func NewTopology(nodes map[string]*Node, peers map[string]*Peer, granularity Gra
|
|||||||
hostnames: hostnames,
|
hostnames: hostnames,
|
||||||
leader: leader,
|
leader: leader,
|
||||||
privateIPs: privateIPs,
|
privateIPs: privateIPs,
|
||||||
wireGuardPersistentKeepAlive: topoMap[location][leader].WireGuardPersistentKeepAlive,
|
persistentKeepAlive: topoMap[location][leader].PersistentKeepAlive,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// Sort the Topology segments so the result is stable.
|
// Sort the Topology segments so the result is stable.
|
||||||
@ -339,7 +339,7 @@ func (t *Topology) Conf() *wireguard.Conf {
|
|||||||
Port: uint32(t.port),
|
Port: uint32(t.port),
|
||||||
},
|
},
|
||||||
PublicKey: s.key,
|
PublicKey: s.key,
|
||||||
PersistentKeepalive: s.wireGuardPersistentKeepAlive,
|
PersistentKeepalive: s.persistentKeepAlive,
|
||||||
}
|
}
|
||||||
c.Peers = append(c.Peers, peer)
|
c.Peers = append(c.Peers, peer)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user