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