Fix casing on keepalive

This commit is contained in:
Francis Nguyen 2020-02-11 21:34:28 -07:00
parent dca1a2b5ae
commit 331c225c36
4 changed files with 17 additions and 17 deletions

View File

@ -56,7 +56,7 @@ 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" persistentKeepaliveKey = "kilo.squat.ai/persistent-keepalive"
wireGuardIPAnnotationKey = "kilo.squat.ai/wireguard-ip" wireGuardIPAnnotationKey = "kilo.squat.ai/wireguard-ip"
regionLabelKey = "topology.kubernetes.io/region" regionLabelKey = "topology.kubernetes.io/region"
@ -263,13 +263,13 @@ func translateNode(node *v1.Node) *mesh.Node {
if !ok { if !ok {
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 persistentKeepAlive int64 var persistentKeepalive int64
if keepAlive, ok := node.ObjectMeta.Annotations[persistentKeepAliveKey]; !ok { if keepAlive, ok := node.ObjectMeta.Annotations[persistentKeepaliveKey]; !ok {
persistentKeepAlive = 0 persistentKeepalive = 0
} else { } else {
if persistentKeepAlive, err = strconv.ParseInt(keepAlive, 10, 64); err != nil { if persistentKeepalive, err = strconv.ParseInt(keepAlive, 10, 64); err != nil {
persistentKeepAlive = 0 persistentKeepalive = 0
} }
} }
var lastSeen int64 var lastSeen int64
@ -292,7 +292,7 @@ func translateNode(node *v1.Node) *mesh.Node {
Leader: leader, Leader: leader,
Location: location, Location: location,
Name: node.Name, Name: node.Name,
PersistentKeepAlive: int(persistentKeepAlive), 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

View File

@ -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{
persistentKeepAliveKey: "25", persistentKeepaliveKey: "25",
}, },
out: &mesh.Node{ out: &mesh.Node{
PersistentKeepAlive: 25, PersistentKeepalive: 25,
}, },
}, },
{ {
@ -148,7 +148,7 @@ func TestTranslateNode(t *testing.T) {
lastSeenAnnotationKey: "1000000000", lastSeenAnnotationKey: "1000000000",
leaderAnnotationKey: "", leaderAnnotationKey: "",
locationAnnotationKey: "b", locationAnnotationKey: "b",
persistentKeepAliveKey: "25", persistentKeepaliveKey: "25",
wireGuardIPAnnotationKey: "10.4.0.1/16", wireGuardIPAnnotationKey: "10.4.0.1/16",
}, },
labels: map[string]string{ labels: map[string]string{
@ -161,7 +161,7 @@ func TestTranslateNode(t *testing.T) {
LastSeen: 1000000000, LastSeen: 1000000000,
Leader: true, Leader: true,
Location: "b", Location: "b",
PersistentKeepAlive: 25, 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)},
}, },

View File

@ -82,7 +82,7 @@ type Node struct {
Leader bool Leader bool
Location string Location string
Name string Name string
PersistentKeepAlive int PersistentKeepalive int
Subnet *net.IPNet Subnet *net.IPNet
WireGuardIP *net.IPNet WireGuardIP *net.IPNet
} }

View File

@ -64,9 +64,9 @@ 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 // persistentKeepalive is the interval in seconds of the emission
// of keepalive packets to the peer. // of keepalive packets to the peer.
persistentKeepAlive int 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
@ -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,
persistentKeepAlive: topoMap[location][leader].PersistentKeepAlive, 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.persistentKeepAlive, PersistentKeepalive: s.persistentKeepalive,
} }
c.Peers = append(c.Peers, peer) c.Peers = append(c.Peers, peer)
} }