From b298bbfce0151c4b4b35bb902b0ef417d5c61da7 Mon Sep 17 00:00:00 2001 From: superherointj <5861043+superherointj@users.noreply.github.com> Date: Fri, 12 Jul 2024 10:21:16 -0300 Subject: [PATCH 1/6] k3s/nixos/tests: move comments to test (clean-up) --- nixos/tests/k3s/auto-deploy.nix | 1 + nixos/tests/k3s/default.nix | 4 ---- nixos/tests/k3s/etcd.nix | 1 + nixos/tests/k3s/multi-node.nix | 1 + nixos/tests/k3s/single-node.nix | 1 + 5 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nixos/tests/k3s/auto-deploy.nix b/nixos/tests/k3s/auto-deploy.nix index 19be88dc7402..d60aede950e7 100644 --- a/nixos/tests/k3s/auto-deploy.nix +++ b/nixos/tests/k3s/auto-deploy.nix @@ -1,3 +1,4 @@ +# Tests whether container images are imported and auto deploying manifests work import ../make-test-python.nix ( { pkgs, diff --git a/nixos/tests/k3s/default.nix b/nixos/tests/k3s/default.nix index 529cf312be7e..6825ba997fdb 100644 --- a/nixos/tests/k3s/default.nix +++ b/nixos/tests/k3s/default.nix @@ -7,9 +7,7 @@ let allK3s = lib.filterAttrs (n: _: lib.strings.hasPrefix "k3s_" n) pkgs; in { - # Test whether container images are imported and auto deploying manifests work auto-deploy = lib.mapAttrs (_: k3s: import ./auto-deploy.nix { inherit system pkgs k3s; }) allK3s; - # Testing K3s with Etcd backend etcd = lib.mapAttrs ( _: k3s: import ./etcd.nix { @@ -17,8 +15,6 @@ in inherit (pkgs) etcd; } ) allK3s; - # Run a single node k3s cluster and verify a pod can run single-node = lib.mapAttrs (_: k3s: import ./single-node.nix { inherit system pkgs k3s; }) allK3s; - # Run a multi-node k3s cluster and verify pod networking works across nodes multi-node = lib.mapAttrs (_: k3s: import ./multi-node.nix { inherit system pkgs k3s; }) allK3s; } diff --git a/nixos/tests/k3s/etcd.nix b/nixos/tests/k3s/etcd.nix index fa6012afd54c..149185d551d7 100644 --- a/nixos/tests/k3s/etcd.nix +++ b/nixos/tests/k3s/etcd.nix @@ -1,3 +1,4 @@ +# Tests K3s with Etcd backend import ../make-test-python.nix ( { pkgs, diff --git a/nixos/tests/k3s/multi-node.nix b/nixos/tests/k3s/multi-node.nix index 504ac10d96c1..361f4946660d 100644 --- a/nixos/tests/k3s/multi-node.nix +++ b/nixos/tests/k3s/multi-node.nix @@ -1,3 +1,4 @@ +# A test that runs a multi-node k3s cluster and verify pod networking works across nodes import ../make-test-python.nix ( { pkgs, diff --git a/nixos/tests/k3s/single-node.nix b/nixos/tests/k3s/single-node.nix index 220f6086b092..e0bc80e8614f 100644 --- a/nixos/tests/k3s/single-node.nix +++ b/nixos/tests/k3s/single-node.nix @@ -1,3 +1,4 @@ +# A test that runs a single node k3s cluster and verify a pod can run import ../make-test-python.nix ( { pkgs, From 7f82c994bdc3ac2b7385895a69a8729c3fff50b6 Mon Sep 17 00:00:00 2001 From: superherointj <5861043+superherointj@users.noreply.github.com> Date: Fri, 12 Jul 2024 11:10:01 -0300 Subject: [PATCH 2/6] k3s: use nixosTests.k3s as source reference for tests --- pkgs/applications/networking/cluster/k3s/builder.nix | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pkgs/applications/networking/cluster/k3s/builder.nix b/pkgs/applications/networking/cluster/k3s/builder.nix index 4973b5e67db9..415697a3ad33 100644 --- a/pkgs/applications/networking/cluster/k3s/builder.nix +++ b/pkgs/applications/networking/cluster/k3s/builder.nix @@ -418,12 +418,8 @@ buildGoModule rec { let k3s_version = "k3s_" + lib.replaceStrings [ "." ] [ "_" ] (lib.versions.majorMinor version); in - { - auto-deploy = nixosTests.k3s.auto-deploy.${k3s_version}; - etcd = nixosTests.k3s.etcd.${k3s_version}; - single-node = nixosTests.k3s.single-node.${k3s_version}; - multi-node = nixosTests.k3s.multi-node.${k3s_version}; - }; + lib.mapAttrs (name: value: nixosTests.k3s.${name}.${k3s_version}) nixosTests.k3s; + passthru.tests = passthru.mkTests k3sVersion; meta = baseMeta; From 4556d198f134719637f0b50e27dd34577255627b Mon Sep 17 00:00:00 2001 From: superherointj <5861043+superherointj@users.noreply.github.com> Date: Fri, 12 Jul 2024 11:26:05 -0300 Subject: [PATCH 3/6] k3s: remove nested with --- pkgs/applications/networking/cluster/k3s/builder.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/applications/networking/cluster/k3s/builder.nix b/pkgs/applications/networking/cluster/k3s/builder.nix index 415697a3ad33..5c2820300b3f 100644 --- a/pkgs/applications/networking/cluster/k3s/builder.nix +++ b/pkgs/applications/networking/cluster/k3s/builder.nix @@ -88,12 +88,12 @@ lib: # make sure they're in the path if desired. let - baseMeta = with lib; { + baseMeta = { description = "Lightweight Kubernetes distribution"; - license = licenses.asl20; + license = lib.licenses.asl20; homepage = "https://k3s.io"; maintainers = lib.teams.k3s.members; - platforms = platforms.linux; + platforms = lib.platforms.linux; # resolves collisions with other installations of kubectl, crictl, ctr # prefer non-k3s versions From e72a3ac6b41a672f1d1c5760b5ee9485e65d3017 Mon Sep 17 00:00:00 2001 From: superherointj <5861043+superherointj@users.noreply.github.com> Date: Fri, 12 Jul 2024 11:31:33 -0300 Subject: [PATCH 4/6] k3s: add missing phases hook --- pkgs/applications/networking/cluster/k3s/builder.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkgs/applications/networking/cluster/k3s/builder.nix b/pkgs/applications/networking/cluster/k3s/builder.nix index 5c2820300b3f..28e55da9b64d 100644 --- a/pkgs/applications/networking/cluster/k3s/builder.nix +++ b/pkgs/applications/networking/cluster/k3s/builder.nix @@ -367,6 +367,7 @@ buildGoModule rec { # https://github.com/NixOS/nixpkgs/pull/158089#discussion_r799965694 # So, why do we use buildGoModule at all? For the `vendorHash` / `go mod download` stuff primarily. buildPhase = '' + runHook preBuild patchShebangs ./scripts/package-cli ./scripts/download ./scripts/build-upload # copy needed 'go generate' inputs into place @@ -387,12 +388,14 @@ buildGoModule rec { ./scripts/package-cli mkdir -p $out/bin + runHook postBuild ''; # Otherwise it depends on 'getGoDirs', which is normally set in buildPhase doCheck = false; installPhase = '' + runHook preInstall # wildcard to match the arm64 build too install -m 0755 dist/artifacts/k3s* -D $out/bin/k3s wrapProgram $out/bin/k3s \ @@ -404,11 +407,14 @@ buildGoModule rec { install -m 0755 ${k3sKillallSh} -D $out/bin/k3s-killall.sh wrapProgram $out/bin/k3s-killall.sh \ --prefix PATH : ${lib.makeBinPath (k3sRuntimeDeps ++ k3sKillallDeps)} + runHook postInstall ''; doInstallCheck = true; installCheckPhase = '' + runHook preInstallCheck $out/bin/k3s --version | grep -F "v${k3sVersion}" >/dev/null + runHook postInstallCheck ''; passthru.updateScript = updateScript; From e4d5a9864a2102dbbc17adc765fd759db24a6edd Mon Sep 17 00:00:00 2001 From: superherointj <5861043+superherointj@users.noreply.github.com> Date: Fri, 12 Jul 2024 11:47:21 -0300 Subject: [PATCH 5/6] k3s: refactor passthru and expose k3s dependencies for update script --- .../networking/cluster/k3s/builder.nix | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/pkgs/applications/networking/cluster/k3s/builder.nix b/pkgs/applications/networking/cluster/k3s/builder.nix index 28e55da9b64d..eeff2578efb7 100644 --- a/pkgs/applications/networking/cluster/k3s/builder.nix +++ b/pkgs/applications/networking/cluster/k3s/builder.nix @@ -417,16 +417,21 @@ buildGoModule rec { runHook postInstallCheck ''; - passthru.updateScript = updateScript; - - passthru.mkTests = - version: - let - k3s_version = "k3s_" + lib.replaceStrings [ "." ] [ "_" ] (lib.versions.majorMinor version); - in - lib.mapAttrs (name: value: nixosTests.k3s.${name}.${k3s_version}) nixosTests.k3s; - - passthru.tests = passthru.mkTests k3sVersion; + passthru = { + k3sCNIPlugins = k3sCNIPlugins; + k3sContainerd = k3sContainerd; + k3sRepo = k3sRepo; + k3sRoot = k3sRoot; + k3sServer = k3sServer; + mkTests = + version: + let + k3s_version = "k3s_" + lib.replaceStrings [ "." ] [ "_" ] (lib.versions.majorMinor version); + in + lib.mapAttrs (name: value: nixosTests.k3s.${name}.${k3s_version}) nixosTests.k3s; + tests = passthru.mkTests k3sVersion; + updateScript = updateScript; + }; meta = baseMeta; } From e3e012325b3e36b4e6d1df99875cdd16976c208e Mon Sep 17 00:00:00 2001 From: superherointj <5861043+superherointj@users.noreply.github.com> Date: Fri, 12 Jul 2024 17:57:50 -0300 Subject: [PATCH 6/6] k3s/tests/auto-deploy: fix race condition Co-authored-by: wrmilling marcusramberg --- nixos/tests/k3s/auto-deploy.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nixos/tests/k3s/auto-deploy.nix b/nixos/tests/k3s/auto-deploy.nix index d60aede950e7..11eed4aef95f 100644 --- a/nixos/tests/k3s/auto-deploy.nix +++ b/nixos/tests/k3s/auto-deploy.nix @@ -109,8 +109,8 @@ import ../make-test-python.nix ( machine.succeed("ls /var/lib/rancher/k3s/server/manifests/hello.yaml") # check if container images got imported - machine.succeed("crictl img | grep 'test\.local/pause'") - machine.succeed("crictl img | grep 'test\.local/hello'") + machine.wait_until_succeeds("crictl img | grep 'test\.local/pause'") + machine.wait_until_succeeds("crictl img | grep 'test\.local/hello'") # check if resources of manifests got created machine.wait_until_succeeds("kubectl get ns foo")