From 52a153aae20d999854d7ece49b865e95b929e490 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Thu, 9 Feb 2023 09:57:37 +0000 Subject: [PATCH 1/3] k3s: test all versions Since https://github.com/NixOS/nixpkgs/issues/213943 got fixed, only the main k3s derivation is tested. Here I changed the tests a bit to make them test all provided k3s derivations @moduon MT-1718 --- nixos/tests/k3s/default.nix | 16 ++++++++++++++-- nixos/tests/k3s/multi-node.nix | 6 +++--- nixos/tests/k3s/single-node.nix | 6 +++--- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/nixos/tests/k3s/default.nix b/nixos/tests/k3s/default.nix index 07d93c41c7a..453a96439d8 100644 --- a/nixos/tests/k3s/default.nix +++ b/nixos/tests/k3s/default.nix @@ -1,9 +1,21 @@ { system ? builtins.currentSystem , pkgs ? import ../../.. { inherit system; } +, lib ? pkgs.lib }: +let + allK3s = { + inherit (pkgs) + k3s + k3s_1_23 + k3s_1_24 + k3s_1_25 + k3s_1_26 + ; + }; +in { # Run a single node k3s cluster and verify a pod can run - single-node = import ./single-node.nix { inherit system pkgs; }; + 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 = import ./multi-node.nix { inherit system pkgs; }; + multi-node = lib.mapAttrs (_: k3s: import ./multi-node.nix { inherit system pkgs k3s; }) allK3s; } diff --git a/nixos/tests/k3s/multi-node.nix b/nixos/tests/k3s/multi-node.nix index 9a6c7fd4657..932b4639b39 100644 --- a/nixos/tests/k3s/multi-node.nix +++ b/nixos/tests/k3s/multi-node.nix @@ -1,4 +1,4 @@ -import ../make-test-python.nix ({ pkgs, lib, ... }: +import ../make-test-python.nix ({ pkgs, lib, k3s, ... }: let imageEnv = pkgs.buildEnv { name = "k3s-pause-image-env"; @@ -39,7 +39,7 @@ import ../make-test-python.nix ({ pkgs, lib, ... }: tokenFile = pkgs.writeText "token" "p@s$w0rd"; in { - name = "k3s-multi-node"; + name = "${k3s.name}-multi-node"; nodes = { server = { pkgs, ... }: { @@ -52,7 +52,7 @@ import ../make-test-python.nix ({ pkgs, lib, ... }: inherit tokenFile; enable = true; role = "server"; - package = pkgs.k3s; + package = k3s; clusterInit = true; extraFlags = builtins.toString [ "--disable" "coredns" diff --git a/nixos/tests/k3s/single-node.nix b/nixos/tests/k3s/single-node.nix index a95fa4a031e..c120f461ddc 100644 --- a/nixos/tests/k3s/single-node.nix +++ b/nixos/tests/k3s/single-node.nix @@ -1,4 +1,4 @@ -import ../make-test-python.nix ({ pkgs, lib, ... }: +import ../make-test-python.nix ({ pkgs, lib, k3s, ... }: let imageEnv = pkgs.buildEnv { name = "k3s-pause-image-env"; @@ -24,7 +24,7 @@ import ../make-test-python.nix ({ pkgs, lib, ... }: ''; in { - name = "k3s"; + name = "${k3s.name}-single-node"; meta = with pkgs.lib.maintainers; { maintainers = [ euank ]; }; @@ -38,7 +38,7 @@ import ../make-test-python.nix ({ pkgs, lib, ... }: services.k3s.enable = true; services.k3s.role = "server"; - services.k3s.package = pkgs.k3s; + services.k3s.package = k3s; # Slightly reduce resource usage services.k3s.extraFlags = builtins.toString [ "--disable" "coredns" From f0a6595fe5bebfa033c0fc1fc91d85d5f5f5c2cd Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Mon, 13 Feb 2023 08:33:20 +0000 Subject: [PATCH 2/3] k3s: add passthru.tests to all derivations --- .../applications/networking/cluster/k3s/1_23/default.nix | 3 +-- .../applications/networking/cluster/k3s/1_24/default.nix | 3 +-- .../applications/networking/cluster/k3s/1_25/default.nix | 3 +-- .../applications/networking/cluster/k3s/1_26/default.nix | 9 ++++++++- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pkgs/applications/networking/cluster/k3s/1_23/default.nix b/pkgs/applications/networking/cluster/k3s/1_23/default.nix index 1fbe7687a00..cac90968f0d 100644 --- a/pkgs/applications/networking/cluster/k3s/1_23/default.nix +++ b/pkgs/applications/networking/cluster/k3s/1_23/default.nix @@ -324,8 +324,7 @@ buildGoModule rec { # Fix-Me: Needs to be adapted specifically for 1.23 # passthru.updateScript = ./update.sh; - # Fix-Me: Needs to be adapted specifically for 1.23 - # passthru.tests = { inherit (nixosTests) k3s-single-node k3s-single-node-docker; }; + passthru.tests = k3s.passthru.mkTests k3sVersion; meta = baseMeta; } diff --git a/pkgs/applications/networking/cluster/k3s/1_24/default.nix b/pkgs/applications/networking/cluster/k3s/1_24/default.nix index 18e0258432e..11037db5b6d 100644 --- a/pkgs/applications/networking/cluster/k3s/1_24/default.nix +++ b/pkgs/applications/networking/cluster/k3s/1_24/default.nix @@ -322,8 +322,7 @@ buildGoModule rec { # Fix-Me: Needs to be adapted specifically for 1.24 # passthru.updateScript = ./update.sh; - # Fix-Me: Needs to be adapted specifically for 1.24 - # passthru.tests = nixosTests.k3s; + passthru.tests = k3s.passthru.mkTests k3sVersion; meta = baseMeta; } diff --git a/pkgs/applications/networking/cluster/k3s/1_25/default.nix b/pkgs/applications/networking/cluster/k3s/1_25/default.nix index dc34821fb25..b62eec69285 100644 --- a/pkgs/applications/networking/cluster/k3s/1_25/default.nix +++ b/pkgs/applications/networking/cluster/k3s/1_25/default.nix @@ -322,8 +322,7 @@ buildGoModule rec { # Fix-Me: Needs to be adapted specifically for 1.25 # passthru.updateScript = ./update.sh; - # Fix-Me: Needs to be adapted specifically for 1.25 - # passthru.tests = nixosTests.k3s; + passthru.tests = k3s.passthru.mkTests k3sVersion; meta = baseMeta; } diff --git a/pkgs/applications/networking/cluster/k3s/1_26/default.nix b/pkgs/applications/networking/cluster/k3s/1_26/default.nix index 74f54d28d59..8a25c0099f1 100644 --- a/pkgs/applications/networking/cluster/k3s/1_26/default.nix +++ b/pkgs/applications/networking/cluster/k3s/1_26/default.nix @@ -319,7 +319,14 @@ buildGoModule rec { passthru.updateScript = ./update.sh; - passthru.tests = nixosTests.k3s; + passthru.mkTests = version: + let k3s_version = "k3s_" + lib.replaceStrings ["."] ["_"] (lib.versions.majorMinor version); + in { + single-node = nixosTests.k3s.single-node.${k3s_version}; + multi-node = nixosTests.k3s.multi-node.${k3s_version}; + }; + passthru.tests = passthru.mkTests k3sVersion; + meta = baseMeta; } From 0ca947e125c56e01d2b0471eaebb60902a2c412a Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Tue, 14 Feb 2023 13:23:35 +0000 Subject: [PATCH 3/3] k3s: dynamic detection of all k3s packages --- nixos/tests/k3s/default.nix | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/nixos/tests/k3s/default.nix b/nixos/tests/k3s/default.nix index 453a96439d8..e168f8233c7 100644 --- a/nixos/tests/k3s/default.nix +++ b/nixos/tests/k3s/default.nix @@ -3,15 +3,7 @@ , lib ? pkgs.lib }: let - allK3s = { - inherit (pkgs) - k3s - k3s_1_23 - k3s_1_24 - k3s_1_25 - k3s_1_26 - ; - }; + allK3s = lib.filterAttrs (n: _: lib.strings.hasPrefix "k3s_" n) pkgs; in { # Run a single node k3s cluster and verify a pod can run