1 { config, lib, options, pkgs, ... }:
6 top = config.services.kubernetes;
7 otop = options.services.kubernetes;
8 cfg = top.controllerManager;
12 (mkRenamedOptionModule [ "services" "kubernetes" "controllerManager" "address" ] ["services" "kubernetes" "controllerManager" "bindAddress"])
13 (mkRemovedOptionModule [ "services" "kubernetes" "controllerManager" "insecurePort" ] "")
17 options.services.kubernetes.controllerManager = with lib.types; {
19 allocateNodeCIDRs = mkOption {
20 description = "Whether to automatically allocate CIDR ranges for cluster nodes.";
25 bindAddress = mkOption {
26 description = "Kubernetes controller manager listening address.";
27 default = "127.0.0.1";
31 clusterCidr = mkOption {
32 description = "Kubernetes CIDR Range for Pods in cluster.";
33 default = top.clusterCidr;
34 defaultText = literalExpression "config.${otop.clusterCidr}";
38 enable = mkEnableOption "Kubernetes controller manager";
40 extraOpts = mkOption {
41 description = "Kubernetes controller manager extra command line options.";
43 type = separatedString " ";
46 featureGates = mkOption {
47 description = "Attribute set of feature gates.";
48 default = top.featureGates;
49 defaultText = literalExpression "config.${otop.featureGates}";
53 kubeconfig = top.lib.mkKubeConfigOptions "Kubernetes controller manager";
55 leaderElect = mkOption {
56 description = "Whether to start leader election before executing main loop.";
61 rootCaFile = mkOption {
63 Kubernetes controller manager certificate authority file included in
64 service account's token secret.
67 defaultText = literalExpression "config.${otop.caFile}";
71 securePort = mkOption {
72 description = "Kubernetes controller manager secure listening port.";
77 serviceAccountKeyFile = mkOption {
79 Kubernetes controller manager PEM-encoded private RSA key file used to
80 sign service account tokens
86 tlsCertFile = mkOption {
87 description = "Kubernetes controller-manager certificate file.";
92 tlsKeyFile = mkOption {
93 description = "Kubernetes controller-manager private key file.";
98 verbosity = mkOption {
100 Optional glog verbosity level for logging statements. See
101 <https://github.com/kubernetes/community/blob/master/contributors/devel/logging.md>
109 ###### implementation
110 config = mkIf cfg.enable {
111 systemd.services.kube-controller-manager = {
112 description = "Kubernetes Controller Manager Service";
113 wantedBy = [ "kubernetes.target" ];
114 after = [ "kube-apiserver.service" ];
117 Restart = "on-failure";
118 Slice = "kubernetes.slice";
119 ExecStart = ''${top.package}/bin/kube-controller-manager \
120 --allocate-node-cidrs=${boolToString cfg.allocateNodeCIDRs} \
121 --bind-address=${cfg.bindAddress} \
122 ${optionalString (cfg.clusterCidr!=null)
123 "--cluster-cidr=${cfg.clusterCidr}"} \
124 ${optionalString (cfg.featureGates != {})
125 "--feature-gates=${concatStringsSep "," (builtins.attrValues (mapAttrs (n: v: "${n}=${trivial.boolToString v}") cfg.featureGates))}"} \
126 --kubeconfig=${top.lib.mkKubeConfig "kube-controller-manager" cfg.kubeconfig} \
127 --leader-elect=${boolToString cfg.leaderElect} \
128 ${optionalString (cfg.rootCaFile!=null)
129 "--root-ca-file=${cfg.rootCaFile}"} \
130 --secure-port=${toString cfg.securePort} \
131 ${optionalString (cfg.serviceAccountKeyFile!=null)
132 "--service-account-private-key-file=${cfg.serviceAccountKeyFile}"} \
133 ${optionalString (cfg.tlsCertFile!=null)
134 "--tls-cert-file=${cfg.tlsCertFile}"} \
135 ${optionalString (cfg.tlsKeyFile!=null)
136 "--tls-private-key-file=${cfg.tlsKeyFile}"} \
137 ${optionalString (elem "RBAC" top.apiserver.authorizationMode)
138 "--use-service-account-credentials"} \
139 ${optionalString (cfg.verbosity != null) "--v=${toString cfg.verbosity}"} \
142 WorkingDirectory = top.dataDir;
144 Group = "kubernetes";
147 StartLimitIntervalSec = 0;
152 services.kubernetes.pki.certs = with top.lib; {
153 controllerManager = mkCert {
154 name = "kube-controller-manager";
155 CN = "kube-controller-manager";
156 action = "systemctl restart kube-controller-manager.service";
158 controllerManagerClient = mkCert {
159 name = "kube-controller-manager-client";
160 CN = "system:kube-controller-manager";
161 action = "systemctl restart kube-controller-manager.service";
165 services.kubernetes.controllerManager.kubeconfig.server = mkDefault top.apiserverAddress;
168 meta.buildDocsInSandbox = false;