git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #124589 from hercules-ci/containers-dnsname

nixos/podman-dnsname: init

commitd9e45124431c887bedf665169d20d98e5854d113 authorRobert Hensing <roberth@users.noreply.github.com> dateWed 2 Jun 2021, 08:18 (5 years ago) parent6a882631d781e5
8 files changed+142−27
nixos/modules/virtualisation/containers.nix+21−1 nixos/modules/virtualisation/podman-dnsname.nix+36 nixos/modules/virtualisation/podman.nix+23−1 nixos/tests/all-tests.nix+1 nixos/tests/podman-dnsname.nix+42 pkgs/applications/networking/cluster/dnsname-cni/default.nix+15−5 pkgs/applications/networking/cluster/dnsname-cni/hardcode-dnsmasq-path.patch−19 pkgs/applications/virtualization/podman/default.nix+4−1
nixos/modules/virtualisation/containers.nix+21−1
@@ -48,6 +48,23 @@ in
4848 description = "containers.conf configuration";
4949 };
5050
51+ containersConf.cniPlugins = mkOption {
52+ type = types.listOf types.package;
53+ defaultText = ''
54+ [
55+ pkgs.cni-plugins
56+ ]
57+ '';
58+ example = lib.literalExample ''
59+ [
60+ pkgs.cniPlugins.dnsname
61+ ]
62+ '';
63+ description = ''
64+ CNI plugins to install on the system.
65+ '';
66+ };
67+
5168 registries = {
5269 search = mkOption {
5370 type = types.listOf types.str;
@@ -97,8 +114,11 @@ in
97114 };
98115
99116 config = lib.mkIf cfg.enable {
117+
118+ virtualisation.containers.containersConf.cniPlugins = [ pkgs.cni-plugins ];
119+
100120 virtualisation.containers.containersConf.settings = {
101− network.cni_plugin_dirs = [ "${pkgs.cni-plugins}/bin/" ];
121+ network.cni_plugin_dirs = map (p: "${lib.getBin p}/bin") cfg.containersConf.cniPlugins;
102122 engine = {
103123 init_path = "${pkgs.catatonit}/bin/catatonit";
104124 } // lib.optionalAttrs cfg.ociSeccompBpfHook.enable {
nixos/modules/virtualisation/podman-dnsname.nixnew file+36
@@ -0,0 +1,36 @@
1+{ config, lib, pkgs, ... }:
2+let
3+ inherit (lib)
4+ mkOption
5+ mkIf
6+ types
7+ ;
8+
9+ cfg = config.virtualisation.podman;
10+
11+in
12+{
13+ options = {
14+ virtualisation.podman = {
15+
16+ defaultNetwork.dnsname.enable = mkOption {
17+ type = types.bool;
18+ default = false;
19+ description = ''
20+ Enable DNS resolution in the default podman network.
21+ '';
22+ };
23+
24+ };
25+ };
26+
27+ config = {
28+ virtualisation.containers.containersConf.cniPlugins = mkIf cfg.defaultNetwork.dnsname.enable [ pkgs.dnsname-cni ];
29+ virtualisation.podman.defaultNetwork.extraPlugins =
30+ lib.optional cfg.defaultNetwork.dnsname.enable {
31+ type = "dnsname";
32+ domainName = "dns.podman";
33+ capabilities.aliases = true;
34+ };
35+ };
36+}
nixos/modules/virtualisation/podman.nix+23−1
@@ -2,6 +2,7 @@
22let
33 cfg = config.virtualisation.podman;
44 toml = pkgs.formats.toml { };
5+ json = pkgs.formats.json { };
56
67 inherit (lib) mkOption types;
78
@@ -22,9 +23,23 @@ let
2223 done
2324 '';
2425
26+ net-conflist = pkgs.runCommand "87-podman-bridge.conflist" {
27+ nativeBuildInputs = [ pkgs.jq ];
28+ extraPlugins = builtins.toJSON cfg.defaultNetwork.extraPlugins;
29+ jqScript = ''
30+ . + { "plugins": (.plugins + $extraPlugins) }
31+ '';
32+ } ''
33+ jq <${cfg.package}/etc/cni/net.d/87-podman-bridge.conflist \
34+ --argjson extraPlugins "$extraPlugins" \
35+ "$jqScript" \
36+ >$out
37+ '';
38+
2539in
2640{
2741 imports = [
42+ ./podman-dnsname.nix
2843 ./podman-network-socket.nix
2944 (lib.mkRenamedOptionModule [ "virtualisation" "podman" "libpod" ] [ "virtualisation" "containers" "containersConf" ])
3045 ];
@@ -99,6 +114,13 @@ in
99114 '';
100115 };
101116
117+ defaultNetwork.extraPlugins = lib.mkOption {
118+ type = types.listOf json.type;
119+ default = [];
120+ description = ''
121+ Extra CNI plugin configurations to add to podman's default network.
122+ '';
123+ };
102124
103125 };
104126
@@ -107,7 +129,7 @@ in
107129 environment.systemPackages = [ cfg.package ]
108130 ++ lib.optional cfg.dockerCompat dockerCompat;
109131
110− environment.etc."cni/net.d/87-podman-bridge.conflist".source = "${cfg.package}/etc/cni/net.d/87-podman-bridge.conflist";
132+ environment.etc."cni/net.d/87-podman-bridge.conflist".source = net-conflist;
111133
112134 virtualisation.containers = {
113135 enable = true; # Enable common /etc/containers configuration
nixos/tests/all-tests.nix+1
@@ -335,6 +335,7 @@ in
335335 plotinus = handleTest ./plotinus.nix {};
336336 podgrab = handleTest ./podgrab.nix {};
337337 podman = handleTestOn ["x86_64-linux"] ./podman.nix {};
338+ podman-dnsname = handleTestOn ["x86_64-linux"] ./podman-dnsname.nix {};
338339 podman-tls-ghostunnel = handleTestOn ["x86_64-linux"] ./podman-tls-ghostunnel.nix {};
339340 pomerium = handleTestOn ["x86_64-linux"] ./pomerium.nix {};
340341 postfix = handleTest ./postfix.nix {};
nixos/tests/podman-dnsname.nixnew file+42
@@ -0,0 +1,42 @@
1+import ./make-test-python.nix (
2+ { pkgs, lib, ... }:
3+ let
4+ inherit (pkgs) writeTextDir python3 curl;
5+ webroot = writeTextDir "index.html" "<h1>Hi</h1>";
6+ in
7+ {
8+ name = "podman-dnsname";
9+ meta = {
10+ maintainers = with lib.maintainers; [ roberth ] ++ lib.teams.podman.members;
11+ };
12+
13+ nodes = {
14+ podman = { pkgs, ... }: {
15+ virtualisation.podman.enable = true;
16+ virtualisation.podman.defaultNetwork.dnsname.enable = true;
17+ };
18+ };
19+
20+ testScript = ''
21+ podman.wait_for_unit("sockets.target")
22+
23+ with subtest("DNS works"): # also tests inter-container tcp routing
24+ podman.succeed("tar cv --files-from /dev/null | podman import - scratchimg")
25+ podman.succeed(
26+ "podman run -d --name=webserver -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin -w ${webroot} scratchimg ${python3}/bin/python -m http.server 8000"
27+ )
28+ podman.succeed("podman ps | grep webserver")
29+ podman.succeed("""
30+ for i in `seq 0 120`; do
31+ podman run --rm --name=client -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg ${curl}/bin/curl http://webserver:8000 >/dev/console \
32+ && exit 0
33+ sleep 0.5
34+ done
35+ exit 1
36+ """)
37+ podman.succeed("podman stop webserver")
38+ podman.succeed("podman rm webserver")
39+
40+ '';
41+ }
42+)
pkgs/applications/networking/cluster/dnsname-cni/default.nix+15−5
@@ -1,4 +1,11 @@
1−{ buildGoModule, fetchFromGitHub, lib, dnsmasq }:
1+{
2+ buildGoModule,
3+ dnsmasq,
4+ fetchFromGitHub,
5+ lib,
6+ nixosTests,
7+ makeWrapper,
8+}:
29
310buildGoModule rec {
411 pname = "cni-plugin-dnsname";
@@ -11,10 +18,9 @@ buildGoModule rec {
1118 sha256 = "sha256-hHkQOHDso92gXFCz40iQ7j2cHTEAMsaeW8MCJV2Otqo=";
1219 };
1320
14− patches = [ ./hardcode-dnsmasq-path.patch ];
15−
16− postPatch = ''
17− substituteInPlace plugins/meta/dnsname/service.go --replace '@DNSMASQ@' '${dnsmasq}/bin/dnsmasq'
21+ nativeBuildInputs = [ makeWrapper ];
22+ postInstall = ''
23+ wrapProgram $out/bin/dnsname --prefix PATH : ${lib.makeBinPath [ dnsmasq ]}
1824 '';
1925
2026 vendorSha256 = null;
@@ -22,6 +28,10 @@ buildGoModule rec {
2228
2329 doCheck = false; # NOTE: requires root privileges
2430
31+ passthru.tests = {
32+ inherit (nixosTests) podman-dnsname;
33+ };
34+
2535 meta = with lib; {
2636 description = "DNS name resolution for containers";
2737 homepage = "https://github.com/containers/dnsname";
pkgs/applications/networking/cluster/dnsname-cni/hardcode-dnsmasq-path.patchdeleted−19
@@ -1,19 +0,0 @@
1−diff --git a/plugins/meta/dnsname/service.go b/plugins/meta/dnsname/service.go
2−index fc05f75..f6b4caf 100644
3−--- a/plugins/meta/dnsname/service.go
4−+++ b/plugins/meta/dnsname/service.go
5−@@ -16,10 +16,14 @@ import (
6−
7− // newDNSMasqFile creates a new instance of a dnsNameFile
8− func newDNSMasqFile(domainName, networkInterface, networkName string) (dnsNameFile, error) {
9−+ /*
10− dnsMasqBinary, err := exec.LookPath("dnsmasq")
11− if err != nil {
12− return dnsNameFile{}, errors.Errorf("the dnsmasq cni plugin requires the dnsmasq binary be in PATH")
13− }
14−+ */
15−+ _ = errors.Errorf // XXX(mikroskeem): reduce diff
16−+ dnsMasqBinary := "@DNSMASQ@"
17− masqConf := dnsNameFile{
18− ConfigFile: makePath(networkName, confFileName),
19− Domain: domainName,
pkgs/applications/virtualization/podman/default.nix+4−1
@@ -84,7 +84,10 @@ buildGoModule rec {
8484 passthru.tests = {
8585 inherit (nixosTests) podman;
8686 # related modules
87− inherit (nixosTests) podman-tls-ghostunnel;
87+ inherit (nixosTests)
88+ podman-tls-ghostunnel
89+ podman-dnsname
90+ ;
8891 };
8992
9093 meta = with lib; {