2021-12-05 20:48:56 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
options,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
2018-07-22 13:14:20 +02:00
|
|
|
let
|
|
|
|
top = config.services.kubernetes;
|
2021-12-05 20:48:56 +01:00
|
|
|
otop = options.services.kubernetes;
|
2018-07-22 13:14:20 +02:00
|
|
|
cfg = top.controllerManager;
|
|
|
|
in
|
|
|
|
{
|
2019-12-10 02:51:19 +01:00
|
|
|
imports = [
|
2024-12-08 13:18:23 +01:00
|
|
|
(lib.mkRenamedOptionModule
|
|
|
|
[ "services" "kubernetes" "controllerManager" "address" ]
|
|
|
|
[ "services" "kubernetes" "controllerManager" "bindAddress" ]
|
|
|
|
)
|
|
|
|
(lib.mkRemovedOptionModule [ "services" "kubernetes" "controllerManager" "insecurePort" ] "")
|
2019-12-10 02:51:19 +01:00
|
|
|
];
|
|
|
|
|
2018-07-22 13:14:20 +02:00
|
|
|
###### interface
|
|
|
|
options.services.kubernetes.controllerManager = with lib.types; {
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
allocateNodeCIDRs = lib.mkOption {
|
2018-07-22 13:14:20 +02:00
|
|
|
description = "Whether to automatically allocate CIDR ranges for cluster nodes.";
|
|
|
|
default = true;
|
|
|
|
type = bool;
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
bindAddress = lib.mkOption {
|
2018-07-22 13:14:20 +02:00
|
|
|
description = "Kubernetes controller manager listening address.";
|
|
|
|
default = "127.0.0.1";
|
|
|
|
type = str;
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
clusterCidr = lib.mkOption {
|
2018-07-22 13:14:20 +02:00
|
|
|
description = "Kubernetes CIDR Range for Pods in cluster.";
|
|
|
|
default = top.clusterCidr;
|
2024-12-08 13:18:23 +01:00
|
|
|
defaultText = lib.literalExpression "config.${otop.clusterCidr}";
|
2018-07-22 13:14:20 +02:00
|
|
|
type = str;
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
enable = lib.mkEnableOption "Kubernetes controller manager";
|
2018-07-22 13:14:20 +02:00
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
extraOpts = lib.mkOption {
|
2018-07-22 13:14:20 +02:00
|
|
|
description = "Kubernetes controller manager extra command line options.";
|
|
|
|
default = "";
|
2021-04-13 21:54:53 +09:00
|
|
|
type = separatedString " ";
|
2018-07-22 13:14:20 +02:00
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
featureGates = lib.mkOption {
|
2024-07-17 09:10:17 +02:00
|
|
|
description = "Attribute set of feature gates.";
|
2018-07-22 13:14:20 +02:00
|
|
|
default = top.featureGates;
|
2024-12-08 13:18:23 +01:00
|
|
|
defaultText = lib.literalExpression "config.${otop.featureGates}";
|
2024-07-17 09:10:17 +02:00
|
|
|
type = attrsOf bool;
|
2018-07-22 13:14:20 +02:00
|
|
|
};
|
|
|
|
|
2022-01-08 06:59:18 +01:00
|
|
|
kubeconfig = top.lib.mkKubeConfigOptions "Kubernetes controller manager";
|
2018-07-22 13:14:20 +02:00
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
leaderElect = lib.mkOption {
|
2018-07-22 13:14:20 +02:00
|
|
|
description = "Whether to start leader election before executing main loop.";
|
|
|
|
type = bool;
|
|
|
|
default = true;
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
rootCaFile = lib.mkOption {
|
2018-07-22 13:14:20 +02:00
|
|
|
description = ''
|
|
|
|
Kubernetes controller manager certificate authority file included in
|
|
|
|
service account's token secret.
|
|
|
|
'';
|
|
|
|
default = top.caFile;
|
2024-12-08 13:18:23 +01:00
|
|
|
defaultText = lib.literalExpression "config.${otop.caFile}";
|
2018-07-22 13:14:20 +02:00
|
|
|
type = nullOr path;
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
securePort = lib.mkOption {
|
2018-07-22 13:14:20 +02:00
|
|
|
description = "Kubernetes controller manager secure listening port.";
|
|
|
|
default = 10252;
|
|
|
|
type = int;
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
serviceAccountKeyFile = lib.mkOption {
|
2018-07-22 13:14:20 +02:00
|
|
|
description = ''
|
|
|
|
Kubernetes controller manager PEM-encoded private RSA key file used to
|
|
|
|
sign service account tokens
|
|
|
|
'';
|
|
|
|
default = null;
|
|
|
|
type = nullOr path;
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
tlsCertFile = lib.mkOption {
|
2018-07-22 13:14:20 +02:00
|
|
|
description = "Kubernetes controller-manager certificate file.";
|
|
|
|
default = null;
|
|
|
|
type = nullOr path;
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
tlsKeyFile = lib.mkOption {
|
2018-07-22 13:14:20 +02:00
|
|
|
description = "Kubernetes controller-manager private key file.";
|
|
|
|
default = null;
|
|
|
|
type = nullOr path;
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
verbosity = lib.mkOption {
|
2018-07-22 13:14:20 +02:00
|
|
|
description = ''
|
|
|
|
Optional glog verbosity level for logging statements. See
|
|
|
|
<https://github.com/kubernetes/community/blob/master/contributors/devel/logging.md>
|
|
|
|
'';
|
|
|
|
default = null;
|
|
|
|
type = nullOr int;
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
2024-12-08 13:18:23 +01:00
|
|
|
config = lib.mkIf cfg.enable {
|
2019-08-24 12:52:32 +02:00
|
|
|
systemd.services.kube-controller-manager = {
|
2018-07-22 13:14:20 +02:00
|
|
|
description = "Kubernetes Controller Manager Service";
|
2019-08-24 12:52:32 +02:00
|
|
|
wantedBy = [ "kubernetes.target" ];
|
2018-07-22 13:14:20 +02:00
|
|
|
after = [ "kube-apiserver.service" ];
|
|
|
|
serviceConfig = {
|
|
|
|
RestartSec = "30s";
|
|
|
|
Restart = "on-failure";
|
|
|
|
Slice = "kubernetes.slice";
|
|
|
|
ExecStart = ''
|
|
|
|
${top.package}/bin/kube-controller-manager \
|
2024-12-08 13:18:23 +01:00
|
|
|
--allocate-node-cidrs=${lib.boolToString cfg.allocateNodeCIDRs} \
|
2018-07-22 13:14:20 +02:00
|
|
|
--bind-address=${cfg.bindAddress} \
|
2024-12-08 13:18:23 +01:00
|
|
|
${lib.optionalString (cfg.clusterCidr != null) "--cluster-cidr=${cfg.clusterCidr}"} \
|
|
|
|
${
|
|
|
|
lib.optionalString (cfg.featureGates != { })
|
|
|
|
"--feature-gates=${
|
|
|
|
lib.concatStringsSep "," (
|
|
|
|
builtins.attrValues (lib.mapAttrs (n: v: "${n}=${lib.trivial.boolToString v}") cfg.featureGates)
|
2024-12-10 20:26:33 +01:00
|
|
|
)
|
2024-12-08 13:18:23 +01:00
|
|
|
}"
|
|
|
|
} \
|
2022-01-08 06:59:18 +01:00
|
|
|
--kubeconfig=${top.lib.mkKubeConfig "kube-controller-manager" cfg.kubeconfig} \
|
2024-12-08 13:18:23 +01:00
|
|
|
--leader-elect=${lib.boolToString cfg.leaderElect} \
|
|
|
|
${lib.optionalString (cfg.rootCaFile != null) "--root-ca-file=${cfg.rootCaFile}"} \
|
2018-07-22 13:14:20 +02:00
|
|
|
--secure-port=${toString cfg.securePort} \
|
2024-12-08 13:18:23 +01:00
|
|
|
${
|
|
|
|
lib.optionalString (
|
|
|
|
cfg.serviceAccountKeyFile != null
|
2018-07-22 13:14:20 +02:00
|
|
|
) "--service-account-private-key-file=${cfg.serviceAccountKeyFile}"
|
|
|
|
} \
|
2024-12-08 13:18:23 +01:00
|
|
|
${lib.optionalString (cfg.tlsCertFile != null) "--tls-cert-file=${cfg.tlsCertFile}"} \
|
|
|
|
${
|
2019-02-28 15:12:58 +01:00
|
|
|
lib.optionalString (cfg.tlsKeyFile != null) "--tls-private-key-file=${cfg.tlsKeyFile}"
|
|
|
|
} \
|
2024-12-08 13:18:23 +01:00
|
|
|
${lib.optionalString (lib.elem "RBAC" top.apiserver.authorizationMode) "--use-service-account-credentials"} \
|
|
|
|
${lib.optionalString (cfg.verbosity != null) "--v=${toString cfg.verbosity}"} \
|
2018-07-22 13:14:20 +02:00
|
|
|
${cfg.extraOpts}
|
|
|
|
'';
|
|
|
|
WorkingDirectory = top.dataDir;
|
|
|
|
User = "kubernetes";
|
|
|
|
Group = "kubernetes";
|
|
|
|
};
|
2021-07-30 16:16:23 +01:00
|
|
|
unitConfig = {
|
|
|
|
StartLimitIntervalSec = 0;
|
|
|
|
};
|
2019-08-24 12:52:32 +02:00
|
|
|
path = top.path;
|
2018-07-22 13:14:20 +02:00
|
|
|
};
|
|
|
|
|
2022-01-08 06:59:18 +01:00
|
|
|
services.kubernetes.pki.certs = with top.lib; {
|
2018-07-22 13:14:20 +02:00
|
|
|
controllerManager = mkCert {
|
|
|
|
name = "kube-controller-manager";
|
|
|
|
CN = "kube-controller-manager";
|
|
|
|
action = "systemctl restart kube-controller-manager.service";
|
|
|
|
};
|
|
|
|
controllerManagerClient = mkCert {
|
|
|
|
name = "kube-controller-manager-client";
|
|
|
|
CN = "system:kube-controller-manager";
|
|
|
|
action = "systemctl restart kube-controller-manager.service";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:23 +01:00
|
|
|
services.kubernetes.controllerManager.kubeconfig.server = lib.mkDefault top.apiserverAddress;
|
2018-07-22 13:14:20 +02:00
|
|
|
};
|
2022-01-08 07:10:25 +01:00
|
|
|
|
|
|
|
meta.buildDocsInSandbox = false;
|
2018-07-22 13:14:20 +02:00
|
|
|
}
|