Skip to content

Commit

Permalink
chore: refactor xtask grpc-client to use controlplane grpc bindings
Browse files Browse the repository at this point in the history
by using the grpc bindings from the controlplane crate instead of the
dataplane api-server crate, we allow for `cargo xtask grpc-client` to
work on macOS (since the datpalane crate is linux only).

Signed-off-by: Sanskar Jaiswal <[email protected]>
  • Loading branch information
aryan9600 committed Jan 19, 2025
1 parent feb7b87 commit e282134
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 8 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ version = "0.3.0"

[workspace.dependencies]
anyhow = { version = "1", default-features = true }
aya = { version = "0.13.1", default-features = false }
chrono = { version = "0.4.33", default-features = false }
clap = { version = "4.5", default-features = true }
env_logger = { version = "0.11", default-features = false }
Expand Down
2 changes: 2 additions & 0 deletions build/Containerfile.dataplane
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ RUN if [ "$TARGETARCH" = "amd64" ]; \
RUN rustup target add $(eval cat arch)-unknown-linux-musl

COPY dataplane dataplane
COPY controlplane controlplane
COPY tools/udp-test-server tools/udp-test-server
COPY xtask xtask
COPY Cargo.toml Cargo.toml
Expand All @@ -57,6 +58,7 @@ RUN --mount=type=cache,target=/workspace/target/ \
RUSTFLAGS=-Ctarget-feature=+crt-static cargo build \
--workspace \
--exclude ebpf \
--package loader \
--release \
--target=$(eval cat arch)-unknown-linux-musl
RUN --mount=type=cache,target=/workspace/target/ \
Expand Down
6 changes: 6 additions & 0 deletions controlplane/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ tracing-subscriber = { workspace = true, features = ["fmt"] }
thiserror = { workspace = true }
anyhow = { workspace = true }
gateway-api = { workspace = true }
tonic = { workspace = true, features = ["tls"] }
tonic-health = { workspace = true }
prost = { workspace = true }

[build-dependencies]
tonic-build = { workspace = true }
1 change: 1 addition & 0 deletions controlplane/src/client/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod backends;
1 change: 1 addition & 0 deletions controlplane/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
use kube::Client;
use thiserror::Error;

pub mod client;
pub mod gateway_controller;
pub mod gateway_utils;

Expand Down
1 change: 1 addition & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ prost = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
tonic = { workspace = true }
tonic-build = { workspace = true, features = ["prost"] }
controlplane = { path = "../controlplane" }

[target.'cfg(target_os = "linux")'.dependencies]
api-server = { path = "../dataplane/api-server" }
8 changes: 5 additions & 3 deletions xtask/src/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use std::str::FromStr;
use anyhow::Error;
use clap::Parser;

use api_server::backends::backends_client::BackendsClient;
use api_server::backends::{Target, Targets, Vip};
use controlplane::client::backends::backends_client::BackendsClient;
use controlplane::client::backends::{Target, Targets, Vip};
use tonic::transport::Endpoint;

#[derive(Debug, Parser)]
pub struct Options {
Expand All @@ -36,7 +37,8 @@ pub struct Options {
pub async fn update(opts: Options) -> Result<(), Error> {
let server_addr: SocketAddr = format!("{}:{}", opts.server_ip, opts.server_port).parse()?;

let mut client = BackendsClient::connect(format!("http://{}", server_addr)).await?;
let conn = Endpoint::new(format!("http://{}", server_addr))?.connect().await?;
let mut client = BackendsClient::new(conn);

let addr = net::Ipv4Addr::from_str(&opts.vip_ip)?;
let daddr = net::Ipv4Addr::from_str(&opts.daddr)?;
Expand Down
6 changes: 2 additions & 4 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
#[cfg(target_os = "linux")]
mod build_ebpf;
mod build_proto;
#[cfg(target_os = "linux")]
mod grpc;
mod run;

Expand All @@ -28,12 +27,11 @@ enum Command {
#[cfg(target_os = "linux")]
BuildEbpf(build_ebpf::Options),
#[cfg(target_os = "linux")]
GrpcClient(grpc::Options),
#[cfg(target_os = "linux")]
RunDataplane(run::Options),

RunControlplane(run::Options),
BuildProto(build_proto::Options),
GrpcClient(grpc::Options),
}

#[tokio::main]
Expand All @@ -45,7 +43,6 @@ async fn main() {
let ret = match opts.command {
BuildEbpf(opts) => build_ebpf::build_ebpf(opts),
BuildProto(opts) => build_proto::build_proto(opts),
#[cfg(target_os = "linux")]
RunDataplane(opts) => run::run_dataplane(opts),
RunControlplane(opts) => run::run_controlplane(opts),
GrpcClient(opts) => grpc::update(opts).await,
Expand All @@ -55,6 +52,7 @@ async fn main() {
let ret = match opts.command {
BuildProto(opts) => build_proto::build_proto(opts),
RunControlplane(opts) => run::run_controlplane(opts),
GrpcClient(opts) => grpc::update(opts).await,
};

if let Err(e) = ret {
Expand Down

0 comments on commit e282134

Please sign in to comment.