Skip to content

Commit dae5133

Browse files
authored
Merge pull request #18 from plaflamme/more-tests
fix: do not require a join token for the controller+worker role
2 parents 9551750 + ae1ef46 commit dae5133

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

flake.nix

+7-6
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@
2525
nixosModules.default = import ./nixos/k0s.nix;
2626

2727
checks = forAllSystems (system:
28-
let pkgs = nixpkgs.legacyPackages.${system};
29-
in {
30-
basic = pkgs.testers.runNixOSTest {
31-
imports = [ ./tests/basic.nix ];
28+
let
29+
pkgs = nixpkgs.legacyPackages.${system};
30+
forAllTests = lib.genAttrs [ "single" "ctrl-wrkr" ];
31+
in forAllTests (test:
32+
pkgs.testers.runNixOSTest {
33+
imports = [ ./tests/${test}.nix ];
3234
node = { pkgsReadOnly = false; };
3335
defaults = {
3436
imports = [ self.nixosModules.default ];
3537
nixpkgs.overlays = [ self.overlays.default ];
3638
};
37-
};
38-
});
39+
}));
3940

4041
};
4142
}

nixos/k0s.nix

+3-2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ in {
7676
if (cfg.role == "worker")
7777
then "worker"
7878
else "controller";
79+
requireJoinToken = cfg.role == "worker" || (cfg.role == "controller" && !cfg.isLeader);
7980
unitName = "k0s" + subcommand;
8081
configFile =
8182
if cfg.configText != ""
@@ -118,9 +119,9 @@ in {
118119
+ optionalString (cfg.role != "worker") " --config=${configFile}"
119120
+ optionalString (cfg.role == "single") " --single"
120121
+ optionalString (cfg.role == "controller+worker") " --enable-worker --no-taints"
121-
+ optionalString (cfg.role != "single" && !cfg.isLeader) " --token-file=${cfg.tokenFile}";
122+
+ optionalString requireJoinToken " --token-file=${cfg.tokenFile}";
122123
};
123-
unitConfig = mkIf (cfg.role != "single" && !cfg.isLeader) {
124+
unitConfig = mkIf requireJoinToken {
124125
ConditionPathExists = cfg.tokenFile;
125126
};
126127
};

tests/ctrl-wrkr.nix

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
name = "ctrl-wrkr";
3+
nodes = {
4+
node1 = { config, ... }: {
5+
services.k0s = {
6+
enable = true;
7+
role = "controller+worker";
8+
spec.api = {
9+
address = config.networking.primaryIPAddress;
10+
sans = [ config.networking.primaryIPAddress ];
11+
};
12+
};
13+
14+
};
15+
};
16+
testScript = { nodes }:
17+
let k0s = nodes.node1.services.k0s.package;
18+
in ''
19+
start_all()
20+
node1.wait_for_unit("k0scontroller")
21+
node1.wait_for_file("/run/k0s/status.sock")
22+
node1.succeed("${k0s}/bin/k0s status")
23+
'';
24+
}

tests/basic.nix tests/single.nix

File renamed without changes.

0 commit comments

Comments
 (0)