diff options
author | Johan Thomsen <jth@dbc.dk> | 2019-02-11 13:47:45 +0100 |
---|---|---|
committer | Johan Thomsen <jth@dbc.dk> | 2019-02-12 18:26:39 +0100 |
commit | 9522ca5ce98af6a5b227adaa5164697385150366 (patch) | |
tree | ae9cc25def220296c7197b939f282d6dc7a77b2d /nixos/modules/services/networking/flannel.nix | |
parent | 67efb6f14c9323a725aa8bb8aae5adadfb57b132 (diff) | |
download | nixpkgs-9522ca5ce98af6a5b227adaa5164697385150366.tar nixpkgs-9522ca5ce98af6a5b227adaa5164697385150366.tar.gz nixpkgs-9522ca5ce98af6a5b227adaa5164697385150366.tar.bz2 nixpkgs-9522ca5ce98af6a5b227adaa5164697385150366.tar.lz nixpkgs-9522ca5ce98af6a5b227adaa5164697385150366.tar.xz nixpkgs-9522ca5ce98af6a5b227adaa5164697385150366.tar.zst nixpkgs-9522ca5ce98af6a5b227adaa5164697385150366.zip |
nixos/flannel: add options to configure kubernetes as config backend for flannel
Diffstat (limited to 'nixos/modules/services/networking/flannel.nix')
-rw-r--r-- | nixos/modules/services/networking/flannel.nix | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/nixos/modules/services/networking/flannel.nix b/nixos/modules/services/networking/flannel.nix index b93e28e34ef..cb39a53b5f9 100644 --- a/nixos/modules/services/networking/flannel.nix +++ b/nixos/modules/services/networking/flannel.nix @@ -73,11 +73,26 @@ in { }; }; + kubeconfig = mkOption { + description = '' + Path to kubeconfig to use for storing flannel config using the + Kubernetes API + ''; + type = types.nullOr types.path; + default = null; + }; + network = mkOption { description = " IPv4 network in CIDR format to use for the entire flannel network."; type = types.str; }; + storageBackend = mkOption { + description = "Determines where flannel stores its configuration at runtime"; + type = types.enum ["etcd" "kubernetes"]; + default = "etcd"; + }; + subnetLen = mkOption { description = '' The size of the subnet allocated to each host. Defaults to 24 (i.e. /24) @@ -122,17 +137,21 @@ in { after = [ "network.target" ]; environment = { FLANNELD_PUBLIC_IP = cfg.publicIp; + FLANNELD_IFACE = cfg.iface; + } // optionalAttrs (cfg.storageBackend == "etcd") { FLANNELD_ETCD_ENDPOINTS = concatStringsSep "," cfg.etcd.endpoints; FLANNELD_ETCD_KEYFILE = cfg.etcd.keyFile; FLANNELD_ETCD_CERTFILE = cfg.etcd.certFile; FLANNELD_ETCD_CAFILE = cfg.etcd.caFile; - FLANNELD_IFACE = cfg.iface; ETCDCTL_CERT_FILE = cfg.etcd.certFile; ETCDCTL_KEY_FILE = cfg.etcd.keyFile; ETCDCTL_CA_FILE = cfg.etcd.caFile; ETCDCTL_PEERS = concatStringsSep "," cfg.etcd.endpoints; + } // optionalAttrs (cfg.storageBackend == "kubernetes") { + FLANNELD_KUBE_SUBNET_MGR = "true"; + FLANNELD_KUBECONFIG_FILE = cfg.kubeconfig; }; - preStart = '' + preStart = mkIf (cfg.storageBackend == "etcd") '' echo "setting network configuration" until ${pkgs.etcdctl.bin}/bin/etcdctl set /coreos.com/network/config '${builtins.toJSON networkConfig}' do @@ -149,6 +168,12 @@ in { serviceConfig.ExecStart = "${cfg.package}/bin/flannel"; }; - services.etcd.enable = mkDefault (cfg.etcd.endpoints == ["http://127.0.0.1:2379"]); + services.etcd.enable = mkDefault (cfg.storageBackend == "etcd" && cfg.etcd.endpoints == ["http://127.0.0.1:2379"]); + + # for some reason, flannel doesn't let you configure this path + # see: https://github.com/coreos/flannel/blob/master/Documentation/configuration.md#configuration + environment.etc."kube-flannel/net-conf.json" = mkIf (cfg.storageBackend == "kubernetes") { + source = pkgs.writeText "net-conf.json" (builtins.toJSON networkConfig); + }; }; } |