From 9752f30f3675af898d9e8fdcbbf44915f8497c70 Mon Sep 17 00:00:00 2001 From: atlas Date: Mon, 23 Nov 2026 19:09:02 +0100 Subject: [PATCH] k8s: the queue's client port is a loadbalancer service The queue's client port was a hostPort on 0.0.0.0, which Pod Security baseline and restricted forbid. It is a LoadBalancer Service now, which k3s's service load balancer binds on every address of the node with a hostPort of its own in kube-system, so hives on other hosts keep their URL. No node port is allocated. The stt policy allows the load balancer's pods in place of the queue's, and the prune unit waits for them to go before the host unit starts. The egress published-port rule and the raw-table rules apply to the load balancer's hostPort as to the pod's. --- docs/4-implementation/k8s/runtime.md | 86 +++++++++++-------- docs/4-implementation/networking/network.md | 12 +-- nix/host-modules/k8s/render.nix | 20 +++-- nix/host-modules/k8s/runtime.nix | 10 +++ nix/host-modules/lib/swarm-nats-raw-rules.nix | 15 ++-- nix/host-modules/swarm-nats.nix | 42 +++++++-- nix/module-eval/k8s.nix | 53 ++++++++++-- nix/vm-tests/k8s-nats-switch.nix | 37 ++++++-- 8 files changed, 200 insertions(+), 75 deletions(-) diff --git a/docs/4-implementation/k8s/runtime.md b/docs/4-implementation/k8s/runtime.md index e01e0049b..38a73b38a 100644 --- a/docs/4-implementation/k8s/runtime.md +++ b/docs/4-implementation/k8s/runtime.md @@ -95,7 +95,10 @@ Job: 2. Wait for the cluster's API, then delete the service's Deployment, CronJob, Service, NetworkPolicy and ServiceAccount (selected by `app.kubernetes.io/name`), and wait until its pods have gone. A pod exits 0 - within its termination grace period. + within its termination grace period. Then wait until the pods that the + service load balancer bound the service's Services' ports with, in + `kube-system`, have gone too: the rule that forwards a port to one stays + until the pod does. 3. Delete the cluster's AddOn for the file, so that a later switch to `"k8s"` applies the same manifest again. Then remove the renamed link. @@ -218,21 +221,27 @@ holds the container back until the pod has gone. loopback, so the responder dials the server by the name its leaf carries and verifies it, with no traffic leaving the pod. Every other client reaches the queue by the same name as before: the node's CoreDNS and the bridge's - resolver answer it with the bridge's address, and the published port forwards - it to the pod. -- **The client port.** The server's port is a `hostPort` on `0.0.0.0`, the - addresses the container's server listens on, so hives on other hosts keep - their URL. A `hostPort` is a DNAT rule, and the firewall's INPUT rules, the - ones `deploy.nats.openFirewall` and the bridge's port list write, never see - what it rewrites. The module therefore adds rules to the raw table, which is - read before the DNAT: a packet for the node's address and the client port is + resolver answer it with the bridge's address, and the load balancer's port + forwards it to the pod. +- **The client port.** The server's port is a `LoadBalancer` Service, + `swarm-nats`, with no `hostPort` on the pod. k3s's service load balancer + (servicelb, on by default) binds the port on `0.0.0.0` of the node with a + `hostPort` of its own, in a pod of `kube-system`, and forwards it to the pod + through the Service, so hives on other hosts keep their URL. The Service + allocates no node port: the forwarding uses the Service's cluster address, + and a node port would be a second way in that the raw-table rules don't name. + The server sees the load balancer's pod as the client, not the client's + address. A `hostPort` is a DNAT rule, and the firewall's INPUT rules, the ones + `deploy.nats.openFirewall` and the bridge's port list write, never see what it + rewrites. The module therefore adds rules to the raw table, which the kernel + reads before the DNAT: a packet for the node's address and the client port is dropped unless it arrives on the host's loopback, the hive bridge or a pod interface, or unless `deploy.nats.openFirewall` is on. The container's port - has that reach. The hostPort sends the bridge's agents to the cluster, which a - host with the egress intercept on refuses, so the module also adds the port to - `egress.publishedPorts` + has that reach. The `hostPort` sends the bridge's agents to the cluster, which + a host with the egress intercept on refuses, so the module also adds the port + to `egress.publishedPorts` ([the egress chain](../networking/network.md#agent-bridge-egress-log)): agents - reach the pod through the published port and no other way. + reach the queue through the published port and no other way. - **The exporter's port.** The exporter's port has no `hostPort`: a ClusterIP Service, `swarm-nats-metrics`, fronts it, and the gateway's `/metrics` location on the host dials the Service's name through nginx's `resolver` (the @@ -306,9 +315,9 @@ identity provider, the queue and the hive collector, each on its one port. It admits no ingress. The kubelet's probes still reach the pod, because the node's own traffic to a pod is always admitted, and the pod doesn't serve anything else: requests reach it as queue messages, over the connection it opens. Where -the queue runs in the cluster, the policy also allows the queue's pod on its -port, because the node forwards the queue's `hostPort` to the pod before the -policy sees the packet. +the queue runs in the cluster, the policy also allows the pods of the queue's +load balancer, in `kube-system`, on the queue's port, because the node forwards +the `hostPort` they bind to them before the policy sees the packet. ## Telemetry and credentials of the poller @@ -382,28 +391,31 @@ that `claude` with `HOME` in the volume writes its config there, as the minter's real login step does, while `claude` with `HOME` on the root leaves nothing there. -The VM test `k8s-nats-switch` moves the queue against the real secret store. A -sampler counts servers and responders every 200 ms and sees at most one of -each, and the container and the pod never together. The pod is Ready by its -exec probe and has the init containers, the `hostPort`s and the volumes the -module renders, and its leaf's volume is a tmpfs. A client on the bridge -reaches the queue by name, and a second node outside the node reaches the -control port and not the queue's, as with the container; with `openFirewall` -it dials the pod by name and verifies the name, and the responder in the pod -admits it. A key written on the host before the switch is the pod's to read, a -key the pod writes is the host server's after the switch back, and a stream -written before a pod delete survives it: the replacement pod reads it from the -same directory. The exporter answers the host's own processes through its -Service and no pod or bridge client, and the switch back removes the pod before +The VM test `k8s-nats-switch` moves the queue against the real secret store, +with the egress intercept on. A sampler counts servers and responders every +200 ms and sees at most one of each, and the container and the pod never +together. The pod is Ready by its exec probe and has the init containers, the +volumes and the Services the module renders and no `hostPort`, and its leaf's +volume is a tmpfs. The load balancer binds the client port from `kube-system` +and the Service has no node port. A client on the bridge reaches the queue by +name and through the published port only, not by the pod's address or the +node's, and a second node outside the node reaches the control port and not the +queue's, as with the container; with `openFirewall` it dials the pod by name and +verifies the name, and the responder in the pod admits it. A key written on the +host before the switch is the pod's to read, a key the pod writes is the host +server's after the switch back, and a stream written before a pod delete +survives it: the replacement pod reads it from the same directory. The exporter +answers the host's own processes through its Service and no pod or bridge +client, and the switch back removes the pod and the load balancer's pod before the container starts. The VM test `k8s-controller-switch` moves the controller. It asserts one copy at each step by the switch's own timestamps and by a sampler, that the pod is Ready -on `/readyz` with the `hostPort` and the volumes the module renders and no -Secret, that its listener's leaf is the one its init container issued, valid as -the listener's name against the hive's root, that the volume holding its key is -a tmpfs, and that the listener refuses a client with no leaf. It runs the -gateway's own controller location, from the module's text for each runtime, -against the host unit and the pod: both answer an unsigned webhook 401. A -changed rev rolls the Deployment onto a new pod and keeps the state volume, and -the switch back deletes the pod and its AddOn before the unit starts. +on `/readyz` with the volumes the module renders and no Secret, that its +listener's leaf is the one its init container issued, valid as the listener's +name against the hive's root, that the volume holding its key is a tmpfs, and +that the listener refuses a client with no leaf. It runs the gateway's own +controller location, from the module's text for each runtime, against the host +unit and the pod: both answer an unsigned webhook 401. A changed rev rolls the +Deployment onto a new pod and keeps the state volume, and the switch back +deletes the pod and its AddOn before the unit starts. diff --git a/docs/4-implementation/networking/network.md b/docs/4-implementation/networking/network.md index df65946bc..cc0e21ea7 100644 --- a/docs/4-implementation/networking/network.md +++ b/docs/4-implementation/networking/network.md @@ -763,12 +763,12 @@ also refuses the flow. `services.hyperhive.deploy.hive-controller.egress.publishedPorts`, in both modes, so such a flow leaves no count and no line. A module that publishes a port adds it: the queue in the cluster adds its client port, because the - pod's `hostPort` rewrites the destination to the pod and the packet then - leaves the bridge for the cluster. An agent dials the queue's name, which the - hive's resolver answers with the bridge's address. A flow to the pod's own - address has no redirect, and one to the node's address has another original - destination, so both stay refused. The set is empty, and the chain has no - such rule, while no module publishes a port. + `hostPort` of the cluster's load balancer rewrites the destination, and the + packet then leaves the bridge for the cluster. An agent dials the queue's + name, which the hive's resolver answers with the bridge's address. A flow to + the pod's own address has no redirect, and one to the node's address has + another original destination, so both stay refused. The set is empty, and the + chain has no such rule, while no module publishes a port. - **What `reject` refuses.** Everything from the bridge to the uplink that the chain didn't exempt or allow, whether a flow is new or not: TCP on any port but the 80 and 443 that squid takes, UDP (DNS to an outside resolver, QUIC diff --git a/nix/host-modules/k8s/render.nix b/nix/host-modules/k8s/render.nix index 00e59096f..2befed17f 100644 --- a/nix/host-modules/k8s/render.nix +++ b/nix/host-modules/k8s/render.nix @@ -370,11 +370,11 @@ let }; # What the policy of a pod that reaches `reaches` allows: the cluster's DNS, - # those host ports, and the queue's own pod where the queue runs in the - # cluster, because its `hostPort` is forwarded to the pod before the policy - # sees the packet. The policy selects every pod of the service for ingress - # too and allows none, so only the node's own traffic (the kubelet's probes, - # which the policy engine always admits) reaches it. + # those host ports, and the pods of the queue's load balancer where the queue + # runs in the cluster, because the `hostPort` they bind is forwarded to them + # before the policy sees the packet. The policy selects every pod of the + # service for ingress too and allows none, so only the node's own traffic + # (the kubelet's probes, which the policy engine always admits) reaches it. networkPolicyOf = name: reaches: let @@ -416,7 +416,15 @@ let } ] ++ lib.optional (queueOnCluster && lib.elem "queue" reaches) { - to = [ { podSelector.matchLabels = labelsFor "swarm-nats"; } ]; + to = [ + { + namespaceSelector.matchLabels."kubernetes.io/metadata.name" = "kube-system"; + podSelector.matchLabels = { + "svccontroller.k3s.cattle.io/svcname" = "swarm-nats"; + "svccontroller.k3s.cattle.io/svcnamespace" = k8sCfg.namespace; + }; + } + ]; ports = [ (tcp hostPorts.queue) ]; }; }; diff --git a/nix/host-modules/k8s/runtime.nix b/nix/host-modules/k8s/runtime.nix index 301d3f397..81f863792 100644 --- a/nix/host-modules/k8s/runtime.nix +++ b/nix/host-modules/k8s/runtime.nix @@ -29,6 +29,15 @@ let ''; apiReady = waitFor 600 "the cluster's API" "${kubectl} get --raw /readyz >/dev/null 2>&1"; + # The service load balancer binds a Service's port on the node with a + # `hostPort` in a pod of `kube-system`, which its controller deletes some time + # after the Service. The rule that forwards the port to that pod stays until + # the pod is gone, and would swallow what the host unit then listens on. + lbPodsGone = + name: + waitFor 180 "the load balancer's pods of ${name}" + "[ -z \"\$(${kubectl} --namespace kube-system get pods --selector svccontroller.k3s.cattle.io/svcname=${name},svccontroller.k3s.cattle.io/svcnamespace=${cfg.namespace} --output name)\" ]"; + caFiles = lib.filterAttrs (_: path: path != null) rendered.caSources; # The services on the cluster whose pods run in a user namespace. @@ -148,6 +157,7 @@ in ${kubectl} --namespace ${cfg.namespace} delete deployment,cronjob,serviceaccount,networkpolicy,service \ --selector=app.kubernetes.io/name=${name} \ --cascade=foreground --wait=true --timeout=180s --ignore-not-found + ${lbPodsGone name} ${kubectl} --namespace kube-system delete addons.k3s.cattle.io ${name} --ignore-not-found rm -f "$pending" ''; diff --git a/nix/host-modules/lib/swarm-nats-raw-rules.nix b/nix/host-modules/lib/swarm-nats-raw-rules.nix index 18010d8bd..7d5050f70 100644 --- a/nix/host-modules/lib/swarm-nats-raw-rules.nix +++ b/nix/host-modules/lib/swarm-nats-raw-rules.nix @@ -1,10 +1,11 @@ -# The iptables rules that give the queue pod's client `hostPort` the reach the -# queue's container has. A `hostPort` is a DNAT rule, and what a DNAT rule -# rewrites is forwarded, never delivered to the host: the INPUT rules (the -# firewall's `allowedTCPPorts` and per-interface rules) never see it, and the -# cluster's own forwarding rules accept it. The raw table is read before the -# DNAT and before any of those, so a rule there reads the original -# destination, as INPUT does for the container's listener. +# The iptables rules that give the `hostPort` the cluster's load balancer binds +# for the queue's client port the reach the queue's container has. A +# `hostPort` is a DNAT rule, and what a DNAT rule rewrites is forwarded, never +# delivered to the host: the INPUT rules (the firewall's `allowedTCPPorts` and +# per-interface rules) never see it, and the cluster's own forwarding rules +# accept it. The raw table is read before the DNAT and before any of those, so a +# rule there reads the original destination, as INPUT does for the container's +# listener. # # The client port is dropped for a packet addressed to the host unless it # arrives on one of `trusted` (the host's loopback, the hive bridge and the diff --git a/nix/host-modules/swarm-nats.nix b/nix/host-modules/swarm-nats.nix index 80432334a..44d2abac8 100644 --- a/nix/host-modules/swarm-nats.nix +++ b/nix/host-modules/swarm-nats.nix @@ -984,13 +984,11 @@ let image = ref server; imagePullPolicy = "Never"; args = lib.tail (lib.splitString " " natsSystem.systemd.services.nats.serviceConfig.ExecStart); - # Every address of the node, which is where the queue listens today. + # The port the client Service targets. ports = [ { name = "client"; containerPort = cfg.port; - hostPort = cfg.port; - hostIP = "0.0.0.0"; } ]; # The monitor is on the pod's loopback, so the probe runs in the @@ -1108,6 +1106,34 @@ let ]; }; }; + + # The client port, on every address of the node, which is where the + # queue listens in its container, so the hives of other hosts keep their + # URL. The cluster's service load balancer (k3s's servicelb) binds the + # Service's port on each node with a `hostPort` of its own, in + # `kube-system`, and forwards it to the pod through the Service. It does + # that by the Service's cluster address, so no node port is needed, and + # none is allocated: a node port would be a second way in, which the + # raw-table rules (./lib/swarm-nats-raw-rules.nix) don't name. The server + # sees the load balancer's pod as the client, not the client's address. + objects."${machine}/loadbalancer" = { + apiVersion = "v1"; + kind = "Service"; + metadata = metaFor machine; + spec = { + type = "LoadBalancer"; + allocateLoadBalancerNodePorts = false; + selector = (metaFor machine).labels; + ports = [ + { + name = "client"; + protocol = "TCP"; + port = cfg.port; + targetPort = "client"; + } + ]; + }; + }; objects."${machine}/networkpolicy" = { apiVersion = "networking.k8s.io/v1"; kind = "NetworkPolicy"; @@ -1615,13 +1641,15 @@ in # sets no listen host), so reachability is the firewall alone. networking.firewall.allowedTCPPorts = lib.mkIf deployCfg.nats.openFirewall [ cfg.port ]; - # The pod's client `hostPort` is a DNAT rule, which the INPUT rules above - # never see: ./lib/swarm-nats-raw-rules.nix gives it the container's reach. services.hyperhive.network.enable = lib.mkIf onK8s (lib.mkDefault true); - # An agent dials the queue at the bridge's address; the pod's `hostPort` is - # forwarded to the cluster, which the egress forward chain would refuse. + # An agent dials the queue at the bridge's address, and the load + # balancer's `hostPort` forwards that to the cluster, which the egress + # forward chain would refuse. services.hyperhive.deploy.hive-controller.egress.publishedPorts = lib.mkIf onK8s [ cfg.port ]; + + # The load balancer's `hostPort` is a DNAT rule, which the INPUT rules above + # never see: ./lib/swarm-nats-raw-rules.nix gives it the container's reach. networking.firewall.extraCommands = lib.mkIf onK8s ( import ./lib/swarm-nats-raw-rules.nix { inherit lib; } { chain = "nixos-fw-nats"; diff --git a/nix/module-eval/k8s.nix b/nix/module-eval/k8s.nix index c12e0139d..49bb2fb05 100644 --- a/nix/module-eval/k8s.nix +++ b/nix/module-eval/k8s.nix @@ -1115,8 +1115,10 @@ let { to = [ { - podSelector.matchLabels = objects."swarm-stt/deployment".spec.selector.matchLabels // { - "app.kubernetes.io/name" = "swarm-nats"; + namespaceSelector.matchLabels."kubernetes.io/metadata.name" = "kube-system"; + podSelector.matchLabels = { + "svccontroller.k3s.cattle.io/svcname" = "swarm-nats"; + "svccontroller.k3s.cattle.io/svcnamespace" = "hyperhive"; }; } ]; @@ -1782,15 +1784,13 @@ let "-c" "/var/lib/nats-callout/nats.conf" ] - # The client port is published on every address of the node. The - # exporter's port is named for its Service and has no `hostPort`. + # Both ports are named for their Services, and neither has a `hostPort`: + # the load balancer publishes the client port on the node. && (named "nats").ports == [ { name = "client"; containerPort = 4222; - hostPort = 4222; - hostIP = "0.0.0.0"; } ] && @@ -2025,6 +2025,47 @@ let && has "-t raw -A nixos-fw-nats -p tcp --dport 4222 -m addrtype --dst-type LOCAL -j DROP" onCluster.networking.firewall.extraCommands && has "-t raw -F nixos-fw-nats" onCluster.networking.firewall.extraStopCommands; } + { + # The host with the queue on it renders the same Service, the control that + # a `deploy.nats.runtime` changes none of it. + name = "the queue's client port is a LoadBalancer Service with no node port, and the pod has no hostPort"; + ok = + let + cluster = render onCluster; + svc = cluster."swarm-nats/loadbalancer"; + pod = cluster."swarm-nats/deployment".spec.template; + ports = lib.concatMap (c: c.ports or [ ]) pod.spec.containers; + in + svc.kind == "Service" + && svc.metadata.name == "swarm-nats" + && svc.metadata.labels."app.kubernetes.io/name" == "swarm-nats" + && svc.spec.type == "LoadBalancer" + && svc.spec.allocateLoadBalancerNodePorts == false + && svc.spec.selector == pod.metadata.labels + && + svc.spec.ports == [ + { + name = "client"; + protocol = "TCP"; + port = 4222; + targetPort = "client"; + } + ] + && !(svc.spec ? loadBalancerClass) + && !(svc.spec ? externalTrafficPolicy) + && !(lib.any (p: p ? hostPort || p ? hostIP) ports) + && + lib.sort lib.lessThan (map (p: p.name) ports) == [ + "client" + "health" + "metrics" + ] + && (render withNode)."swarm-nats/loadbalancer" == svc + # Waiting for the load balancer's pods to go is part of every prune, and + # names the service's own Service and namespace. + && lib.hasInfix "--selector svccontroller.k3s.cattle.io/svcname=swarm-nats,svccontroller.k3s.cattle.io/svcnamespace=hyperhive" withNode.systemd.services.swarm-nats-k8s-prune.script + && !(lib.hasInfix "svcname=swarm-nats," withNode.systemd.services.swarm-controller-k8s-prune.script); + } { # The host with the queue on it is the control: it publishes no port, and # its chain has no rule of the kind. diff --git a/nix/vm-tests/k8s-nats-switch.nix b/nix/vm-tests/k8s-nats-switch.nix index 2e586e4f4..321219382 100644 --- a/nix/vm-tests/k8s-nats-switch.nix +++ b/nix/vm-tests/k8s-nats-switch.nix @@ -10,8 +10,8 @@ # sampler counts the processes every 200 ms), and the container and the pod # never overlap; # - the pod is Ready by its exec probe on the server's monitor, holds the leaf -# and the callout config as init containers, and publishes the client port -# on every address, with no `hostPort` on the exporter; +# and the callout config as init containers, and has no `hostPort`: the client +# port is a LoadBalancer Service with no node port, bound by the load balancer; # - with the egress intercept on, a client on the hive's bridge reaches the # queue by name through the published port and not by the pod's address or # the node's, and the responder in the pod admits the router's token; @@ -22,8 +22,8 @@ # - the store is the container's own directory: a key the host server wrote is # read by the pod, and a key the pod wrote is read by the host server after # the switch back, which hands the files back to the server's user; -# - the switch back leaves no pod, Deployment, Service, NetworkPolicy or AddOn, -# and the container starts after the prune unit. +# - the switch back leaves no pod, Service, NetworkPolicy or AddOn, and the +# container starts after the prune unit. # # One stub is the identity provider: it introspects the test's one token as the # notification router, whose permissions create and fill a stream. The test @@ -623,14 +623,14 @@ pkgs.testers.runNixOSTest { machine.fail("test -e /etc/nixos-containers/swarm-nats.conf") assert counts() == (1, 1), counts() - with subtest("the pod holds the leaf and the config as init containers, publishes the client port on every address, and has no hostPort on the exporter"): + with subtest("the pod holds the leaf and the config as init containers, and has no hostPort on the server or the exporter"): spec = pod(machine, pod_name)["spec"] assert [c["name"] for c in spec["initContainers"]] == ["tls-issue", "callout-config"], spec["initContainers"] assert [c["name"] for c in spec["containers"]] == ["swarm-nats", "nats", "tls-renew", "exporter"], spec["containers"] assert spec["shareProcessNamespace"] is True, spec server = next(c for c in spec["containers"] if c["name"] == "nats") client = next(p for p in server["ports"] if p["name"] == "client") - assert client["hostPort"] == PORT and client["hostIP"] == "0.0.0.0", client + assert client == {"name": "client", "containerPort": PORT, "protocol": "TCP"}, client command = server["readinessProbe"]["exec"]["command"] assert command[0] == "/bin/wget" and command[-1].endswith("/healthz?js-enabled-only=true"), command exporter = next(c for c in spec["containers"] if c["name"] == "exporter") @@ -664,6 +664,26 @@ pkgs.testers.runNixOSTest { assert policy["policyTypes"] == ["Ingress"], policy assert policy["ingress"] == [{"ports": [{"port": PORT, "protocol": "TCP"}]}], policy + with subtest("the client port is a LoadBalancer Service with no node port, which the cluster's load balancer binds on the node from kube-system"): + machine.wait_until_succeeds( + f"kubectl -n {NS} get service {SERVICE} -o jsonpath='{{.status.loadBalancer.ingress[0].ip}}' | grep -q .", + timeout=300, + ) + svc = json.loads(kube(machine, f"get service {SERVICE} -o json")) + assert svc["spec"]["type"] == "LoadBalancer", svc["spec"] + assert svc["spec"]["allocateLoadBalancerNodePorts"] is False, svc["spec"] + assert [(p["port"], p["targetPort"]) for p in svc["spec"]["ports"]] == [(PORT, "client")], svc["spec"] + assert not any("nodePort" in p for p in svc["spec"]["ports"]), svc["spec"] + lb_pods = json.loads(kube(machine, f"-n kube-system get pods --selector svccontroller.k3s.cattle.io/svcname={SERVICE} -o json"))["items"] + assert len(lb_pods) == 1, lb_pods + lb_ports = [p for c in lb_pods[0]["spec"]["containers"] for p in c.get("ports", [])] + assert [(p["hostPort"], p["containerPort"]) for p in lb_ports] == [(PORT, PORT)], lb_ports + assert all(p.get("hostIP", "") in ("", "0.0.0.0") for p in lb_ports), lb_ports + # No node port: the Service has a rule for its cluster address, the + # control that the lookup finds it, and none in the chain of node ports. + assert f"hyperhive/{SERVICE}:client" in machine.succeed("iptables -t nat -S KUBE-SERVICES") + assert f"hyperhive/{SERVICE}:client" not in machine.succeed("iptables -t nat -S KUBE-NODEPORTS") + with subtest("one server and one responder run, and the queue answers by name with its name verified"): assert counts() == (1, 1), counts() assert probe(machine, BRIDGE)[0], probe(machine, BRIDGE) @@ -769,7 +789,12 @@ pkgs.testers.runNixOSTest { assert pods() == [], pods() assert machine.execute(f"kubectl -n {NS} get deployment {SERVICE}")[0] != 0 assert machine.execute(f"kubectl -n {NS} get service {METRICS_SERVICE}")[0] != 0 + assert machine.execute(f"kubectl -n {NS} get service {SERVICE}")[0] != 0 assert machine.execute(f"kubectl -n {NS} get networkpolicy {SERVICE}")[0] != 0 + # The load balancer's pod and its `hostPort` rule are gone before the + # container listens on the port. + assert machine.succeed(f"kubectl -n kube-system get pods --selector svccontroller.k3s.cattle.io/svcname={SERVICE} -o name").strip() == "" + assert f"--dport {PORT} " not in machine.succeed("iptables -t nat -S") assert machine.execute(f"kubectl -n kube-system get addons.k3s.cattle.io {SERVICE}")[0] != 0 assert machine.execute(f"test -e {MANIFESTS}/{SERVICE}.yaml")[0] != 0 assert machine.execute(f"test -e {MANIFESTS}/{SERVICE}.yaml.pruning")[0] != 0