Skip to content

Commit

Permalink
chore: refactor grpc gen and project structure
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
aryan9600 committed Jan 23, 2025
1 parent b24b0a2 commit 70de278
Show file tree
Hide file tree
Showing 13 changed files with 154 additions and 81 deletions.
13 changes: 11 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"dataplane/loader",
"tools/udp-test-server",
"xtask",
"lib/backends",
]
exclude = ["dataplane/ebpf"]

Expand All @@ -16,6 +17,9 @@ license = "Apache-2.0"
repository = "https://github.com/kubernetes-sigs/blixt"
version = "0.3.0"

# this should not include any crates that are linux only. doing so
# will break the controlplane on macOS. this includes crates belonging
# to this workspace that import third party linux only crates.
[workspace.dependencies]
anyhow = { version = "1", default-features = true }
chrono = { version = "0.4.33", default-features = false }
Expand All @@ -41,3 +45,4 @@ tonic-build = { version = "0.11.0", default-features = false }
tonic-health = { version = "0.11.0", default-features = false }
tracing = { version = "0.1.37", default-features = false }
tracing-subscriber = { version = "0.3", default-features = false }
backends = { path = "./lib/backends" }
5 changes: 1 addition & 4 deletions dataplane/api-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ version.workspace = true
[dependencies]
anyhow = { workspace = true }
aya = { version = "0.13.1", features = ["async_tokio"] }
backends = { workspace = true }
clap = { workspace = true, features = ["derive"] }
common = { path = "../common", features = ["user"] }
libc = { workspace = true }
log = { workspace = true }
netlink-packet-core = { version = "0.7.0" }
netlink-packet-route = { version = "0.20.1" }
netlink-sys = { version = "0.8.7" }
prost = { workspace = true }
tokio = { workspace = true, features = [
"macros",
"rt",
Expand All @@ -26,9 +26,6 @@ tokio = { workspace = true, features = [
tonic = { workspace = true, features = ["tls"] }
tonic-health = { workspace = true }

[build-dependencies]
tonic-build = { workspace = true }

[dev-dependencies]
tempfile = "3.14.0"
rcgen = "0.13.2"
3 changes: 1 addition & 2 deletions dataplane/api-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Copyright 2023 The Kubernetes Authors.
SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
*/

pub mod backends;
pub mod config;
pub mod netutils;
pub mod server;
Expand All @@ -19,7 +18,7 @@ use aya::maps::{HashMap, MapData};
use log::info;
use tonic::transport::{Certificate, Identity, Server, ServerTlsConfig};

use backends::backends_server::BackendsServer;
use backends::backends::backends_server::BackendsServer;
use common::{BackendKey, BackendList, ClientKey, LoadBalancerMapping};
use config::TLSConfig;

Expand Down
5 changes: 3 additions & 2 deletions dataplane/api-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ use aya::maps::{HashMap, MapData, MapError};
use tokio::sync::Mutex;
use tonic::{Request, Response, Status};

use crate::backends::backends_server::Backends;
use crate::backends::{Confirmation, InterfaceIndexConfirmation, PodIp, Targets, Vip};
use backends::backends::{Confirmation, InterfaceIndexConfirmation, PodIp, Targets, Vip};

use crate::netutils::if_index_for_routing_ip;
use backends::backends::backends_server::Backends;
use common::{
Backend, BackendKey, BackendList, ClientKey, LoadBalancerMapping, BACKENDS_ARRAY_CAPACITY,
};
Expand Down
14 changes: 14 additions & 0 deletions lib/backends/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "backends"
edition.workspace = true
license.workspace = true
repository.workspace = true
version.workspace = true

[dependencies]
tonic = { workspace = true, features = ["codegen", "prost"] }
prost = { workspace = true }
tonic-build = { workspace = true, features = ["prost"] }

[build-dependencies]
tonic-build = { workspace = true, features = ["prost"] }
11 changes: 11 additions & 0 deletions lib/backends/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fn main() {
let proto_file = "./proto/backends.proto";

println!("building proto {}", proto_file);

tonic_build::configure()
.protoc_arg("--experimental_allow_proto3_optional")
.out_dir("./src")
.compile(&[proto_file], &["."])
.unwrap();
}
File renamed without changes.
Loading

0 comments on commit 70de278

Please sign in to comment.