blob: a1b1a35392a63423a4ba82347cf5a74ff70a0a96 [file] [log] [blame]
Serge Bazanskief3aab62022-11-18 14:39:45 +00001# Vendored from nixpkgs git 44ad80ab1036c5cc83ada4bfa451dac9939f2a10
2# Copyright (c) 2003-2023 Eelco Dolstra and the Nixpkgs/NixOS contributors
3# SPDX-License-Identifier: MIT
Bartosz Stebel9a88f282023-10-08 22:26:20 +02004#
5# Same as upstream proxy.nix module from nixpkgs, but with one change:
6# - use the package from top.kubelet.package instead of top.package
Serge Bazanskief3aab62022-11-18 14:39:45 +00007
8{ config, lib, pkgs, ... }:
9
10with lib;
11
12let
13 top = config.services.kubernetes;
14 cfg = top.proxy;
15in
16{
17 imports = [
18 (mkRenamedOptionModule [ "services" "kubernetes" "proxy" "address" ] ["services" "kubernetes" "proxy" "bindAddress"])
19 ];
20
21 ###### interface
22 options.services.kubernetes.proxy = with lib.types; {
23
24 bindAddress = mkOption {
25 description = "Kubernetes proxy listening address.";
26 default = "0.0.0.0";
27 type = str;
28 };
29
30 enable = mkEnableOption "Kubernetes proxy";
31
32 extraOpts = mkOption {
33 description = "Kubernetes proxy extra command line options.";
34 default = "";
35 type = str;
36 };
37
38 featureGates = mkOption {
39 description = "List set of feature gates";
40 default = top.featureGates;
41 type = listOf str;
42 };
43
44 hostname = mkOption {
45 description = "Kubernetes proxy hostname override.";
46 default = config.networking.hostName;
47 type = str;
48 };
49
50 kubeconfig = top.lib.mkKubeConfigOptions "Kubernetes proxy";
51
52 verbosity = mkOption {
53 description = ''
54 Optional glog verbosity level for logging statements. See
55 <link xlink:href="https://github.com/kubernetes/community/blob/master/contributors/devel/logging.md"/>
56 '';
57 default = null;
58 type = nullOr int;
59 };
60
61 };
62
63 ###### implementation
64 config = mkIf cfg.enable {
65 systemd.services.kube-proxy = {
66 description = "Kubernetes Proxy Service";
67 wantedBy = [ "kubernetes.target" ];
68 after = [ "kube-apiserver.service" ];
69 path = with pkgs; [ iptables conntrack_tools ];
70 serviceConfig = {
71 Slice = "kubernetes.slice";
Bartosz Stebel9a88f282023-10-08 22:26:20 +020072 # hscloud change: use kubelet pkg
73 ExecStart = ''${top.kubelet.package}/bin/kube-proxy \
Serge Bazanskief3aab62022-11-18 14:39:45 +000074 --bind-address=${cfg.bindAddress} \
75 ${optionalString (top.clusterCidr!=null)
76 "--cluster-cidr=${top.clusterCidr}"} \
77 ${optionalString (cfg.featureGates != [])
78 "--feature-gates=${concatMapStringsSep "," (feature: "${feature}=true") cfg.featureGates}"} \
79 --hostname-override=${cfg.hostname} \
80 --kubeconfig=${top.lib.mkKubeConfig "kube-proxy" cfg.kubeconfig} \
81 ${optionalString (cfg.verbosity != null) "--v=${toString cfg.verbosity}"} \
82 ${cfg.extraOpts}
83 '';
84 WorkingDirectory = top.dataDir;
85 Restart = "on-failure";
86 RestartSec = 5;
87 };
88 };
89
90 services.kubernetes.proxy.hostname = with config.networking; mkDefault hostName;
91
92 services.kubernetes.pki.certs = {
93 kubeProxyClient = top.lib.mkCert {
94 name = "kube-proxy-client";
95 CN = "system:kube-proxy";
96 action = "systemctl restart kube-proxy.service";
97 };
98 };
99
100 services.kubernetes.proxy.kubeconfig.server = mkDefault top.apiserverAddress;
101 };
102}