vm-tests: a k3s node harness, and the swarm images boot as pods
This commit is contained in:
parent
6d0c0dc391
commit
b7545e27fd
1 changed files with 427 additions and 0 deletions
51
nix/vm-tests/lib/k3s-node.nix
Normal file
51
nix/vm-tests/lib/k3s-node.nix
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
# A single-node k3s server for a NixOS VM test: import it as a node module,
|
||||
# `imports = [ (import ./lib/k3s-node.nix { images = [ … ]; }) ]`.
|
||||
#
|
||||
# - `images`: `dockerTools` image tarballs (`buildLayeredImage`), which k3s'
|
||||
# containerd imports from its image directory at start. Nothing is pulled:
|
||||
# the VM has no network, so a pod names one of these with
|
||||
# `imagePullPolicy: Never`. `/etc/k3s-node/images` lists their references
|
||||
# (`imageName:imageTag`, one per line) for `lib/k3s.py`'s `wait_images`.
|
||||
# - `memoryMiB`: the VM's memory.
|
||||
#
|
||||
# CoreDNS and the local-path provisioner stay on, so a test can use cluster DNS
|
||||
# and PersistentVolumeClaims. The firewall stays on and trusts the pod network's
|
||||
# interfaces, so the node reaches pods on their IPs.
|
||||
#
|
||||
# `lib/k3s.py` holds the Python helpers a test script uses with this node.
|
||||
{
|
||||
images ? [ ],
|
||||
memoryMiB ? 6144,
|
||||
}:
|
||||
{ config, pkgs, ... }:
|
||||
{
|
||||
services.k3s = {
|
||||
enable = true;
|
||||
role = "server";
|
||||
images = [ config.services.k3s.package.airgap-images ] ++ images;
|
||||
extraFlags = [
|
||||
"--disable=traefik,servicelb,metrics-server"
|
||||
"--write-kubeconfig-mode=644"
|
||||
];
|
||||
};
|
||||
|
||||
environment.systemPackages = [
|
||||
pkgs.kubectl
|
||||
pkgs.curl
|
||||
];
|
||||
environment.variables.KUBECONFIG = "/etc/rancher/k3s/k3s.yaml";
|
||||
environment.etc."k3s-node/images".text = pkgs.lib.concatMapStrings (
|
||||
i: "${i.imageName}:${i.imageTag}\n"
|
||||
) images;
|
||||
|
||||
networking.firewall.trustedInterfaces = [
|
||||
"cni0"
|
||||
"flannel.1"
|
||||
];
|
||||
|
||||
virtualisation = {
|
||||
memorySize = memoryMiB;
|
||||
cores = 4;
|
||||
diskSize = 8192;
|
||||
};
|
||||
}
|
||||
Loading…
Reference in a new issue