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

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

85 lines
2.3 KiB
Nix
Raw Normal View History

import ./make-test-python.nix ({ pkgs, ... }:
2021-10-24 03:34:10 +02:00
let
2021-10-26 02:43:27 +02:00
imageEnv = pkgs.buildEnv {
name = "k3s-pause-image-env";
paths = with pkgs; [ tini (hiPrio coreutils) busybox ];
};
pauseImage = pkgs.dockerTools.streamLayeredImage {
2021-10-24 03:34:10 +02:00
name = "test.local/pause";
tag = "local";
2021-10-26 02:43:27 +02:00
contents = imageEnv;
2021-10-24 03:34:10 +02:00
config.Entrypoint = [ "/bin/tini" "--" "/bin/sleep" "inf" ];
};
# Don't use the default service account because there's a race where it may
# not be created yet; make our own instead.
testPodYaml = pkgs.writeText "test.yml" ''
apiVersion: v1
kind: ServiceAccount
metadata:
name: test
---
apiVersion: v1
kind: Pod
metadata:
name: test
spec:
serviceAccountName: test
containers:
- name: test
image: test.local/pause:local
imagePullPolicy: Never
command: ["sh", "-c", "sleep inf"]
'';
in
{
name = "k3s";
meta = with pkgs.lib.maintainers; {
maintainers = [ euank ];
};
2022-03-21 00:15:30 +01:00
nodes.machine = { pkgs, ... }: {
2021-10-24 03:34:10 +02:00
environment.systemPackages = with pkgs; [ k3s gzip ];
2021-10-24 03:34:10 +02:00
# k3s uses enough resources the default vm fails.
2021-10-26 02:43:27 +02:00
virtualisation.memorySize = 1536;
virtualisation.diskSize = 4096;
2021-10-24 03:34:10 +02:00
services.k3s = {
enable = true;
role = "server";
docker = true;
# Slightly reduce resource usage
extraFlags = "--no-deploy coredns,servicelb,traefik,local-storage,metrics-server --pause-image test.local/pause:local";
};
2021-10-24 03:34:10 +02:00
users.users = {
noprivs = {
isNormalUser = true;
description = "Can't access k3s by default";
password = "*";
};
};
};
2021-10-24 03:34:10 +02:00
testScript = ''
start_all()
2021-10-24 03:34:10 +02:00
machine.wait_for_unit("k3s")
machine.succeed("k3s kubectl cluster-info")
machine.fail("sudo -u noprivs k3s kubectl cluster-info")
2021-10-26 02:43:27 +02:00
# FIXME: this fails with the current nixos kernel config; once it passes, we should uncomment it
# machine.succeed("k3s check-config")
2021-10-24 03:34:10 +02:00
machine.succeed(
2021-10-26 02:43:27 +02:00
"${pauseImage} | docker load"
2021-10-24 03:34:10 +02:00
)
2021-10-24 03:34:10 +02:00
machine.succeed("k3s kubectl apply -f ${testPodYaml}")
machine.succeed("k3s kubectl wait --for 'condition=Ready' pod/test")
machine.succeed("k3s kubectl delete -f ${testPodYaml}")
2021-10-24 03:34:10 +02:00
machine.shutdown()
'';
})