git.iko.soy/typeable/nixpkgs
on master help sign in
flannel service: init
commitfeb9fc3aff07698a01163336613224b08547d65b authorJaka Hudoklin <jakahudoklin@gmail.com> dateTue 27 Sep 2016, 22:56 (10 years ago) parenteb1377b
3 files changed+209
nixos/modules/module-list.nix+1 nixos/modules/services/networking/flannel.nix+153 nixos/tests/flannel.nix+55
nixos/modules/module-list.nix+1
@@ -345,6 +345,7 @@
345345 ./services/networking/ferm.nix
346346 ./services/networking/firefox/sync-server.nix
347347 ./services/networking/firewall.nix
348+ ./services/networking/flannel.nix
348349 ./services/networking/flashpolicyd.nix
349350 ./services/networking/freenet.nix
350351 ./services/networking/gale.nix
nixos/modules/services/networking/flannel.nixnew file+153
@@ -0,0 +1,153 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.flannel;
7+
8+ networkConfig = filterAttrs (n: v: v != null) {
9+ Network = cfg.network;
10+ SubnetLen = cfg.subnetLen;
11+ SubnetMin = cfg.subnetMin;
12+ SubnetMax = cfg.subnetMax;
13+ Backend = cfg.backend;
14+ };
15+in {
16+ options.services.flannel = {
17+ enable = mkEnableOption "flannel";
18+
19+ package = mkOption {
20+ description = "Package to use for flannel";
21+ type = types.package;
22+ default = pkgs.flannel.bin;
23+ };
24+
25+ publicIp = mkOption {
26+ description = ''
27+ IP accessible by other nodes for inter-host communication.
28+ Defaults to the IP of the interface being used for communication.
29+ '';
30+ type = types.nullOr types.str;
31+ default = null;
32+ };
33+
34+ iface = mkOption {
35+ description = ''
36+ Interface to use (IP or name) for inter-host communication.
37+ Defaults to the interface for the default route on the machine.
38+ '';
39+ type = types.nullOr types.str;
40+ default = null;
41+ };
42+
43+ etcd = {
44+ endpoints = mkOption {
45+ description = "Etcd endpoints";
46+ type = types.listOf types.str;
47+ default = ["http://127.0.0.1:2379"];
48+ };
49+
50+ prefix = mkOption {
51+ description = "Etcd key prefix";
52+ type = types.str;
53+ default = "/coreos.com/network";
54+ };
55+
56+ caFile = mkOption {
57+ description = "Etcd certificate authority file";
58+ type = types.nullOr types.path;
59+ default = null;
60+ };
61+
62+ certFile = mkOption {
63+ description = "Etcd cert file";
64+ type = types.nullOr types.path;
65+ default = null;
66+ };
67+
68+ keyFile = mkOption {
69+ description = "Etcd key file";
70+ type = types.nullOr types.path;
71+ default = null;
72+ };
73+ };
74+
75+ network = mkOption {
76+ description = " IPv4 network in CIDR format to use for the entire flannel network.";
77+ type = types.str;
78+ };
79+
80+ subnetLen = mkOption {
81+ description = ''
82+ The size of the subnet allocated to each host. Defaults to 24 (i.e. /24)
83+ unless the Network was configured to be smaller than a /24 in which case
84+ it is one less than the network.
85+ '';
86+ type = types.int;
87+ default = 24;
88+ };
89+
90+ subnetMin = mkOption {
91+ description = ''
92+ The beginning of IP range which the subnet allocation should start with.
93+ Defaults to the first subnet of Network.
94+ '';
95+ type = types.nullOr types.str;
96+ default = null;
97+ };
98+
99+ subnetMax = mkOption {
100+ description = ''
101+ The end of IP range which the subnet allocation should start with.
102+ Defaults to the last subnet of Network.
103+ '';
104+ type = types.nullOr types.str;
105+ default = null;
106+ };
107+
108+ backend = mkOption {
109+ description = "Type of backend to use and specific configurations for that backend.";
110+ type = types.attrs;
111+ default = {
112+ Type = "vxlan";
113+ };
114+ };
115+ };
116+
117+ config = mkIf cfg.enable {
118+ systemd.services.flannel = {
119+ description = "Flannel Service";
120+ wantedBy = [ "multi-user.target" ];
121+ after = [ "network.target" ];
122+ environment = {
123+ FLANNELD_PUBLIC_IP = cfg.publicIp;
124+ FLANNELD_ETCD_ENDPOINTS = concatStringsSep "," cfg.etcd.endpoints;
125+ FLANNELD_ETCD_KEYFILE = cfg.etcd.keyFile;
126+ FLANNELD_ETCD_CERTFILE = cfg.etcd.certFile;
127+ FLANNELD_ETCD_CAFILE = cfg.etcd.caFile;
128+ FLANNELD_IFACE = cfg.iface;
129+ ETCDCTL_CERT_FILE = cfg.etcd.certFile;
130+ ETCDCTL_KEY_FILE = cfg.etcd.keyFile;
131+ ETCDCTL_CA_FILE = cfg.etcd.caFile;
132+ ETCDCTL_PEERS = concatStringsSep "," cfg.etcd.endpoints;
133+ };
134+ preStart = ''
135+ echo "setting network configuration"
136+ until ${pkgs.etcdctl.bin}/bin/etcdctl set /coreos.com/network/config '${builtins.toJSON networkConfig}'
137+ do
138+ echo "setting network configuration, retry"
139+ sleep 1
140+ done
141+ '';
142+ postStart = ''
143+ while [ ! -f /run/flannel/subnet.env ]
144+ do
145+ sleep 1
146+ done
147+ '';
148+ serviceConfig.ExecStart = "${cfg.package}/bin/flannel";
149+ };
150+
151+ services.etcd.enable = mkDefault cfg.etcd.endpoints == ["http://127.0.0.1:2379"];
152+ };
153+}
nixos/tests/flannel.nixnew file+55
@@ -0,0 +1,55 @@
1+import ./make-test.nix ({ pkgs, ...} : rec {
2+ name = "flannel";
3+
4+ meta = with pkgs.stdenv.lib.maintainers; {
5+ maintainers = [ offline ];
6+ };
7+
8+ nodes = let
9+ flannelConfig = {
10+ services.flannel = {
11+ enable = true;
12+ network = "10.1.0.0/16";
13+ iface = "eth1";
14+ etcd.endpoints = ["http://etcd:2379"];
15+ };
16+
17+ networking.firewall.allowedUDPPorts = [ 8472 ];
18+ };
19+ in {
20+ etcd = { config, pkgs, ... }: {
21+ services = {
22+ etcd = {
23+ enable = true;
24+ listenClientUrls = ["http://etcd:2379"];
25+ listenPeerUrls = ["http://etcd:2380"];
26+ initialAdvertisePeerUrls = ["http://etcd:2379"];
27+ initialCluster = ["etcd=http://etcd:2379"];
28+ };
29+ };
30+
31+ networking.firewall.allowedTCPPorts = [ 2379 ];
32+ };
33+
34+ node1 = { config, ... }: {
35+ require = [flannelConfig];
36+ };
37+
38+ node2 = { config, ... }: {
39+ require = [flannelConfig];
40+ };
41+ };
42+
43+ testScript = ''
44+ startAll;
45+
46+ $node1->waitForUnit("flannel.service");
47+ $node2->waitForUnit("flannel.service");
48+
49+ my $ip1 = $node1->succeed("ip -4 addr show flannel.1 | grep -oP '(?<=inet).*(?=/)'");
50+ my $ip2 = $node2->succeed("ip -4 addr show flannel.1 | grep -oP '(?<=inet).*(?=/)'");
51+
52+ $node1->waitUntilSucceeds("ping -c 1 $ip2");
53+ $node2->waitUntilSucceeds("ping -c 1 $ip1");
54+ '';
55+})