2018-07-22 12:14:20 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
top = config.services.kubernetes;
|
|
|
|
cfg = top.scheduler;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
options.services.kubernetes.scheduler = with lib.types; {
|
|
|
|
|
|
|
|
address = mkOption {
|
|
|
|
description = "Kubernetes scheduler listening address.";
|
|
|
|
default = "127.0.0.1";
|
|
|
|
type = str;
|
|
|
|
};
|
|
|
|
|
2019-04-20 02:41:48 +01:00
|
|
|
enable = mkEnableOption "Kubernetes scheduler";
|
2018-07-22 12:14:20 +01:00
|
|
|
|
|
|
|
extraOpts = mkOption {
|
|
|
|
description = "Kubernetes scheduler extra command line options.";
|
|
|
|
default = "";
|
|
|
|
type = str;
|
|
|
|
};
|
|
|
|
|
|
|
|
featureGates = mkOption {
|
|
|
|
description = "List set of feature gates";
|
|
|
|
default = top.featureGates;
|
|
|
|
type = listOf str;
|
|
|
|
};
|
|
|
|
|
|
|
|
kubeconfig = top.lib.mkKubeConfigOptions "Kubernetes scheduler";
|
|
|
|
|
|
|
|
leaderElect = mkOption {
|
|
|
|
description = "Whether to start leader election before executing main loop.";
|
|
|
|
type = bool;
|
|
|
|
default = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
description = "Kubernetes scheduler listening port.";
|
|
|
|
default = 10251;
|
|
|
|
type = int;
|
|
|
|
};
|
|
|
|
|
|
|
|
verbosity = mkOption {
|
|
|
|
description = ''
|
|
|
|
Optional glog verbosity level for logging statements. See
|
|
|
|
<link xlink:href="https://github.com/kubernetes/community/blob/master/contributors/devel/logging.md"/>
|
|
|
|
'';
|
|
|
|
default = null;
|
|
|
|
type = nullOr int;
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
2019-03-11 10:03:40 +00:00
|
|
|
config = let
|
|
|
|
|
|
|
|
schedulerPaths = filter (a: a != null) [
|
|
|
|
cfg.kubeconfig.caFile
|
|
|
|
cfg.kubeconfig.certFile
|
|
|
|
cfg.kubeconfig.keyFile
|
|
|
|
];
|
|
|
|
|
|
|
|
in mkIf cfg.enable {
|
|
|
|
systemd.services.kube-scheduler = rec {
|
2018-07-22 12:14:20 +01:00
|
|
|
description = "Kubernetes Scheduler Service";
|
2019-03-06 15:40:27 +00:00
|
|
|
wantedBy = [ "kube-control-plane-online.target" ];
|
2018-07-22 12:14:20 +01:00
|
|
|
after = [ "kube-apiserver.service" ];
|
2019-03-06 15:40:27 +00:00
|
|
|
before = [ "kube-control-plane-online.target" ];
|
2019-03-11 10:03:40 +00:00
|
|
|
environment.KUBECONFIG = top.lib.mkKubeConfig "kube-scheduler" cfg.kubeconfig;
|
|
|
|
path = [ pkgs.kubectl ];
|
2019-03-01 07:44:45 +00:00
|
|
|
preStart = ''
|
2019-03-11 10:03:40 +00:00
|
|
|
until kubectl auth can-i get /api -q 2>/dev/null; do
|
|
|
|
echo kubectl auth can-i get /api: exit status $?
|
|
|
|
sleep 2
|
|
|
|
done
|
2019-03-01 07:44:45 +00:00
|
|
|
'';
|
2018-07-22 12:14:20 +01:00
|
|
|
serviceConfig = {
|
|
|
|
Slice = "kubernetes.slice";
|
|
|
|
ExecStart = ''${top.package}/bin/kube-scheduler \
|
|
|
|
--address=${cfg.address} \
|
|
|
|
${optionalString (cfg.featureGates != [])
|
|
|
|
"--feature-gates=${concatMapStringsSep "," (feature: "${feature}=true") cfg.featureGates}"} \
|
2019-03-11 10:03:40 +00:00
|
|
|
--kubeconfig=${environment.KUBECONFIG} \
|
2018-07-22 12:14:20 +01:00
|
|
|
--leader-elect=${boolToString cfg.leaderElect} \
|
|
|
|
--port=${toString cfg.port} \
|
|
|
|
${optionalString (cfg.verbosity != null) "--v=${toString cfg.verbosity}"} \
|
|
|
|
${cfg.extraOpts}
|
|
|
|
'';
|
|
|
|
WorkingDirectory = top.dataDir;
|
|
|
|
User = "kubernetes";
|
|
|
|
Group = "kubernetes";
|
2019-02-21 13:34:22 +00:00
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = 5;
|
2018-07-22 12:14:20 +01:00
|
|
|
};
|
2019-03-11 10:03:40 +00:00
|
|
|
unitConfig.ConditionPathExists = schedulerPaths;
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.paths.kube-scheduler = {
|
|
|
|
wantedBy = [ "kube-scheduler.service" ];
|
|
|
|
pathConfig = {
|
|
|
|
PathExists = schedulerPaths;
|
|
|
|
PathChanged = schedulerPaths;
|
|
|
|
};
|
2018-07-22 12:14:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
services.kubernetes.pki.certs = {
|
|
|
|
schedulerClient = top.lib.mkCert {
|
|
|
|
name = "kube-scheduler-client";
|
|
|
|
CN = "system:kube-scheduler";
|
|
|
|
action = "systemctl restart kube-scheduler.service";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.kubernetes.scheduler.kubeconfig.server = mkDefault top.apiserverAddress;
|
|
|
|
};
|
|
|
|
}
|