vm-tests: k8s-node boots a node through deploy.k8s.enable
This commit is contained in:
parent
9654aa0ac7
commit
2cad6da060
5 changed files with 115 additions and 0 deletions
|
|
@ -54,6 +54,7 @@ jobs:
|
||||||
- full-setup
|
- full-setup
|
||||||
- semi-spread
|
- semi-spread
|
||||||
- k8s-swarm-images
|
- k8s-swarm-images
|
||||||
|
- k8s-node
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
if: inputs.test == '' || inputs.test == matrix.test
|
if: inputs.test == '' || inputs.test == matrix.test
|
||||||
|
|
|
||||||
|
|
@ -120,3 +120,5 @@ phase or readiness, read a container's state, fetch a pod's health endpoint,
|
||||||
and delete a pod while recording its exit and how long the delete took.
|
and delete a pod while recording its exit and how long the delete took.
|
||||||
`k8s-swarm-images` boots the swarm daemons' images as pods on it. Run a k3s
|
`k8s-swarm-images` boots the swarm daemons' images as pods on it. Run a k3s
|
||||||
test on its own, by name: the all-tests run can pass the one-hour job limit.
|
test on its own, by name: the all-tests run can pass the one-hour job limit.
|
||||||
|
`k8s-node` boots a host with `services.hyperhive.deploy.k8s.enable` instead,
|
||||||
|
so the node is the module's own and not the harness's.
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,7 @@ let
|
||||||
semi-spread
|
semi-spread
|
||||||
swarm-builder-offline
|
swarm-builder-offline
|
||||||
k8s-swarm-images
|
k8s-swarm-images
|
||||||
|
k8s-node
|
||||||
;
|
;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
|
|
|
||||||
|
|
@ -16,5 +16,6 @@
|
||||||
swarm-builder-offline = import ./vm-tests/swarm-builder-offline.nix { inherit pkgs self; };
|
swarm-builder-offline = import ./vm-tests/swarm-builder-offline.nix { inherit pkgs self; };
|
||||||
full-setup = import ./vm-tests/full-setup.nix { inherit pkgs self; };
|
full-setup = import ./vm-tests/full-setup.nix { inherit pkgs self; };
|
||||||
k8s-swarm-images = import ./vm-tests/k8s-swarm-images.nix { inherit pkgs self; };
|
k8s-swarm-images = import ./vm-tests/k8s-swarm-images.nix { inherit pkgs self; };
|
||||||
|
k8s-node = import ./vm-tests/k8s-node.nix { inherit pkgs self; };
|
||||||
semi-spread = import ./vm-tests/semi-spread.nix { inherit pkgs self; };
|
semi-spread = import ./vm-tests/semi-spread.nix { inherit pkgs self; };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
110
nix/vm-tests/k8s-node.nix
Normal file
110
nix/vm-tests/k8s-node.nix
Normal file
|
|
@ -0,0 +1,110 @@
|
||||||
|
# `vmTests.<system>.k8s-node`: a host with `services.hyperhive.deploy.k8s.enable`
|
||||||
|
# (../host-modules/k8s/node.nix) boots a single-node k3s. The node is the
|
||||||
|
# module's own configuration, not a hand-written one, and its one in-cluster
|
||||||
|
# service is the CI run poller, whose image the module loads. The script
|
||||||
|
# asserts:
|
||||||
|
#
|
||||||
|
# - the node is Ready within 300 s of boot, and containerd lists every image
|
||||||
|
# the module loads (`system.build.k8sImages`);
|
||||||
|
# - the cluster encrypts its Secrets, runs CoreDNS, and runs neither traefik
|
||||||
|
# nor metrics-server;
|
||||||
|
# - the cluster holds no hyperhive workload: its namespace does not exist and
|
||||||
|
# no pod runs one of the images;
|
||||||
|
# - the node takes pod and service addresses from the module's ranges and the
|
||||||
|
# hive bridge keeps its own, so the two do not share a subnet;
|
||||||
|
# - the firewall trusts `cni0`, and still guards the other interfaces.
|
||||||
|
#
|
||||||
|
# The poller's own host unit and its trust bundle unit stay as they are on the
|
||||||
|
# host and fail here, which nothing in this test reads.
|
||||||
|
{ pkgs, self }:
|
||||||
|
let
|
||||||
|
inherit (pkgs) lib;
|
||||||
|
in
|
||||||
|
pkgs.testers.runNixOSTest {
|
||||||
|
name = "k8s-node";
|
||||||
|
|
||||||
|
# Under the 20 min budget for one dispatched run; the runner's job bound is 1 h.
|
||||||
|
globalTimeout = 1500;
|
||||||
|
|
||||||
|
nodes.machine =
|
||||||
|
{ config, ... }:
|
||||||
|
{
|
||||||
|
imports = [ self.nixosModules.default ];
|
||||||
|
|
||||||
|
services.hyperhive = {
|
||||||
|
deploy.k8s.enable = true;
|
||||||
|
network.enable = true;
|
||||||
|
deploy.ci-metrics.enable = true;
|
||||||
|
deploy.bao.ciMetricsClientCertFile = "/var/lib/ci-metrics/client.pem";
|
||||||
|
deploy.bao.ciMetricsClientKeyFile = "/var/lib/ci-metrics/client-key.pem";
|
||||||
|
deploy.hive-controller.hiveName = "h1";
|
||||||
|
swarm.domain = "t.local";
|
||||||
|
swarm.hives.h1.domain = "h1.t.local";
|
||||||
|
};
|
||||||
|
system.stateVersion = "25.11";
|
||||||
|
|
||||||
|
environment.systemPackages = [
|
||||||
|
pkgs.kubectl
|
||||||
|
pkgs.curl
|
||||||
|
];
|
||||||
|
environment.variables.KUBECONFIG = "/etc/rancher/k3s/k3s.yaml";
|
||||||
|
|
||||||
|
# The references `lib/k3s.py`'s `wait_images` looks for.
|
||||||
|
environment.etc."k3s-node/images".text = lib.concatMapStrings (
|
||||||
|
i: "${i.imageName}:${i.imageTag}\n"
|
||||||
|
) config.system.build.k8sImages;
|
||||||
|
|
||||||
|
virtualisation = {
|
||||||
|
memorySize = 4096;
|
||||||
|
cores = 4;
|
||||||
|
diskSize = 8192;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
testScript = builtins.readFile ./lib/k3s.py + ''
|
||||||
|
|
||||||
|
with subtest("the node is Ready and holds every image the module loads"):
|
||||||
|
wait_node_ready(machine, timeout=300)
|
||||||
|
refs = image_refs(machine)
|
||||||
|
assert refs == ["hyperhive/swarm-ci-metrics:" + refs[0].split(":", 1)[1]], refs
|
||||||
|
wait_images(machine)
|
||||||
|
|
||||||
|
with subtest("the cluster encrypts its secrets and runs CoreDNS but neither traefik nor metrics-server"):
|
||||||
|
status = machine.succeed("k3s secrets-encrypt status")
|
||||||
|
assert "Encryption Status: Enabled" in status, status
|
||||||
|
machine.wait_until_succeeds(
|
||||||
|
"kubectl -n kube-system rollout status deployment/coredns --timeout=5s", timeout=120
|
||||||
|
)
|
||||||
|
deployments = kube(machine, "-n kube-system get deployments -o name").split()
|
||||||
|
assert "deployment.apps/coredns" in deployments, deployments
|
||||||
|
for name in ["traefik", "metrics-server"]:
|
||||||
|
assert f"deployment.apps/{name}" not in deployments, deployments
|
||||||
|
|
||||||
|
with subtest("the cluster holds no hyperhive workload"):
|
||||||
|
machine.fail("kubectl get namespace hyperhive")
|
||||||
|
pods = json.loads(kube(machine, "get pods -A -o json"))["items"]
|
||||||
|
images = [c["image"] for p in pods for c in p["spec"]["containers"]]
|
||||||
|
assert images, "no pod runs: the lookup finds nothing"
|
||||||
|
assert not [i for i in images if "hyperhive/" in i], images
|
||||||
|
|
||||||
|
with subtest("the pods and services use the module's ranges, apart from the hive bridge"):
|
||||||
|
pod_cidr = kube(machine, "get node -o jsonpath='{.items[0].spec.podCIDR}'")
|
||||||
|
assert pod_cidr == "10.200.0.0/24", pod_cidr
|
||||||
|
svc_ip = kube(machine, "get service kubernetes -o jsonpath='{.spec.clusterIP}'")
|
||||||
|
assert svc_ip == "10.201.0.1", svc_ip
|
||||||
|
dns_ip = kube(machine, "-n kube-system get service kube-dns -o jsonpath='{.spec.clusterIP}'")
|
||||||
|
assert dns_ip == "10.201.0.10", dns_ip
|
||||||
|
cni = machine.wait_until_succeeds("ip -4 -o addr show dev cni0", timeout=60)
|
||||||
|
assert "10.200.0.1/24" in cni, cni
|
||||||
|
bridge = machine.succeed("ip -4 -o addr show dev hive-br0")
|
||||||
|
assert "10.42.0.1/24" in bridge, bridge
|
||||||
|
assert "10.42.0.1" not in cni, cni
|
||||||
|
|
||||||
|
with subtest("the firewall trusts the pod network and guards the other interfaces"):
|
||||||
|
rules = machine.succeed("iptables -S nixos-fw")
|
||||||
|
assert "-i cni0 " in rules, rules
|
||||||
|
assert "-i flannel.1 " in rules, rules
|
||||||
|
assert "-i lo " in rules, rules
|
||||||
|
assert "-i eth0 " not in rules, rules
|
||||||
|
'';
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue