conlink 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ name: Push (compose tests)
2
+
3
+ on:
4
+ push: {}
5
+ pull_request:
6
+ branches: [ master ]
7
+ workflow_dispatch: {}
8
+
9
+ jobs:
10
+ compose-tests:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: Checkout
14
+ uses: actions/checkout@v3
15
+
16
+ - name: stub step
17
+ run: "echo stub stub"
package/Dockerfile CHANGED
@@ -24,7 +24,7 @@ FROM node:16-slim as run
24
24
  RUN apt-get -y update
25
25
  # Runtime deps and utilities
26
26
  RUN apt-get -y install libpcap-dev tcpdump iproute2 iputils-ping curl \
27
- iptables \
27
+ iptables bridge-utils \
28
28
  openvswitch-switch openvswitch-testcontroller
29
29
 
30
30
  COPY --from=build /app/ /app/
package/README.md CHANGED
@@ -1,14 +1,24 @@
1
1
  # conlink: Declarative Low-Level Networking for Containers
2
2
 
3
+
3
4
  Create (layer 2 and layer 3) networking between containers using
4
5
  a declarative configuration.
5
6
 
6
7
  ## Prerequisites
7
8
 
9
+ General:
10
+ * docker
8
11
  * docker-compose version 1.25.4 or later.
9
- * `openvswitch` kernel module loaded on the host
10
- * `geneve` (and/or `vxlan`) kernel module loaded on the host (only
11
- needed for `test5-geneve-compose` example)
12
+
13
+ Other:
14
+ * For Open vSwtich (OVS) bridging, the `openvswitch` kernel module
15
+ must loaded on the host system (where docker engine is running).
16
+ * For podman usage (e.g. second part of `test3`), podman is required.
17
+ * For remote connections/links (e.g. `test5`), the `geneve` (and/or
18
+ `vxlan`) kernel module must be loaded on the host system (where
19
+ docker engine is running)
20
+ * For CloudFormation deployment (e.g. `test6`), the AWS CLI is
21
+ required.
12
22
 
13
23
  ## Usage Notes
14
24
 
@@ -34,6 +44,18 @@ will also be required for the conlink container. In particular, if the
34
44
  container uses systemd, then it will likely use `SYS_NICE` and
35
45
  `NET_BROADCAST` and conlink will likewise need those capabilities.
36
46
 
47
+ ### Bridging: Open vSwtich/OVS or Linux bridge
48
+
49
+ Conlink creates bridges/switches and connects veth container links to
50
+ those bridges (specified by `bridge:` in the link specification).
51
+ By default, conlink will attempt to create Open vSwitch/OVS bridges
52
+ for these connections, however, if the kernel does not provide support
53
+ (`openvswitch` kernel module loaded), then conlink will fallback to
54
+ using standard Linux bridges. The fallback behavior can be changed by
55
+ setting the `--bridge-mode` option to either "ovs" or "linux". If the
56
+ bridge mode is set to "ovs" then conlink will fail to start if the
57
+ `openvswitch` kernel module is not detected.
58
+
37
59
  ## Network Configuration Syntax
38
60
 
39
61
  Network configuration can either be loaded directly from configuration
@@ -71,8 +93,8 @@ The following table describes the link properties:
71
93
  | route | * | string | | ip route add args |
72
94
  | nat | * | IP | | DNAT/SNAT to IP |
73
95
  | netem | * | string | | tc qdisc NetEm options |
74
- | mode | 5 | IP | | virt intf mode |
75
- | vlanid | vlan | IP | | VLAN ID |
96
+ | mode | 5 | string | | virt intf mode |
97
+ | vlanid | vlan | number | | VLAN ID |
76
98
 
77
99
  - 1 - veth, dummy, vlan, ipvlan, macvlan, ipvtap, macvtap
78
100
  - 2 - defaults to outer compose service
@@ -186,11 +208,11 @@ From the second node ping an address in the internet service:
186
208
  docker-compose -f examples/test2-compose.yaml exec --index 2 node ping 8.8.8.8
187
209
  ```
188
210
 
189
- Scale the nodes from 2 to 5 and then ping from first node from the fifth:
211
+ Scale the nodes from 2 to 5 and then ping the fifth node from the second:
190
212
 
191
213
  ```
192
214
  docker-compose -f examples/test2-compose.yaml up -d --scale node=5
193
- docker-compose -f examples/test2-compose.yaml exec --index 5 node ping 10.0.1.1
215
+ docker-compose -f examples/test2-compose.yaml exec --index 2 node ping 10.0.1.5
194
216
  ```
195
217
 
196
218
 
@@ -261,7 +283,7 @@ defined in the first compose file.
261
283
  MODES_DIR=./examples/test4-multiple/modes ./mdc node1 up --build --force-recreate
262
284
  ```
263
285
 
264
- Ping the router host from `node`:
286
+ Ping the router host from `node1`:
265
287
 
266
288
  ```
267
289
  docker-compose exec node1 ping 10.0.0.100
@@ -282,6 +304,14 @@ docker-compose exec --index 1 node2 ping 10.1.0.1
282
304
  docker-compose exec --index 2 node2 ping 10.1.0.1
283
305
  ```
284
306
 
307
+ From `node1`, ping both `node2` replicas across the switches and `r0` router:
308
+
309
+ ```
310
+ docker-compose exec node1 ping 10.2.0.1
311
+ docker-compose exec node1 ping 10.2.0.2
312
+ ```
313
+
314
+
285
315
  Restart the compose instance and add another compose file that starts
286
316
  conlink using an addition network file `web-network.yaml`. The network
287
317
  file starts up a simple web server on the router.
@@ -395,8 +425,8 @@ Show the links in both node containers to see that the MAC addresses
395
425
  are `00:0a:0b:0c:0d:0*` and the MTUs are set to `4111`.
396
426
 
397
427
  ```
398
- docker-compose -f examples/test7-compose.yaml exec --index 1 ip link
399
- docker-compose -f examples/test7-compose.yaml exec --index 2 ip link
428
+ docker-compose -f examples/test7-compose.yaml exec --index 1 node ip link
429
+ docker-compose -f examples/test7-compose.yaml exec --index 2 node ip link
400
430
  ```
401
431
 
402
432
  Ping the second node from the first to show the the NetEm setting is
package/mdc CHANGED
@@ -1,4 +1,4 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env bash
2
2
 
3
3
  set -e
4
4
  shopt -s dotglob # recursive copy of dot files too
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "conlink",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "conlink - Declarative Low-Level Networking for Containers",
5
5
  "repository": "https://github.com/LonoCloud/conlink",
6
6
  "license": "SEE LICENSE IN LICENSE",
package/scripts/copy.sh CHANGED
@@ -26,9 +26,11 @@ dst_dir="${1}"; shift || die 2 "Usage: ${0} [-T|--template] SRC_DIR DST_DIR"
26
26
  cp -a "${src}" "${dst}" || die 1 "Failed to copy file"
27
27
  # TODO: make this configurable
28
28
  chown root.root "${dst}" || die 1 "Unable to set ownership"
29
+ chmod +w "${dst}" || die 1 "Unable to make writable"
29
30
 
30
31
  [ -z "${TEMPLATE}" ] && continue
31
32
 
33
+ tmpfile="$(mktemp)"
32
34
  # match all {{FOO}} style variables and replace from environment
33
35
  for v in $(cat "${dst}" | grep -o '{{[^ }{]*}}' | sed 's/[}{]//g' | sort -u); do
34
36
  if set | grep -qs "^${v}="; then
@@ -36,9 +38,11 @@ dst_dir="${1}"; shift || die 2 "Usage: ${0} [-T|--template] SRC_DIR DST_DIR"
36
38
  | sed "s/^['\"]\(.*\)['\"]$/\1/" \
37
39
  | sed 's/[\/&]/\\&/g')
38
40
  echo "Replacing '{{${v}}}' with '${val}' in '${dst}'"
39
- sed -i "s/{{${v}}}/${val}/g" "${dst}"
41
+ sed "s/{{${v}}}/${val}/g" "${dst}" > "${tmpfile}"
42
+ cp "${tmpfile}" "${dst}"
40
43
  fi
41
44
  done
45
+ rm -f "${tmpfile}"
42
46
  done
43
47
 
44
48
  if [ "${*}" ]; then
@@ -27,9 +27,9 @@ General Options:
27
27
  -v, --verbose Show verbose output (stderr)
28
28
  [env: VERBOSE]
29
29
  --show-config Print loaded network config JSON and exit
30
- --bridge-mode BRIDGE-MODE Bridge mode (ovs or linux) to use for
31
- bridge/switch connections
32
- [default: ovs]
30
+ --bridge-mode BRIDGE-MODE Bridge mode (ovs, linux, or auto)
31
+ to use for bridge/switch connections
32
+ [default: auto] [env: CONLINK_BRIDGE_MODE]
33
33
  --network-file NETWORK-FILE... Network config file
34
34
  --compose-file COMPOSE-FILE... Docker compose file with network config
35
35
  --compose-project NAME Docker compose project name for resolving
@@ -651,17 +651,38 @@ General Options:
651
651
  (fatal 2 "Could not find config-schema" orig-config-schema)))
652
652
 
653
653
  (defn startup-checks
654
- "Check startup state and exit if openvswitch kernel module is not
655
- loaded or if no docker or podman connection could be established."
656
- [bridge-mode docker podman]
654
+ "Check startup state and return map of :bridge-mode, :docker, and
655
+ :podman. If bridge-mode is :auto then return :ovs if the
656
+ 'openvswitch' kernel module is loaded otherwise fall back to :linux.
657
+ Exit with an error if bridge-mode is :ovs and the 'openvswitch'
658
+ kernel module is not loaded or if neither a docker or podman
659
+ connection could be established."
660
+ [{:keys [bridge-mode docker-socket podman-socket]}]
657
661
  (P/let
658
- [kmod-okay? (if (= :ovs bridge-mode)
659
- (kmod-loaded? "openvswitch")
660
- true)]
661
- (when (not kmod-okay?)
662
- (fatal 1 "bridge-mode is 'ovs', but no 'openvswitch' module loaded"))
662
+ [{:keys [info warn]} @ctx
663
+ ovs? (kmod-loaded? "openvswitch")
664
+ bridge-mode (condp = [bridge-mode ovs?]
665
+ [:auto true]
666
+ :ovs
667
+
668
+ [:auto false]
669
+ (do
670
+ (warn (str "bridge-mode is 'auto' but no 'openvswitch' "
671
+ "kernel module loaded, so using 'linux'"))
672
+ :linux)
673
+
674
+ [:ovs false]
675
+ (fatal 1 (str "bridge-mode is 'ovs', but no 'openvswitch' "
676
+ "kernel module loaded"))
677
+
678
+ bridge-mode)
679
+ docker (docker-client docker-socket)
680
+ podman (docker-client podman-socket)]
663
681
  (when (and (not docker) (not podman))
664
- (fatal 1 "Failed to start either docker or podman client/listener"))))
682
+ (fatal 1 "Failed to start either docker or podman client/listener"))
683
+ {:bridge-mode bridge-mode
684
+ :docker docker
685
+ :podman podman}))
665
686
 
666
687
  (defn server
667
688
  "Process:
@@ -691,7 +712,7 @@ General Options:
691
712
  _ (arg-checks opts)
692
713
  _ (info (str "User options:\n" (indent-pprint-str opts " ")))
693
714
 
694
- {:keys [network-file compose-file compose-project bridge-mode]} opts
715
+ {:keys [network-file compose-file compose-project]} opts
695
716
  env (js->clj (js/Object.assign #js {} js/process.env))
696
717
  self-pid js/process.pid
697
718
  schema (load-config (:config-schema opts))
@@ -703,9 +724,7 @@ General Options:
703
724
  (println (js/JSON.stringify (->js network-config)))
704
725
  (js/process.exit 0))
705
726
 
706
- docker (docker-client (:docker-socket opts))
707
- podman (docker-client (:podman-socket opts))
708
- _ (startup-checks bridge-mode docker podman)
727
+ {:keys [bridge-mode docker podman]} (startup-checks opts)
709
728
  self-cid (get-container-id)
710
729
  self-container-obj (when self-cid
711
730
  (get-container (or docker podman) self-cid))