conlink 2.1.0 → 2.4.0
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.
- package/.github/workflows/push.yml +3 -3
- package/Dockerfile +2 -2
- package/README.md +278 -25
- package/examples/test10-compose.yaml +49 -0
- package/examples/test7-compose.yaml +10 -2
- package/examples/test9-compose.yaml +8 -3
- package/link-add.sh +21 -14
- package/link-forward.sh +46 -0
- package/link-mirred.sh +8 -29
- package/mdc +38 -25
- package/net2dot.cljs +3 -3
- package/package.json +3 -2
- package/schema.yaml +13 -3
- package/scripts/copy.sh +3 -2
- package/scripts/wait.sh +1 -1
- package/src/conlink/core.cljs +198 -84
- package/src/conlink/util.cljs +1 -1
- package/test/test1.yaml +26 -0
- package/test/test10.yaml +46 -0
- package/test/test2.yaml +37 -0
- package/test/test4.yaml +80 -0
- package/test/test7.yaml +34 -0
- package/test/test9.yaml +110 -0
- package/run-tests.sh +0 -191
package/link-mirred.sh
CHANGED
|
@@ -34,41 +34,20 @@ die() { warn "ERROR: ${*}"; exit 1; }
|
|
|
34
34
|
add_ingress() {
|
|
35
35
|
local IF=$1 res=
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
info "${IF0} already has ingress qdisc"
|
|
41
|
-
;;
|
|
42
|
-
""|*"qdisc noqueue"*)
|
|
43
|
-
info "Adding ingress qdisc to ${IF}"
|
|
44
|
-
tc qdisc add dev "${IF}" ingress \
|
|
45
|
-
|| die "Could not add ingress qdisc to ${IF}"
|
|
46
|
-
;;
|
|
47
|
-
*)
|
|
48
|
-
die "${IF} has invalid ingress qdisc or could not be queried"
|
|
49
|
-
;;
|
|
50
|
-
esac
|
|
37
|
+
info "Adding ingress qdisc to ${IF}"
|
|
38
|
+
tc qdisc replace dev "${IF}" ingress \
|
|
39
|
+
|| die "Could not add ingress qdisc to ${IF}"
|
|
51
40
|
}
|
|
52
41
|
|
|
53
42
|
# Idempotently add mirred filter redirect rule to an interface
|
|
54
43
|
add_mirred() {
|
|
55
44
|
local IF0=$1 IF1=$2 res=
|
|
56
45
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"")
|
|
63
|
-
info "Adding filter redirect action from ${IF0} to ${IF1}"
|
|
64
|
-
tc filter add dev ${IF0} parent ffff: protocol all u32 match u8 0 0 action \
|
|
65
|
-
mirred egress redirect dev ${IF1} \
|
|
66
|
-
|| die "Could not add filter redirect action from ${IF0} to ${IF1}"
|
|
67
|
-
;;
|
|
68
|
-
*)
|
|
69
|
-
die "${IF0} has invalid filter redirect action or could not be queried"
|
|
70
|
-
;;
|
|
71
|
-
esac
|
|
46
|
+
info "Adding filter redirect action from ${IF0} to ${IF1}"
|
|
47
|
+
tc filter del dev ${IF0} root
|
|
48
|
+
tc filter replace dev ${IF0} parent ffff: protocol all u32 match u8 0 0 action \
|
|
49
|
+
mirred egress redirect dev ${IF1} \
|
|
50
|
+
|| die "Could not add filter redirect action from ${IF0} to ${IF1}"
|
|
72
51
|
}
|
|
73
52
|
|
|
74
53
|
# Parse arguments
|
package/mdc
CHANGED
|
@@ -17,21 +17,18 @@ LS=$(which ls)
|
|
|
17
17
|
RESOLVE_DEPS="${RESOLVE_DEPS-./node_modules/@lonocloud/resolve-deps/resolve-deps.py}"
|
|
18
18
|
DOCKER_COMPOSE="${DOCKER_COMPOSE:-docker-compose}"
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
which ${RESOLVE_DEPS} >/dev/null 2>/dev/null \
|
|
21
|
+
|| die "Missing ${RESOLVE_DEPS}. Perhaps 'npm install'?"
|
|
22
|
+
|
|
23
|
+
# Resolve mode directory paths
|
|
24
|
+
|
|
21
25
|
MODE_SPEC="${1}"; shift
|
|
22
|
-
|
|
23
|
-
MODES="$(${RESOLVE_DEPS} "${MODES_DIR}" ${MODE_SPEC})"
|
|
24
|
-
else
|
|
25
|
-
MODES="${MODE_SPEC//,/ }"
|
|
26
|
-
fi
|
|
26
|
+
RESOLVED_MODES="$(${RESOLVE_DEPS} --path "${MODES_DIR}" --format=paths ${MODE_SPEC})"
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
# Create base (empty) compose file to anchor mode relative paths
|
|
29
|
+
# to the same root directory. Create files dir.
|
|
30
30
|
|
|
31
|
-
declare -A FINISHED
|
|
32
31
|
COMPOSE_FILE=./.compose-empty.yaml
|
|
33
|
-
COMPOSE_PROFILES=
|
|
34
|
-
MDC_MODE_DIRS=
|
|
35
32
|
cat /dev/null > ${ENV_FILE}-mdc-tmp
|
|
36
33
|
echo -e "version: '2.4'\nservices: {}" > ./.compose-empty.yaml
|
|
37
34
|
|
|
@@ -42,19 +39,25 @@ esac
|
|
|
42
39
|
[ -d "${MDC_FILES_DIR}" ] && rm -r${VERBOSE:+v} ${MDC_FILES_DIR}/
|
|
43
40
|
mkdir -p "${MDC_FILES_DIR}"
|
|
44
41
|
|
|
45
|
-
|
|
42
|
+
# Incorporate modes' compose config, env, and files
|
|
43
|
+
|
|
44
|
+
declare -A FINISHED
|
|
45
|
+
COMPOSE_PROFILES=
|
|
46
|
+
MDC_MODE_NAMES=
|
|
47
|
+
MDC_MODE_DIRS=
|
|
48
|
+
for resolved in ${RESOLVED_MODES}; do
|
|
49
|
+
mode=${resolved%=*}
|
|
50
|
+
path=${resolved#*=}
|
|
51
|
+
|
|
46
52
|
# Only process each mode once
|
|
47
53
|
[ "${FINISHED[${mode}]}" ] && continue
|
|
48
54
|
FINISHED["${mode}"]=1
|
|
49
55
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
die "No mode dir found for ${mode}"
|
|
53
|
-
|
|
54
|
-
MDC_MODE_DIRS="${MDC_MODE_DIRS},${MODES_DIR}/${mode}"
|
|
56
|
+
MDC_MODE_NAMES="${MDC_MODE_NAMES} ${mode}"
|
|
57
|
+
MDC_MODE_DIRS="${MDC_MODE_DIRS},${path}"
|
|
55
58
|
|
|
56
59
|
# mode can refer to a compose file in multiple ways
|
|
57
|
-
cfiles="${
|
|
60
|
+
cfiles="${path}/compose.yaml ${path}/compose.yml ${path}/docker-compose.yaml ${path}/docker-compose.yml"
|
|
58
61
|
for cfile in ${cfiles}; do
|
|
59
62
|
if [ -e "${cfile}" ]; then
|
|
60
63
|
COMPOSE_FILE="${COMPOSE_FILE}:${cfile}"
|
|
@@ -66,27 +69,35 @@ for mode in ${MODES}; do
|
|
|
66
69
|
COMPOSE_PROFILES="${COMPOSE_PROFILES},MODE_${mode}"
|
|
67
70
|
|
|
68
71
|
# if there is a mode specific env file then include it
|
|
69
|
-
efiles="${
|
|
72
|
+
efiles="${path}/env ${path}/.env"
|
|
70
73
|
for efile in ${efiles}; do
|
|
71
74
|
if [ -e "${efile}" ]; then
|
|
72
|
-
echo "### mdc begin mode ${mode}" >> ${ENV_FILE}-mdc-tmp
|
|
75
|
+
echo "### mdc begin mode ${mode} (${efile})" >> ${ENV_FILE}-mdc-tmp
|
|
73
76
|
vecho "cat ${efile} >> ${ENV_FILE}-mdc-tmp"
|
|
74
77
|
cat ${efile} >> ${ENV_FILE}-mdc-tmp
|
|
75
|
-
echo
|
|
78
|
+
echo >> ${ENV_FILE}-mdc-tmp
|
|
79
|
+
echo "### mdc end mode ${mode} (${efile})" >> ${ENV_FILE}-mdc-tmp
|
|
76
80
|
fi
|
|
77
81
|
done
|
|
78
82
|
|
|
79
83
|
# if there are mode specific files then copy them to MDC_FILES_DIR
|
|
80
|
-
if [ -d "${
|
|
81
|
-
for vfd in $(cd ${
|
|
84
|
+
if [ -d "${path}" ]; then
|
|
85
|
+
for vfd in $(cd ${path} && $LS -d */files 2>/dev/null || true); do
|
|
82
86
|
dest=${MDC_FILES_DIR}/${vfd%/files}
|
|
83
87
|
mkdir -p ${dest}
|
|
84
|
-
vecho cp -a ${
|
|
85
|
-
cp -a ${
|
|
88
|
+
vecho cp -a ${path}/${vfd}/* ${dest}
|
|
89
|
+
cp -a ${path}/${vfd}/* ${dest}
|
|
86
90
|
done
|
|
87
91
|
fi
|
|
88
92
|
done
|
|
89
93
|
|
|
94
|
+
vecho
|
|
95
|
+
|
|
96
|
+
# Summarize and set env
|
|
97
|
+
|
|
98
|
+
echo >&2 "MODES: ${MDC_MODE_NAMES}"
|
|
99
|
+
vecho "ENV_FILE: ${ENV_FILE}"
|
|
100
|
+
|
|
90
101
|
COMPOSE_FILE="${COMPOSE_FILE#:}"
|
|
91
102
|
vecho "COMPOSE_FILE: ${COMPOSE_FILE}"
|
|
92
103
|
echo "COMPOSE_FILE=${COMPOSE_FILE}" >> ${ENV_FILE}-mdc-tmp
|
|
@@ -100,6 +111,8 @@ MDC_MODE_DIRS="${MDC_MODE_DIRS#,}"
|
|
|
100
111
|
vecho "MDC_MODE_DIRS: ${MDC_MODE_DIRS}"
|
|
101
112
|
echo "MDC_MODE_DIRS=\"${MDC_MODE_DIRS}\"" >> ${ENV_FILE}-mdc-tmp
|
|
102
113
|
|
|
114
|
+
vecho
|
|
115
|
+
|
|
103
116
|
vecho mv ${ENV_FILE}-mdc-tmp ${ENV_FILE}
|
|
104
117
|
mv ${ENV_FILE}-mdc-tmp ${ENV_FILE}
|
|
105
118
|
|
package/net2dot.cljs
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
(S/replace #"[*]" "_STAR_")
|
|
30
30
|
(S/replace #"[$]" "_DOLLAR_")
|
|
31
31
|
(S/replace #"[{]" "_LCURLY_")
|
|
32
|
-
(S/replace #"[}]" "
|
|
32
|
+
(S/replace #"[}]" "_RCURLY_")
|
|
33
33
|
(S/replace #"[ ]" "_SPACE_")))
|
|
34
34
|
|
|
35
35
|
(defn node-props [label props]
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
#(->> (subgraph conlink (str "cluster_bridge_" %2)
|
|
62
62
|
%2 BRIDGE-PROPS)
|
|
63
63
|
(assoc %1 %2))
|
|
64
|
-
{} (keep :bridge (:links network-config)))
|
|
64
|
+
{} (map :bridge (keep :bridge (:links network-config))))
|
|
65
65
|
services (reduce
|
|
66
66
|
#(->> (subgraph host (str "cluster_service_" (dot-id %2))
|
|
67
67
|
(str "service '" (name %2) "'") SVC-PROPS)
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"-" (name dev)))
|
|
86
86
|
out-id (str "out-" outer-dev)
|
|
87
87
|
out-parent (condp = (keyword base)
|
|
88
|
-
:conlink (get bridges bridge)
|
|
88
|
+
:conlink (get bridges (:bridge bridge))
|
|
89
89
|
:host host)
|
|
90
90
|
{:keys [type vlanid]} link
|
|
91
91
|
[elabel iprops] (if (= "host" base)
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "conlink",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
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",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@lonocloud/resolve-deps": "^0.0
|
|
8
|
+
"@lonocloud/resolve-deps": "^0.1.0",
|
|
9
9
|
"ajv": "^8.12.0",
|
|
10
10
|
"dockerode": "^3.3.4",
|
|
11
11
|
"nbb": "^1.2.179",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"yaml": "^2.2.1"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
+
"@lonocloud/dctest": "0.1.1",
|
|
17
18
|
"shadow-cljs": "^2.25.7",
|
|
18
19
|
"source-map-support": "^0.5.21"
|
|
19
20
|
}
|
package/schema.yaml
CHANGED
|
@@ -3,6 +3,7 @@ $defs:
|
|
|
3
3
|
ip: {type: string, pattern: "^([0-9]{1,3}[.]){3}[0-9]+$"}
|
|
4
4
|
mac: {type: string, pattern: "^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$"}
|
|
5
5
|
intf: {type: string, pattern: "^.{1,15}$"}
|
|
6
|
+
fwd: {type: string, pattern: "^[0-9]{1,5}:[0-9]{1,5}/(tcp|udp)$"}
|
|
6
7
|
|
|
7
8
|
type: object
|
|
8
9
|
additionalProperties: false
|
|
@@ -40,11 +41,18 @@ properties:
|
|
|
40
41
|
ip: { "$ref": "#/$defs/cidr" }
|
|
41
42
|
mac: { "$ref": "#/$defs/mac" }
|
|
42
43
|
mtu: {type: number}
|
|
43
|
-
route: {type: string}
|
|
44
44
|
nat: { "$ref": "#/$defs/ip" }
|
|
45
|
-
netem: {type: string}
|
|
46
45
|
mode: {type: string}
|
|
47
46
|
vlanid: {type: number}
|
|
47
|
+
route:
|
|
48
|
+
oneOf: [{type: string},
|
|
49
|
+
{type: array, items: {type: string}}]
|
|
50
|
+
forward:
|
|
51
|
+
oneOf: [{ "$ref": "#/$defs/fwd" },
|
|
52
|
+
{type: array, items: { "$ref": "#/$defs/fwd" }}]
|
|
53
|
+
netem:
|
|
54
|
+
oneOf: [{type: string},
|
|
55
|
+
{type: array, items: {type: string}}]
|
|
48
56
|
|
|
49
57
|
bridges:
|
|
50
58
|
type: array
|
|
@@ -63,7 +71,9 @@ properties:
|
|
|
63
71
|
bridge: {type: string}
|
|
64
72
|
remote: { "$ref": "#/$defs/ip" }
|
|
65
73
|
vni: {type: number}
|
|
66
|
-
netem:
|
|
74
|
+
netem:
|
|
75
|
+
oneOf: [{type: string},
|
|
76
|
+
{type: array, items: {type: string}}]
|
|
67
77
|
|
|
68
78
|
commands:
|
|
69
79
|
type: array
|
package/scripts/copy.sh
CHANGED
package/scripts/wait.sh
CHANGED