vuls: init at 0.27.0
[NixPkgs.git] / nixos / tests / rke2 / single-node.nix
blob5a512eacca0f197c571fd6bc3d551bd33535202b
1 import ../make-test-python.nix ({ pkgs, lib, rke2, ... }:
2   let
3     pauseImage = pkgs.dockerTools.streamLayeredImage {
4       name = "test.local/pause";
5       tag = "local";
6       contents = pkgs.buildEnv {
7         name = "rke2-pause-image-env";
8         paths = with pkgs; [ tini (hiPrio coreutils) busybox ];
9       };
10       config.Entrypoint = [ "/bin/tini" "--" "/bin/sleep" "inf" ];
11     };
12     testPodYaml = pkgs.writeText "test.yaml" ''
13       apiVersion: v1
14       kind: Pod
15       metadata:
16         name: test
17       spec:
18         containers:
19         - name: test
20           image: test.local/pause:local
21           imagePullPolicy: Never
22           command: ["sh", "-c", "sleep inf"]
23     '';
24   in
25   {
26     name = "${rke2.name}-single-node";
27     meta.maintainers = rke2.meta.maintainers;
29     nodes.machine = { pkgs, ... }: {
30       networking.firewall.enable = false;
31       networking.useDHCP = false;
32       networking.defaultGateway = "192.168.1.1";
33       networking.interfaces.eth1.ipv4.addresses = pkgs.lib.mkForce [
34         { address = "192.168.1.1"; prefixLength = 24; }
35       ];
37       virtualisation.memorySize = 1536;
38       virtualisation.diskSize = 4096;
40       services.rke2 = {
41         enable = true;
42         role = "server";
43         package = rke2;
44         nodeIP = "192.168.1.1";
45         disable = [
46           "rke2-coredns"
47           "rke2-metrics-server"
48           "rke2-ingress-nginx"
49         ];
50         extraFlags = [
51           "--cluster-reset"
52         ];
53       };
54     };
56     testScript = let
57       kubectl = "${pkgs.kubectl}/bin/kubectl --kubeconfig=/etc/rancher/rke2/rke2.yaml";
58       ctr = "${pkgs.containerd}/bin/ctr -a /run/k3s/containerd/containerd.sock";
59     in ''
60       start_all()
62       machine.wait_for_unit("rke2")
63       machine.succeed("${kubectl} cluster-info")
64       machine.wait_until_succeeds(
65         "${pauseImage} | ${ctr} -n k8s.io image import -"
66       )
68       machine.wait_until_succeeds("${kubectl} get serviceaccount default")
69       machine.succeed("${kubectl} apply -f ${testPodYaml}")
70       machine.succeed("${kubectl} wait --for 'condition=Ready' pod/test")
71       machine.succeed("${kubectl} delete -f ${testPodYaml}")
73       machine.shutdown()
74     '';
75   })