Add WireGuardPersistentKeepAlive to mesh.Node
This commit is contained in:
parent
a6afc3247d
commit
8a5dbbe368
@ -57,6 +57,7 @@ const (
|
||||
leaderAnnotationKey = "kilo.squat.ai/leader"
|
||||
locationAnnotationKey = "kilo.squat.ai/location"
|
||||
wireGuardIPAnnotationKey = "kilo.squat.ai/wireguard-ip"
|
||||
wireGuardPersistentKeepAliveKey = "kilo.squat.ai/wireguard-persistent-keepalive"
|
||||
|
||||
regionLabelKey = "topology.kubernetes.io/region"
|
||||
jsonPatchSlash = "~1"
|
||||
@ -262,6 +263,15 @@ func translateNode(node *v1.Node) *mesh.Node {
|
||||
if !ok {
|
||||
internalIP = node.ObjectMeta.Annotations[internalIPAnnotationKey]
|
||||
}
|
||||
// Set Wireguard PersistentKeepAliveKey.
|
||||
var wireGuardPersistentKeepAlive int64
|
||||
if wgKeepAlive, ok := node.ObjectMeta.Annotations[wireGuardIPAnnotationKey]; !ok {
|
||||
wireGuardPersistentKeepAlive = 0
|
||||
} else {
|
||||
if wireGuardPersistentKeepAlive, err = strconv.ParseInt(wgKeepAlive, 10, 64); err != nil {
|
||||
wireGuardPersistentKeepAlive = 0
|
||||
}
|
||||
}
|
||||
var lastSeen int64
|
||||
if ls, ok := node.ObjectMeta.Annotations[lastSeenAnnotationKey]; !ok {
|
||||
lastSeen = 0
|
||||
@ -287,6 +297,7 @@ func translateNode(node *v1.Node) *mesh.Node {
|
||||
// the node's agent has not yet reconciled. In either case, the IP
|
||||
// will parse as nil.
|
||||
WireGuardIP: normalizeIP(node.ObjectMeta.Annotations[wireGuardIPAnnotationKey]),
|
||||
WireGuardPersistentKeepAlive: wireGuardPersistentKeepAlive,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,6 +111,15 @@ func TestTranslateNode(t *testing.T) {
|
||||
ExternalIP: &net.IPNet{IP: net.ParseIP("10.0.0.2"), Mask: net.CIDRMask(24, 32)},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wireguard persistent keepalive override",
|
||||
annotations: map[string]string{
|
||||
wireGuardPersistentKeepAliveKey: "25",
|
||||
},
|
||||
out: &mesh.Node{
|
||||
WireGuardPersistentKeepAlive: 25,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "internal IP override",
|
||||
annotations: map[string]string{
|
||||
@ -140,6 +149,7 @@ func TestTranslateNode(t *testing.T) {
|
||||
leaderAnnotationKey: "",
|
||||
locationAnnotationKey: "b",
|
||||
wireGuardIPAnnotationKey: "10.4.0.1/16",
|
||||
wireGuardPersistentKeepAliveKey: "25",
|
||||
},
|
||||
labels: map[string]string{
|
||||
regionLabelKey: "a",
|
||||
@ -153,6 +163,7 @@ func TestTranslateNode(t *testing.T) {
|
||||
Location: "b",
|
||||
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)},
|
||||
WireGuardPersistentKeepAlive: 25,
|
||||
},
|
||||
subnet: "10.2.1.0/24",
|
||||
},
|
||||
|
@ -84,6 +84,7 @@ type Node struct {
|
||||
Name string
|
||||
Subnet *net.IPNet
|
||||
WireGuardIP *net.IPNet
|
||||
WireGuardPersistentKeepAlive int64
|
||||
}
|
||||
|
||||
// Ready indicates whether or not the node is ready.
|
||||
|
Loading…
Reference in New Issue
Block a user