Cleanup pki: scheduler

This commit is contained in:
Christian Albrecht 2019-03-11 11:03:40 +01:00
parent 46653f84c9
commit 50c5f489ef
No known key found for this signature in database
GPG Key ID: 866AF4B25DF7EB00
2 changed files with 26 additions and 25 deletions

View File

@ -124,10 +124,6 @@ in
top.caFile top.caFile
certmgrAPITokenPath certmgrAPITokenPath
]; ];
schedulerPaths = mkIf top.scheduler.enable [
cfg.certs.schedulerClient.cert
cfg.certs.schedulerClient.key
];
in in
{ {
@ -287,19 +283,6 @@ in
}; };
}; };
systemd.services.kube-scheduler = mkIf top.scheduler.enable {
environment = { inherit (top.pki.certs.schedulerClient) cert key; };
unitConfig.ConditionPathExists = schedulerPaths;
};
systemd.paths.kube-scheduler = mkIf top.scheduler.enable {
wantedBy = [ "kube-scheduler.service" ];
pathConfig = {
PathExists = schedulerPaths;
PathChanged = schedulerPaths;
};
};
systemd.services.kube-control-plane-online.environment = let systemd.services.kube-control-plane-online.environment = let
client = with cfg.certs; if top.apiserver.enable then clusterAdmin else kubelet; client = with cfg.certs; if top.apiserver.enable then clusterAdmin else kubelet;
in { in {

View File

@ -56,18 +56,27 @@ in
}; };
###### implementation ###### implementation
config = mkIf cfg.enable { config = let
systemd.services.kube-scheduler = {
schedulerPaths = filter (a: a != null) [
cfg.kubeconfig.caFile
cfg.kubeconfig.certFile
cfg.kubeconfig.keyFile
];
in mkIf cfg.enable {
systemd.services.kube-scheduler = rec {
description = "Kubernetes Scheduler Service"; description = "Kubernetes Scheduler Service";
wantedBy = [ "kube-control-plane-online.target" ]; wantedBy = [ "kube-control-plane-online.target" ];
after = [ "kube-apiserver.service" ]; after = [ "kube-apiserver.service" ];
before = [ "kube-control-plane-online.target" ]; before = [ "kube-control-plane-online.target" ];
environment.KUBECONFIG = top.lib.mkKubeConfig "kube-scheduler" cfg.kubeconfig;
path = [ pkgs.kubectl ];
preStart = '' preStart = ''
${top.lib.mkWaitCurl ( with config.systemd.services.kube-scheduler; { until kubectl auth can-i get /api -q 2>/dev/null; do
sleep = 1; echo kubectl auth can-i get /api: exit status $?
path = "/api"; sleep 2
cacert = top.caFile; done
} // optionalAttrs (environment ? cert) { inherit (environment) cert key; })}
''; '';
serviceConfig = { serviceConfig = {
Slice = "kubernetes.slice"; Slice = "kubernetes.slice";
@ -75,7 +84,7 @@ in
--address=${cfg.address} \ --address=${cfg.address} \
${optionalString (cfg.featureGates != []) ${optionalString (cfg.featureGates != [])
"--feature-gates=${concatMapStringsSep "," (feature: "${feature}=true") cfg.featureGates}"} \ "--feature-gates=${concatMapStringsSep "," (feature: "${feature}=true") cfg.featureGates}"} \
--kubeconfig=${top.lib.mkKubeConfig "kube-scheduler" cfg.kubeconfig} \ --kubeconfig=${environment.KUBECONFIG} \
--leader-elect=${boolToString cfg.leaderElect} \ --leader-elect=${boolToString cfg.leaderElect} \
--port=${toString cfg.port} \ --port=${toString cfg.port} \
${optionalString (cfg.verbosity != null) "--v=${toString cfg.verbosity}"} \ ${optionalString (cfg.verbosity != null) "--v=${toString cfg.verbosity}"} \
@ -87,6 +96,15 @@ in
Restart = "on-failure"; Restart = "on-failure";
RestartSec = 5; RestartSec = 5;
}; };
unitConfig.ConditionPathExists = schedulerPaths;
};
systemd.paths.kube-scheduler = {
wantedBy = [ "kube-scheduler.service" ];
pathConfig = {
PathExists = schedulerPaths;
PathChanged = schedulerPaths;
};
}; };
services.kubernetes.pki.certs = { services.kubernetes.pki.certs = {