Skip to content

Commit

Permalink
nixos/services.kubernetes.addonManager: remove with lib;
Browse files Browse the repository at this point in the history
  • Loading branch information
Stunkymonkey committed Dec 8, 2024
1 parent c1109e8 commit 42a84ad
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions nixos/modules/services/cluster/kubernetes/addon-manager.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
{ config, lib, pkgs, ... }:

with lib;

let
top = config.services.kubernetes;
cfg = top.addonManager;

isRBACEnabled = elem "RBAC" top.apiserver.authorizationMode;
isRBACEnabled = lib.elem "RBAC" top.apiserver.authorizationMode;

addons = pkgs.runCommand "kubernetes-addons" { } ''
mkdir -p $out
# since we are mounting the addons to the addon manager, they need to be copied
${concatMapStringsSep ";" (a: "cp -v ${a}/* $out/") (mapAttrsToList (name: addon:
${lib.concatMapStringsSep ";" (a: "cp -v ${a}/* $out/") (lib.mapAttrsToList (name: addon:
pkgs.writeTextDir "${name}.json" (builtins.toJSON addon)
) (cfg.addons))}
'';
Expand All @@ -20,14 +17,14 @@ in
###### interface
options.services.kubernetes.addonManager = with lib.types; {

bootstrapAddons = mkOption {
bootstrapAddons = lib.mkOption {
description = ''
Bootstrap addons are like regular addons, but they are applied with cluster-admin rights.
They are applied at addon-manager startup only.
'';
default = { };
type = attrsOf attrs;
example = literalExpression ''
example = lib.literalExpression ''
{
"my-service" = {
"apiVersion" = "v1";
Expand All @@ -42,11 +39,11 @@ in
'';
};

addons = mkOption {
addons = lib.mkOption {
description = "Kubernetes addons (any kind of Kubernetes resource can be an addon).";
default = { };
type = attrsOf (either attrs (listOf attrs));
example = literalExpression ''
example = lib.literalExpression ''
{
"my-service" = {
"apiVersion" = "v1";
Expand All @@ -62,11 +59,11 @@ in
'';
};

enable = mkEnableOption "Kubernetes addon manager";
enable = lib.mkEnableOption "Kubernetes addon manager";
};

###### implementation
config = mkIf cfg.enable {
config = lib.mkIf cfg.enable {
environment.etc."kubernetes/addons".source = "${addons}/";

systemd.services.kube-addon-manager = {
Expand All @@ -89,7 +86,7 @@ in
};
};

services.kubernetes.addonManager.bootstrapAddons = mkIf isRBACEnabled
services.kubernetes.addonManager.bootstrapAddons = lib.mkIf isRBACEnabled
(let
name = "system:kube-addon-manager";
namespace = "kube-system";
Expand Down

0 comments on commit 42a84ad

Please sign in to comment.