Skip to content

Commit 88d7cbb

Browse files
committed
Integration work to get flowctl-go able to invoke flow-firecracker
1 parent b1ebf2b commit 88d7cbb

File tree

11 files changed

+367
-40
lines changed

11 files changed

+367
-40
lines changed

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ mnl = { version = "0.2.2", features = ["mnl-1-0-4"] }
201201

202202
tracing-log = "0.1.3"
203203
which = "4.4.0"
204+
serde_plain = "1.0.1"
204205

205206
[profile.release]
206207
incremental = true

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ WORKDIR = $(realpath .)/.build
5050
# Packaged build outputs.
5151
PKGDIR = ${WORKDIR}/package
5252

53+
ASSETS_PATH = $(realpath .)/assets
54+
5355
# Etcd release we pin within Flow distributions.
5456
ETCD_VERSION = v3.5.5
5557

@@ -165,6 +167,10 @@ ${RUSTBIN}/agent:
165167
${RUSTBIN}/flowctl:
166168
cargo build --release --locked -p flowctl
167169

170+
.PHONY: ${RUSTBIN}/flow-firecracker
171+
${RUSTBIN}/flow-firecracker:
172+
cargo build --release --locked -p task-runtime
173+
168174
# Statically linked binaries using MUSL:
169175

170176
.PHONY: ${RUST_MUSL_BIN}/flow-connector-init
@@ -197,6 +203,8 @@ GNU_TARGETS = \
197203
${PKGDIR}/bin/gazette \
198204
${PKGDIR}/bin/sops \
199205
${PKGDIR}/bin/flowctl \
206+
${PKGDIR}/bin/flow-firecracker \
207+
${PKGDIR}/bin/vmlinux.bin \
200208

201209
MUSL_TARGETS = \
202210
${PKGDIR}/bin/flow-connector-init \
@@ -250,6 +258,12 @@ ${PKGDIR}/bin/flow-schemalate: ${RUST_MUSL_BIN}/flow-schemalate | ${PKGDIR}
250258
${PKGDIR}/bin/flowctl: ${RUSTBIN}/flowctl | ${PKGDIR}
251259
cp ${RUSTBIN}/flowctl $@
252260

261+
${PKGDIR}/bin/flow-firecracker: ${RUSTBIN}/flow-firecracker | ${PKGDIR}
262+
cp ${RUSTBIN}/flow-firecracker $@
263+
264+
${PKGDIR}/bin/vmlinux.bin: ${ASSETS_PATH}/vmlinux.bin | ${PKGDIR}
265+
cp ${ASSETS_PATH}/vmlinux.bin $@
266+
253267
# Control-plane binaries
254268

255269
${PKGDIR}/bin/agent: ${RUSTBIN}/agent | ${PKGDIR}

assets/vmlinux.bin

47.7 MB
Binary file not shown.

crates/task-runtime/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ repository.workspace = true
99
license.workspace = true
1010

1111
[[bin]]
12-
name = "test-firecracker"
12+
name = "flow-firecracker"
1313
path = "src/main.rs"
1414

1515
[dependencies]
1616
connector-init = { path = "../connector-init" }
17+
ops = { path = "../ops" }
1718

1819
cmd_lib = { workspace = true }
1920
uuid = { workspace = true }
2021
tempfile = { workspace = true }
2122

23+
time = { workspace = true }
2224
async-trait = { workspace = true }
2325
firec = { workspace = true }
2426
bollard = { workspace = true }
@@ -36,6 +38,7 @@ clap = { workspace = true }
3638
which = { workspace = true }
3739
lazy_static = { workspace = true }
3840
fancy-regex = { workspace = true }
41+
serde_plain = { workspace = true }
3942

4043
#-- Prune:
4144
anyhow = { workspace = true }

crates/task-runtime/src/cni.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use std::str::FromStr;
1+
use core::fmt;
2+
use std::{fmt::Display, str::FromStr};
23

3-
use anyhow::Context;
4+
use anyhow::{anyhow, Context};
45
use fancy_regex::Regex;
56
use serde::{Deserialize, Serialize};
67

@@ -32,6 +33,14 @@ pub enum PortMappingProtocol {
3233
TCP,
3334
UDP,
3435
}
36+
37+
impl fmt::Display for PortMappingProtocol {
38+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39+
let val = serde_plain::to_string(self).unwrap_or("unknown".to_owned());
40+
write!(f, "{}", val)
41+
}
42+
}
43+
3544
#[derive(Serialize, Deserialize, Debug, Clone)]
3645
#[serde(rename_all = "camelCase")]
3746
pub struct PortMapping {
@@ -41,7 +50,7 @@ pub struct PortMapping {
4150
}
4251

4352
lazy_static::lazy_static! {
44-
static ref PORT_RE: Regex = Regex::new(r"^([0-9]{1,5}):([0-9]{1,5})(/(tcp|udp))?$").unwrap();
53+
static ref PORT_RE: Regex = Regex::new(r"^([0-9]{1,5}):([0-9]{1,5})(/(\w+))?$").unwrap();
4554
}
4655

4756
impl FromStr for PortMapping {
@@ -68,11 +77,8 @@ impl FromStr for PortMapping {
6877
.as_str()
6978
.parse::<usize>()?;
7079
let protocol = capture_groups
71-
.get(3)
72-
.map(|proto| {
73-
let val = proto.as_str();
74-
serde_json::de::from_str::<PortMappingProtocol>(&format!(r#""{val}""#))
75-
})
80+
.get(4)
81+
.map(|proto| serde_plain::from_str(proto.as_str()))
7682
.unwrap_or(Ok(PortMappingProtocol::TCP))?;
7783

7884
Ok(Self {

crates/task-runtime/src/firecracker.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::{
1010
path::{Path, PathBuf},
1111
};
1212
use tokio::runtime::Handle;
13-
use tracing::{debug, error};
13+
use tracing::{debug, error, info};
1414
use uuid::Uuid;
1515

1616
use crate::cni::PortMapping;
@@ -36,8 +36,8 @@ pub fn setup_init_fs(
3636

3737
run_cmd!(
3838
cd $temp_dir;
39-
fallocate -l 64M initfs;
40-
mkfs.ext2 initfs;
39+
dd if=/dev/zero of=initfs bs=512 count=125000;
40+
mkfs.ext2 -q initfs;
4141
mkdir initmount;
4242
mount -o loop,noatime initfs initmount;
4343
chown $user:$user initmount;
@@ -234,6 +234,15 @@ impl FirecrackerNetworking {
234234
let plugins_path = self.cni_plugins_path.clone();
235235

236236
let cni_response = if self.port_mappings.len() > 0 {
237+
for PortMapping {
238+
protocol,
239+
host_port,
240+
container_port,
241+
} in self.port_mappings.iter()
242+
{
243+
info!("Binding host {protocol} port {host_port} to guest port {container_port} ")
244+
}
245+
237246
let capability_args_val =
238247
serde_json::to_string(&json!({"portMappings": self.port_mappings}))
239248
.context("Serializing port mappings")?;

0 commit comments

Comments
 (0)