nixpkgs/nixos/tests/k3s/single-node.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

86 lines
2.5 KiB
Nix
Raw Normal View History

import ../make-test-python.nix ({ pkgs, lib, k3s, ... }:
2021-10-24 01:34:10 +00:00
let
2021-10-26 00:43:27 +00:00
imageEnv = pkgs.buildEnv {
name = "k3s-pause-image-env";
paths = with pkgs; [ tini (hiPrio coreutils) busybox ];
};
pauseImage = pkgs.dockerTools.streamLayeredImage {
2021-10-24 01:34:10 +00:00
name = "test.local/pause";
tag = "local";
2021-10-26 00:43:27 +00:00
contents = imageEnv;
2021-10-24 01:34:10 +00:00
config.Entrypoint = [ "/bin/tini" "--" "/bin/sleep" "inf" ];
};
testPodYaml = pkgs.writeText "test.yml" ''
apiVersion: v1
kind: Pod
metadata:
name: test
spec:
containers:
- name: test
image: test.local/pause:local
imagePullPolicy: Never
command: ["sh", "-c", "sleep inf"]
'';
in
{
name = "${k3s.name}-single-node";
2021-10-24 01:34:10 +00:00
meta = with pkgs.lib.maintainers; {
2022-10-04 17:06:48 +00:00
maintainers = [ euank ];
2021-10-24 01:34:10 +00:00
};
2022-03-20 23:15:30 +00:00
nodes.machine = { pkgs, ... }: {
2021-10-24 01:34:10 +00:00
environment.systemPackages = with pkgs; [ k3s gzip ];
2021-10-24 01:34:10 +00:00
# k3s uses enough resources the default vm fails.
2021-10-26 00:43:27 +00:00
virtualisation.memorySize = 1536;
virtualisation.diskSize = 4096;
2021-10-24 01:34:10 +00:00
services.k3s.enable = true;
services.k3s.role = "server";
services.k3s.package = k3s;
2021-10-24 01:34:10 +00:00
# Slightly reduce resource usage
services.k3s.extraFlags = builtins.toString [
"--disable" "coredns"
"--disable" "local-storage"
"--disable" "metrics-server"
"--disable" "servicelb"
"--disable" "traefik"
"--pause-image" "test.local/pause:local"
];
2021-10-24 01:34:10 +00:00
users.users = {
noprivs = {
isNormalUser = true;
description = "Can't access k3s by default";
password = "*";
};
};
};
2021-10-24 01:34:10 +00:00
testScript = ''
start_all()
2021-10-24 01:34:10 +00:00
machine.wait_for_unit("k3s")
2023-04-27 19:24:37 +00:00
machine.succeed("kubectl cluster-info")
machine.fail("sudo -u noprivs kubectl cluster-info")
'' # Fix-Me: Tests fail for 'aarch64-linux' as: "CONFIG_CGROUP_FREEZER: missing (fail)"
+ lib.optionalString (!pkgs.stdenv.isAarch64) ''machine.succeed("k3s check-config")'' + ''
2021-10-24 01:34:10 +00:00
machine.succeed(
2023-04-27 19:24:37 +00:00
"${pauseImage} | ctr image import -"
2021-10-24 01:34:10 +00:00
)
# Also wait for our service account to show up; it takes a sec
2023-04-27 19:24:37 +00:00
machine.wait_until_succeeds("kubectl get serviceaccount default")
machine.succeed("kubectl apply -f ${testPodYaml}")
machine.succeed("kubectl wait --for 'condition=Ready' pod/test")
machine.succeed("kubectl delete -f ${testPodYaml}")
# regression test for #176445
machine.fail("journalctl -o cat -u k3s.service | grep 'ipset utility not found'")
2021-10-24 01:34:10 +00:00
machine.shutdown()
'';
})