Skip to content

Commit 51954b2

Browse files
committed
chore: refactor grpc gen and project structure
introduce a new crate `lib/backends` that contains the protobuf files along with the corresponding rust bindings. this allows flexible usage by both the dataplane and controlplane crates. Signed-off-by: Sanskar Jaiswal <[email protected]>
1 parent b24b0a2 commit 51954b2

File tree

14 files changed

+159
-81
lines changed

14 files changed

+159
-81
lines changed

Cargo.lock

+11-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ members = [
77
"dataplane/loader",
88
"tools/udp-test-server",
99
"xtask",
10+
"lib/backends",
1011
]
1112
exclude = ["dataplane/ebpf"]
1213

@@ -16,6 +17,13 @@ license = "Apache-2.0"
1617
repository = "https://github.com/kubernetes-sigs/blixt"
1718
version = "0.3.0"
1819

20+
# Note: We intend to support running the control-plane on multiple operating systems to enable
21+
# more development and testing from non-Linux systems, even though the dataplane strongly requires
22+
# Linux (due largely to eBPF). This library is utilized by the controlplane, and as such we must
23+
# not include any crates that are linux only. doing so this should not include any crates that are
24+
# linux only. Doing so will break the controlplane on other systems (e.g. MacOS which along with
25+
# Linux is a common development environment for our contributors). This includes crates belonging
26+
# to this workspace that import third party linux only crates.
1927
[workspace.dependencies]
2028
anyhow = { version = "1", default-features = true }
2129
chrono = { version = "0.4.33", default-features = false }
@@ -41,3 +49,4 @@ tonic-build = { version = "0.11.0", default-features = false }
4149
tonic-health = { version = "0.11.0", default-features = false }
4250
tracing = { version = "0.1.37", default-features = false }
4351
tracing-subscriber = { version = "0.3", default-features = false }
52+
backends = { path = "./lib/backends" }

build/Containerfile.dataplane

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ RUN rustup target add $(eval cat arch)-unknown-linux-musl
3535

3636
COPY dataplane dataplane
3737
COPY controlplane controlplane
38+
COPY lib lib
3839
COPY tools/udp-test-server tools/udp-test-server
3940
COPY xtask xtask
4041
COPY Cargo.toml Cargo.toml

dataplane/api-server/Cargo.toml

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ version.workspace = true
88
[dependencies]
99
anyhow = { workspace = true }
1010
aya = { version = "0.13.1", features = ["async_tokio"] }
11+
backends = { workspace = true }
1112
clap = { workspace = true, features = ["derive"] }
1213
common = { path = "../common", features = ["user"] }
1314
libc = { workspace = true }
1415
log = { workspace = true }
1516
netlink-packet-core = { version = "0.7.0" }
1617
netlink-packet-route = { version = "0.20.1" }
1718
netlink-sys = { version = "0.8.7" }
18-
prost = { workspace = true }
1919
tokio = { workspace = true, features = [
2020
"macros",
2121
"rt",
@@ -26,9 +26,6 @@ tokio = { workspace = true, features = [
2626
tonic = { workspace = true, features = ["tls"] }
2727
tonic-health = { workspace = true }
2828

29-
[build-dependencies]
30-
tonic-build = { workspace = true }
31-
3229
[dev-dependencies]
3330
tempfile = "3.14.0"
3431
rcgen = "0.13.2"

dataplane/api-server/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Copyright 2023 The Kubernetes Authors.
44
SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
55
*/
66

7-
pub mod backends;
87
pub mod config;
98
pub mod netutils;
109
pub mod server;
@@ -19,7 +18,7 @@ use aya::maps::{HashMap, MapData};
1918
use log::info;
2019
use tonic::transport::{Certificate, Identity, Server, ServerTlsConfig};
2120

22-
use backends::backends_server::BackendsServer;
21+
use backends::backends::backends_server::BackendsServer;
2322
use common::{BackendKey, BackendList, ClientKey, LoadBalancerMapping};
2423
use config::TLSConfig;
2524

dataplane/api-server/src/server.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ use aya::maps::{HashMap, MapData, MapError};
1212
use tokio::sync::Mutex;
1313
use tonic::{Request, Response, Status};
1414

15-
use crate::backends::backends_server::Backends;
16-
use crate::backends::{Confirmation, InterfaceIndexConfirmation, PodIp, Targets, Vip};
15+
use backends::backends::{Confirmation, InterfaceIndexConfirmation, PodIp, Targets, Vip};
16+
1717
use crate::netutils::if_index_for_routing_ip;
18+
use backends::backends::backends_server::Backends;
1819
use common::{
1920
Backend, BackendKey, BackendList, ClientKey, LoadBalancerMapping, BACKENDS_ARRAY_CAPACITY,
2021
};

lib/backends/Cargo.toml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "backends"
3+
edition.workspace = true
4+
license.workspace = true
5+
repository.workspace = true
6+
version.workspace = true
7+
8+
[dependencies]
9+
tonic = { workspace = true, features = ["codegen", "prost"] }
10+
prost = { workspace = true }
11+
tonic-build = { workspace = true, features = ["prost"] }
12+
13+
[build-dependencies]
14+
tonic-build = { workspace = true, features = ["prost"] }

lib/backends/build.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fn main() {
2+
let proto_file = "./proto/backends.proto";
3+
4+
println!("building proto {}", proto_file);
5+
6+
tonic_build::configure()
7+
.protoc_arg("--experimental_allow_proto3_optional")
8+
.out_dir("./src")
9+
.compile(&[proto_file], &["."])
10+
.unwrap();
11+
}
File renamed without changes.

0 commit comments

Comments
 (0)