the conversion procedure is simple: - find all things that look like options, ie calls to either `mkOption` or `lib.mkOption` that take an attrset. remember the attrset as the option - for all options, find a `description` attribute who's value is not a call to `mdDoc` or `lib.mdDoc` - textually convert the entire value of the attribute to MD with a few simple regexes (the set from mdize-module.sh) - if the change produced a change in the manual output, discard - if the change kept the manual unchanged, add some text to the description to make sure we've actually found an option. if the manual changes this time, keep the converted description this procedure converts 80% of nixos options to markdown. around 2000 options remain to be inspected, but most of those fail the "does not change the manual output check": currently the MD conversion process does not faithfully convert docbook tags like <code> and <package>, so any option using such tags will not be converted at all.
172 lines
4.5 KiB
Nix
172 lines
4.5 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
top = config.services.kubernetes;
|
|
cfg = top.addonManager;
|
|
|
|
isRBACEnabled = 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:
|
|
pkgs.writeTextDir "${name}.json" (builtins.toJSON addon)
|
|
) (cfg.addons))}
|
|
'';
|
|
in
|
|
{
|
|
###### interface
|
|
options.services.kubernetes.addonManager = with lib.types; {
|
|
|
|
bootstrapAddons = mkOption {
|
|
description = lib.mdDoc ''
|
|
Bootstrap addons are like regular addons, but they are applied with cluster-admin rigths.
|
|
They are applied at addon-manager startup only.
|
|
'';
|
|
default = { };
|
|
type = attrsOf attrs;
|
|
example = literalExpression ''
|
|
{
|
|
"my-service" = {
|
|
"apiVersion" = "v1";
|
|
"kind" = "Service";
|
|
"metadata" = {
|
|
"name" = "my-service";
|
|
"namespace" = "default";
|
|
};
|
|
"spec" = { ... };
|
|
};
|
|
}
|
|
'';
|
|
};
|
|
|
|
addons = mkOption {
|
|
description = lib.mdDoc "Kubernetes addons (any kind of Kubernetes resource can be an addon).";
|
|
default = { };
|
|
type = attrsOf (either attrs (listOf attrs));
|
|
example = literalExpression ''
|
|
{
|
|
"my-service" = {
|
|
"apiVersion" = "v1";
|
|
"kind" = "Service";
|
|
"metadata" = {
|
|
"name" = "my-service";
|
|
"namespace" = "default";
|
|
};
|
|
"spec" = { ... };
|
|
};
|
|
}
|
|
// import <nixpkgs/nixos/modules/services/cluster/kubernetes/dns.nix> { cfg = config.services.kubernetes; };
|
|
'';
|
|
};
|
|
|
|
enable = mkEnableOption "Kubernetes addon manager.";
|
|
};
|
|
|
|
###### implementation
|
|
config = mkIf cfg.enable {
|
|
environment.etc."kubernetes/addons".source = "${addons}/";
|
|
|
|
systemd.services.kube-addon-manager = {
|
|
description = "Kubernetes addon manager";
|
|
wantedBy = [ "kubernetes.target" ];
|
|
after = [ "kube-apiserver.service" ];
|
|
environment.ADDON_PATH = "/etc/kubernetes/addons/";
|
|
path = [ pkgs.gawk ];
|
|
serviceConfig = {
|
|
Slice = "kubernetes.slice";
|
|
ExecStart = "${top.package}/bin/kube-addons";
|
|
WorkingDirectory = top.dataDir;
|
|
User = "kubernetes";
|
|
Group = "kubernetes";
|
|
Restart = "on-failure";
|
|
RestartSec = 10;
|
|
};
|
|
unitConfig = {
|
|
StartLimitIntervalSec = 0;
|
|
};
|
|
};
|
|
|
|
services.kubernetes.addonManager.bootstrapAddons = mkIf isRBACEnabled
|
|
(let
|
|
name = "system:kube-addon-manager";
|
|
namespace = "kube-system";
|
|
in
|
|
{
|
|
|
|
kube-addon-manager-r = {
|
|
apiVersion = "rbac.authorization.k8s.io/v1";
|
|
kind = "Role";
|
|
metadata = {
|
|
inherit name namespace;
|
|
};
|
|
rules = [{
|
|
apiGroups = ["*"];
|
|
resources = ["*"];
|
|
verbs = ["*"];
|
|
}];
|
|
};
|
|
|
|
kube-addon-manager-rb = {
|
|
apiVersion = "rbac.authorization.k8s.io/v1";
|
|
kind = "RoleBinding";
|
|
metadata = {
|
|
inherit name namespace;
|
|
};
|
|
roleRef = {
|
|
apiGroup = "rbac.authorization.k8s.io";
|
|
kind = "Role";
|
|
inherit name;
|
|
};
|
|
subjects = [{
|
|
apiGroup = "rbac.authorization.k8s.io";
|
|
kind = "User";
|
|
inherit name;
|
|
}];
|
|
};
|
|
|
|
kube-addon-manager-cluster-lister-cr = {
|
|
apiVersion = "rbac.authorization.k8s.io/v1";
|
|
kind = "ClusterRole";
|
|
metadata = {
|
|
name = "${name}:cluster-lister";
|
|
};
|
|
rules = [{
|
|
apiGroups = ["*"];
|
|
resources = ["*"];
|
|
verbs = ["list"];
|
|
}];
|
|
};
|
|
|
|
kube-addon-manager-cluster-lister-crb = {
|
|
apiVersion = "rbac.authorization.k8s.io/v1";
|
|
kind = "ClusterRoleBinding";
|
|
metadata = {
|
|
name = "${name}:cluster-lister";
|
|
};
|
|
roleRef = {
|
|
apiGroup = "rbac.authorization.k8s.io";
|
|
kind = "ClusterRole";
|
|
name = "${name}:cluster-lister";
|
|
};
|
|
subjects = [{
|
|
kind = "User";
|
|
inherit name;
|
|
}];
|
|
};
|
|
});
|
|
|
|
services.kubernetes.pki.certs = {
|
|
addonManager = top.lib.mkCert {
|
|
name = "kube-addon-manager";
|
|
CN = "system:kube-addon-manager";
|
|
action = "systemctl restart kube-addon-manager.service";
|
|
};
|
|
};
|
|
};
|
|
|
|
meta.buildDocsInSandbox = false;
|
|
}
|