From 759d2b8646116825bccefd16010e8a5ec44c9aa4 Mon Sep 17 00:00:00 2001 From: Robert Rose Date: Mon, 9 Dec 2024 16:39:22 +0100 Subject: [PATCH] nixos/k3s: make assertions about missing configuration options warnings It is possible to configure k3s in various ways (cli flags, env variables, single config file, multiple config files) and everything is merged together in a final config. The nixos module cannot know if a configuration option that is missing from the module point of view is supplied in another way, so it shouldn't assert missing configuration options. --- .../modules/services/cluster/k3s/default.nix | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/nixos/modules/services/cluster/k3s/default.nix b/nixos/modules/services/cluster/k3s/default.nix index 100eabfdd8c3..97019ba5cb4d 100644 --- a/nixos/modules/services/cluster/k3s/default.nix +++ b/nixos/modules/services/cluster/k3s/default.nix @@ -462,27 +462,25 @@ in ++ (lib.optional (cfg.role != "server" && cfg.charts != { }) "k3s: Helm charts are only made available to the cluster on server nodes (role == server), they will be ignored by this node." ) - ++ (lib.optional (cfg.disableAgent && cfg.images != [ ]) - "k3s: Images are only imported on nodes with an enabled agent, they will be ignored by this node" + ++ (lib.optional ( + cfg.disableAgent && cfg.images != [ ] + ) "k3s: Images are only imported on nodes with an enabled agent, they will be ignored by this node") + ++ (lib.optional ( + cfg.role == "agent" && cfg.configPath == null && cfg.serverAddr == "" + ) "k3s: ServerAddr or configPath (with 'server' key) should be set if role is 'agent'") + ++ (lib.optional + (cfg.role == "agent" && cfg.configPath == null && cfg.tokenFile == null && cfg.token == "") + "k3s: Token or tokenFile or configPath (with 'token' or 'token-file' keys) should be set if role is 'agent'" ); assertions = [ - { - assertion = cfg.role == "agent" -> (cfg.configPath != null || cfg.serverAddr != ""); - message = "serverAddr or configPath (with 'server' key) should be set if role is 'agent'"; - } - { - assertion = - cfg.role == "agent" -> cfg.configPath != null || cfg.tokenFile != null || cfg.token != ""; - message = "token or tokenFile or configPath (with 'token' or 'token-file' keys) should be set if role is 'agent'"; - } { assertion = cfg.role == "agent" -> !cfg.disableAgent; - message = "disableAgent must be false if role is 'agent'"; + message = "k3s: disableAgent must be false if role is 'agent'"; } { assertion = cfg.role == "agent" -> !cfg.clusterInit; - message = "clusterInit must be false if role is 'agent'"; + message = "k3s: clusterInit must be false if role is 'agent'"; } ];