Watch
0
0
Fork
You've already forked hyperhive
0

move flannel's wireguard port to 51830, advertise the node address as the tunnel endpoint, drop the 51820 assertion

This commit is contained in:
atlas 2026-11-27 23:06:25 +01:00
commit 1a9fab57f5

View file

@ -67,10 +67,21 @@ let
swarm.hives.h2.domain = "h2.t.local";
};
# The mesh interface a federated hive runs on the same host (`wg0` on UDP
# 51820, as in the semi-spread example), which the two fixtures below carry:
# a host that is a cluster node and in the mesh is the expected deployment.
semiSpreadWg = {
networking.wireguard.interfaces.wg0 = {
ips = [ "10.77.0.2/24" ];
listenPort = 51820;
privateKeyFile = "/etc/wireguard/wg0.key";
};
};
# A host that joins that cluster: an agent with the store identity its join
# token is read under. The only fixture without `deploy.k8s.enable`, which
# is what it claims about.
joined = hive {
joined = hiveWith [ semiSpreadWg ] {
deploy.k8s.join.server = "192.168.1.10";
deploy.k8s.address = "192.168.1.11";
deploy.hive-controller.tls = {
@ -117,27 +128,16 @@ let
nodeOffRefusals = lib.filter (a: !a.assertion) nodeOffRefused.assertions;
# A node every assertion refuses: no rendering, a pod range containing the
# hive bridge's subnet, a service range inside the pod range, and a WireGuard
# interface on the port flannel's tunnel binds.
nodeRefused =
hiveWith
[
{
networking.wireguard.interfaces.wg0 = {
listenPort = 51820;
privateKeyFile = "/etc/wireguard/wg0.key";
};
}
]
{
deploy.k8s.enable = true;
k8s.enable = false;
network.enable = true;
deploy.k8s.podCidr = "10.42.0.0/16";
deploy.k8s.serviceCidr = "10.42.128.0/17";
};
# hive bridge's subnet, and a service range inside the pod range.
nodeRefused = hive {
deploy.k8s.enable = true;
k8s.enable = false;
network.enable = true;
deploy.k8s.podCidr = "10.42.0.0/16";
deploy.k8s.serviceCidr = "10.42.128.0/17";
};
# The node on a host with no hive bridge, so no address to resolve names to.
nodeNoBridge = hive { deploy.k8s.enable = true; };
nodeNoBridge = hiveWith [ semiSpreadWg ] { deploy.k8s.enable = true; };
coreDnsKey = "hyperhive-host-services.override";
refusals = lib.filter (a: !a.assertion) nodeRefused.assertions;
refuses = needle: lib.any (a: hasInfix needle a.message) refusals;
@ -435,10 +435,50 @@ let
&& !(lib.elem "flannel.1" joined.networking.firewall.trustedInterfaces);
}
{
# The all-local host, with no WireGuard interface, is the control: every
# assertion holds there.
name = "the node refuses a WireGuard interface of the host's own on the port flannel's tunnel binds";
ok = lib.all (a: a.assertion) withNode.assertions && refuses "flannel's WireGuard tunnel on UDP";
# The mesh interface is the control that the fixtures carry what the
# case is about, and its port is what the tunnel must not take.
name = "a cluster node that is also in the semi-spread mesh evaluates, and flannel's tunnel listens on a port other than the mesh's";
ok =
let
port = nodeNoBridge.services.hyperhive.deploy.k8s.flannelWgPort;
# The net-conf spelled out here, so the path (a hash of its text) says
# what the file holds, the tunnel's port among it.
expected = pkgs.writeText "flannel-net-conf.json" (
builtins.toJSON {
Network = "10.200.0.0/16";
EnableIPv4 = true;
EnableIPv6 = false;
IPv6Network = "::/0";
Backend = {
Type = "wireguard";
PersistentKeepaliveInterval = 25;
ListenPort = port;
};
}
);
flag = "--flannel-conf=${expected}";
in
nodeNoBridge.networking.wireguard.interfaces.wg0.listenPort == 51820
&& joined.networking.wireguard.interfaces.wg0.listenPort == 51820
&& lib.all (a: a.assertion) nodeNoBridge.assertions
&& lib.all (a: a.assertion) joined.assertions
&& port != 51820
&& joined.services.hyperhive.deploy.k8s.flannelWgPort == port
&& lib.elem flag nodeNoBridge.services.k3s.extraFlags
&& lib.elem flag withNode.services.k3s.extraFlags
&& lib.elem flag joined.services.k3s.extraFlags;
}
{
# Without an address, the node of the same server is the control: it
# advertises no external IP, and the tunnel follows the default route.
name = "a node with an address advertises it as its external IP so flannel's tunnel runs on it, and the server asks flannel to use external IPs";
ok =
lib.elem "--node-external-ip=192.168.1.10" withNode.services.k3s.extraFlags
&& lib.elem "--flannel-external-ip" withNode.services.k3s.extraFlags
&& lib.elem "--node-external-ip=192.168.1.11" joined.services.k3s.extraFlags
&& !(lib.elem "--flannel-external-ip" joined.services.k3s.extraFlags)
&& lib.elem "--flannel-external-ip" nodeNoBridge.services.k3s.extraFlags
&& !(lib.any (lib.hasPrefix "--node-external-ip") nodeNoBridge.services.k3s.extraFlags);
}
{
# The names are the control that the search finds something: the swarm's
@ -2840,7 +2880,7 @@ let
forNodes = address: [
(rule address "tcp" "6443")
(rule address "tcp" "10250")
(rule address "udp" "51820")
(rule address "udp" (toString onCluster.services.hyperhive.deploy.k8s.flannelWgPort))
(rule address "tcp" "5001")
];
nodeLines = lib.filter (l: hasInfix "--dport" l && hasInfix "nixos-fw -s" l) (
@ -2851,10 +2891,12 @@ let
&& lib.length nodeLines == 8
&& !(hasInfix "--dport 6443" nodeNoBridge.networking.firewall.extraCommands)
&& !(lib.elem 6443 onCluster.networking.firewall.allowedTCPPorts)
&& !(lib.elem 51820 onCluster.networking.firewall.allowedUDPPorts)
&& !(lib.elem onCluster.services.hyperhive.deploy.k8s.flannelWgPort onCluster.networking.firewall.allowedUDPPorts)
&& !(hasInfix "8472" rules)
&& !(hasInfix "8472" joined.networking.firewall.extraCommands)
&& hasInfix (rule "192.168.1.10" "udp" "51820") joined.networking.firewall.extraCommands;
&& hasInfix (rule "192.168.1.10" "udp" (
toString joined.services.hyperhive.deploy.k8s.flannelWgPort
)) joined.networking.firewall.extraCommands;
}
{
# The main node is the control for each absence.