1 import ../make-test-python.nix ({ pkgs, lib, k3s, etcd, ... }:
4 name = "${k3s.name}-etcd";
12 listenClientUrls = [ "http://192.168.1.1:2379" "http://127.0.0.1:2379" ];
13 listenPeerUrls = [ "http://192.168.1.1:2380" ];
14 initialAdvertisePeerUrls = [ "http://192.168.1.1:2380" ];
15 initialCluster = [ "etcd=http://192.168.1.1:2380" ];
19 defaultGateway = "192.168.1.1";
20 interfaces.eth1.ipv4.addresses = pkgs.lib.mkForce [
21 { address = "192.168.1.1"; prefixLength = 24; }
26 k3s = { pkgs, ... }: {
27 environment.systemPackages = with pkgs; [ jq ];
28 # k3s uses enough resources the default vm fails.
29 virtualisation.memorySize = 1536;
30 virtualisation.diskSize = 4096;
35 extraFlags = builtins.toString [
36 "--datastore-endpoint=\"http://192.168.1.1:2379\""
38 "--disable" "local-storage"
39 "--disable" "metrics-server"
40 "--disable" "servicelb"
42 "--node-ip" "192.168.1.2"
48 allowedTCPPorts = [ 2379 2380 6443 ];
49 allowedUDPPorts = [ 8472 ];
52 defaultGateway = "192.168.1.2";
53 interfaces.eth1.ipv4.addresses = pkgs.lib.mkForce [
54 { address = "192.168.1.2"; prefixLength = 24; }
62 with subtest("should start etcd"):
64 etcd.wait_for_unit("etcd.service")
66 with subtest("should wait for etcdctl endpoint status to succeed"):
67 etcd.wait_until_succeeds("etcdctl endpoint status")
69 with subtest("should start k3s"):
71 k3s.wait_for_unit("k3s")
73 with subtest("should test if kubectl works"):
74 k3s.wait_until_succeeds("k3s kubectl get node")
76 with subtest("should wait for service account to show up; takes a sec"):
77 k3s.wait_until_succeeds("k3s kubectl get serviceaccount default")
79 with subtest("should create a sample secret object"):
80 k3s.succeed("k3s kubectl create secret generic nixossecret --from-literal thesecret=abacadabra")
82 with subtest("should check if secret is correct"):
83 k3s.wait_until_succeeds("[[ $(kubectl get secrets nixossecret -o json | jq -r .data.thesecret | base64 -d) == abacadabra ]]")
85 with subtest("should have a secret in database"):
86 etcd.wait_until_succeeds("[[ $(etcdctl get /registry/secrets/default/nixossecret | head -c1 | wc -c) -ne 0 ]]")
88 with subtest("should delete the secret"):
89 k3s.succeed("k3s kubectl delete secret nixossecret")
91 with subtest("should not have a secret in database"):
92 etcd.wait_until_fails("[[ $(etcdctl get /registry/secrets/default/nixossecret | head -c1 | wc -c) -ne 0 ]]")
94 with subtest("should shutdown k3s and etcd"):
99 meta.maintainers = etcd.meta.maintainers ++ k3s.meta.maintainers;