mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-12 05:16:25 +03:00
nixos/services.flannel: remove with lib;
This commit is contained in:
parent
00d0e3ba98
commit
688b08939c
1 changed files with 42 additions and 45 deletions
|
@ -1,11 +1,8 @@
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.services.flannel;
|
cfg = config.services.flannel;
|
||||||
|
|
||||||
networkConfig = filterAttrs (n: v: v != null) {
|
networkConfig = lib.filterAttrs (n: v: v != null) {
|
||||||
Network = cfg.network;
|
Network = cfg.network;
|
||||||
SubnetLen = cfg.subnetLen;
|
SubnetLen = cfg.subnetLen;
|
||||||
SubnetMin = cfg.subnetMin;
|
SubnetMin = cfg.subnetMin;
|
||||||
|
@ -14,128 +11,128 @@ let
|
||||||
};
|
};
|
||||||
in {
|
in {
|
||||||
options.services.flannel = {
|
options.services.flannel = {
|
||||||
enable = mkEnableOption "flannel";
|
enable = lib.mkEnableOption "flannel";
|
||||||
|
|
||||||
package = mkPackageOption pkgs "flannel" { };
|
package = lib.mkPackageOption pkgs "flannel" { };
|
||||||
|
|
||||||
publicIp = mkOption {
|
publicIp = lib.mkOption {
|
||||||
description = ''
|
description = ''
|
||||||
IP accessible by other nodes for inter-host communication.
|
IP accessible by other nodes for inter-host communication.
|
||||||
Defaults to the IP of the interface being used for communication.
|
Defaults to the IP of the interface being used for communication.
|
||||||
'';
|
'';
|
||||||
type = types.nullOr types.str;
|
type = lib.types.nullOr lib.types.str;
|
||||||
default = null;
|
default = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
iface = mkOption {
|
iface = lib.mkOption {
|
||||||
description = ''
|
description = ''
|
||||||
Interface to use (IP or name) for inter-host communication.
|
Interface to use (IP or name) for inter-host communication.
|
||||||
Defaults to the interface for the default route on the machine.
|
Defaults to the interface for the default route on the machine.
|
||||||
'';
|
'';
|
||||||
type = types.nullOr types.str;
|
type = lib.types.nullOr lib.types.str;
|
||||||
default = null;
|
default = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
etcd = {
|
etcd = {
|
||||||
endpoints = mkOption {
|
endpoints = lib.mkOption {
|
||||||
description = "Etcd endpoints";
|
description = "Etcd endpoints";
|
||||||
type = types.listOf types.str;
|
type = lib.types.listOf lib.types.str;
|
||||||
default = ["http://127.0.0.1:2379"];
|
default = ["http://127.0.0.1:2379"];
|
||||||
};
|
};
|
||||||
|
|
||||||
prefix = mkOption {
|
prefix = lib.mkOption {
|
||||||
description = "Etcd key prefix";
|
description = "Etcd key prefix";
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
default = "/coreos.com/network";
|
default = "/coreos.com/network";
|
||||||
};
|
};
|
||||||
|
|
||||||
caFile = mkOption {
|
caFile = lib.mkOption {
|
||||||
description = "Etcd certificate authority file";
|
description = "Etcd certificate authority file";
|
||||||
type = types.nullOr types.path;
|
type = lib.types.nullOr lib.types.path;
|
||||||
default = null;
|
default = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
certFile = mkOption {
|
certFile = lib.mkOption {
|
||||||
description = "Etcd cert file";
|
description = "Etcd cert file";
|
||||||
type = types.nullOr types.path;
|
type = lib.types.nullOr lib.types.path;
|
||||||
default = null;
|
default = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
keyFile = mkOption {
|
keyFile = lib.mkOption {
|
||||||
description = "Etcd key file";
|
description = "Etcd key file";
|
||||||
type = types.nullOr types.path;
|
type = lib.types.nullOr lib.types.path;
|
||||||
default = null;
|
default = null;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
kubeconfig = mkOption {
|
kubeconfig = lib.mkOption {
|
||||||
description = ''
|
description = ''
|
||||||
Path to kubeconfig to use for storing flannel config using the
|
Path to kubeconfig to use for storing flannel config using the
|
||||||
Kubernetes API
|
Kubernetes API
|
||||||
'';
|
'';
|
||||||
type = types.nullOr types.path;
|
type = lib.types.nullOr lib.types.path;
|
||||||
default = null;
|
default = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
network = mkOption {
|
network = lib.mkOption {
|
||||||
description = " IPv4 network in CIDR format to use for the entire flannel network.";
|
description = " IPv4 network in CIDR format to use for the entire flannel network.";
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
};
|
};
|
||||||
|
|
||||||
nodeName = mkOption {
|
nodeName = lib.mkOption {
|
||||||
description = ''
|
description = ''
|
||||||
Needed when running with Kubernetes as backend as this cannot be auto-detected";
|
Needed when running with Kubernetes as backend as this cannot be auto-detected";
|
||||||
'';
|
'';
|
||||||
type = types.nullOr types.str;
|
type = lib.types.nullOr lib.types.str;
|
||||||
default = config.networking.fqdnOrHostName;
|
default = config.networking.fqdnOrHostName;
|
||||||
defaultText = literalExpression "config.networking.fqdnOrHostName";
|
defaultText = lib.literalExpression "config.networking.fqdnOrHostName";
|
||||||
example = "node1.example.com";
|
example = "node1.example.com";
|
||||||
};
|
};
|
||||||
|
|
||||||
storageBackend = mkOption {
|
storageBackend = lib.mkOption {
|
||||||
description = "Determines where flannel stores its configuration at runtime";
|
description = "Determines where flannel stores its configuration at runtime";
|
||||||
type = types.enum ["etcd" "kubernetes"];
|
type = lib.types.enum ["etcd" "kubernetes"];
|
||||||
default = "etcd";
|
default = "etcd";
|
||||||
};
|
};
|
||||||
|
|
||||||
subnetLen = mkOption {
|
subnetLen = lib.mkOption {
|
||||||
description = ''
|
description = ''
|
||||||
The size of the subnet allocated to each host. Defaults to 24 (i.e. /24)
|
The size of the subnet allocated to each host. Defaults to 24 (i.e. /24)
|
||||||
unless the Network was configured to be smaller than a /24 in which case
|
unless the Network was configured to be smaller than a /24 in which case
|
||||||
it is one less than the network.
|
it is one less than the network.
|
||||||
'';
|
'';
|
||||||
type = types.int;
|
type = lib.types.int;
|
||||||
default = 24;
|
default = 24;
|
||||||
};
|
};
|
||||||
|
|
||||||
subnetMin = mkOption {
|
subnetMin = lib.mkOption {
|
||||||
description = ''
|
description = ''
|
||||||
The beginning of IP range which the subnet allocation should start with.
|
The beginning of IP range which the subnet allocation should start with.
|
||||||
Defaults to the first subnet of Network.
|
Defaults to the first subnet of Network.
|
||||||
'';
|
'';
|
||||||
type = types.nullOr types.str;
|
type = lib.types.nullOr lib.types.str;
|
||||||
default = null;
|
default = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
subnetMax = mkOption {
|
subnetMax = lib.mkOption {
|
||||||
description = ''
|
description = ''
|
||||||
The end of IP range which the subnet allocation should start with.
|
The end of IP range which the subnet allocation should start with.
|
||||||
Defaults to the last subnet of Network.
|
Defaults to the last subnet of Network.
|
||||||
'';
|
'';
|
||||||
type = types.nullOr types.str;
|
type = lib.types.nullOr lib.types.str;
|
||||||
default = null;
|
default = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
backend = mkOption {
|
backend = lib.mkOption {
|
||||||
description = "Type of backend to use and specific configurations for that backend.";
|
description = "Type of backend to use and specific configurations for that backend.";
|
||||||
type = types.attrs;
|
type = lib.types.attrs;
|
||||||
default = {
|
default = {
|
||||||
Type = "vxlan";
|
Type = "vxlan";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
systemd.services.flannel = {
|
systemd.services.flannel = {
|
||||||
description = "Flannel Service";
|
description = "Flannel Service";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
@ -143,23 +140,23 @@ in {
|
||||||
environment = {
|
environment = {
|
||||||
FLANNELD_PUBLIC_IP = cfg.publicIp;
|
FLANNELD_PUBLIC_IP = cfg.publicIp;
|
||||||
FLANNELD_IFACE = cfg.iface;
|
FLANNELD_IFACE = cfg.iface;
|
||||||
} // optionalAttrs (cfg.storageBackend == "etcd") {
|
} // lib.optionalAttrs (cfg.storageBackend == "etcd") {
|
||||||
FLANNELD_ETCD_ENDPOINTS = concatStringsSep "," cfg.etcd.endpoints;
|
FLANNELD_ETCD_ENDPOINTS = lib.concatStringsSep "," cfg.etcd.endpoints;
|
||||||
FLANNELD_ETCD_KEYFILE = cfg.etcd.keyFile;
|
FLANNELD_ETCD_KEYFILE = cfg.etcd.keyFile;
|
||||||
FLANNELD_ETCD_CERTFILE = cfg.etcd.certFile;
|
FLANNELD_ETCD_CERTFILE = cfg.etcd.certFile;
|
||||||
FLANNELD_ETCD_CAFILE = cfg.etcd.caFile;
|
FLANNELD_ETCD_CAFILE = cfg.etcd.caFile;
|
||||||
ETCDCTL_CERT = cfg.etcd.certFile;
|
ETCDCTL_CERT = cfg.etcd.certFile;
|
||||||
ETCDCTL_KEY = cfg.etcd.keyFile;
|
ETCDCTL_KEY = cfg.etcd.keyFile;
|
||||||
ETCDCTL_CACERT = cfg.etcd.caFile;
|
ETCDCTL_CACERT = cfg.etcd.caFile;
|
||||||
ETCDCTL_ENDPOINTS = concatStringsSep "," cfg.etcd.endpoints;
|
ETCDCTL_ENDPOINTS = lib.concatStringsSep "," cfg.etcd.endpoints;
|
||||||
ETCDCTL_API = "3";
|
ETCDCTL_API = "3";
|
||||||
} // optionalAttrs (cfg.storageBackend == "kubernetes") {
|
} // lib.optionalAttrs (cfg.storageBackend == "kubernetes") {
|
||||||
FLANNELD_KUBE_SUBNET_MGR = "true";
|
FLANNELD_KUBE_SUBNET_MGR = "true";
|
||||||
FLANNELD_KUBECONFIG_FILE = cfg.kubeconfig;
|
FLANNELD_KUBECONFIG_FILE = cfg.kubeconfig;
|
||||||
NODE_NAME = cfg.nodeName;
|
NODE_NAME = cfg.nodeName;
|
||||||
};
|
};
|
||||||
path = [ pkgs.iptables ];
|
path = [ pkgs.iptables ];
|
||||||
preStart = optionalString (cfg.storageBackend == "etcd") ''
|
preStart = lib.optionalString (cfg.storageBackend == "etcd") ''
|
||||||
echo "setting network configuration"
|
echo "setting network configuration"
|
||||||
until ${pkgs.etcd}/bin/etcdctl put /coreos.com/network/config '${builtins.toJSON networkConfig}'
|
until ${pkgs.etcd}/bin/etcdctl put /coreos.com/network/config '${builtins.toJSON networkConfig}'
|
||||||
do
|
do
|
||||||
|
@ -175,11 +172,11 @@ in {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
services.etcd.enable = mkDefault (cfg.storageBackend == "etcd" && cfg.etcd.endpoints == ["http://127.0.0.1:2379"]);
|
services.etcd.enable = lib.mkDefault (cfg.storageBackend == "etcd" && cfg.etcd.endpoints == ["http://127.0.0.1:2379"]);
|
||||||
|
|
||||||
# for some reason, flannel doesn't let you configure this path
|
# for some reason, flannel doesn't let you configure this path
|
||||||
# see: https://github.com/coreos/flannel/blob/master/Documentation/configuration.md#configuration
|
# see: https://github.com/coreos/flannel/blob/master/Documentation/configuration.md#configuration
|
||||||
environment.etc."kube-flannel/net-conf.json" = mkIf (cfg.storageBackend == "kubernetes") {
|
environment.etc."kube-flannel/net-conf.json" = lib.mkIf (cfg.storageBackend == "kubernetes") {
|
||||||
source = pkgs.writeText "net-conf.json" (builtins.toJSON networkConfig);
|
source = pkgs.writeText "net-conf.json" (builtins.toJSON networkConfig);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue