Skip to content

Commit 99c8658

Browse files
committed
Bootstrap deviceplugin implementation
Adds an initial deviceplugin implementation based on the k8s-deviceplugin crate. Signed-off-by: hasheddan <[email protected]>
1 parent e043a58 commit 99c8658

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

plugin/Cargo.toml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "plugin"
3+
version = "0.1.0"
4+
authors = ["hasheddan <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
k8s-deviceplugin = { path = "../k8s-deviceplugin" }
11+
tonic = "0.4"
12+
prost = "0.7"
13+
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
14+
tower = { version = "0.4" }

plugin/src/main.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use k8s_deviceplugin::v1beta1::registration_client::RegistrationClient;
2+
use k8s_deviceplugin::v1beta1;
3+
use tokio::net::UnixStream;
4+
use std::convert::TryFrom;
5+
use tonic::transport::{Endpoint, Uri};
6+
use tower::service_fn;
7+
8+
#[tokio::main]
9+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
10+
let channel = Endpoint::try_from("http://[::]:50051")?
11+
.connect_with_connector(service_fn(|_: Uri| {
12+
UnixStream::connect(v1beta1::KUBELET_SOCKET)
13+
}))
14+
.await?;
15+
let mut client = RegistrationClient::new(channel);
16+
let request = tonic::Request::new(v1beta1::RegisterRequest {
17+
endpoint: format!("{}/fpgk8s.sock", v1beta1::KUBELET_SOCKET),
18+
resource_name: "fpgk8s.io/fpga".into(),
19+
version: v1beta1::VERSION.into(),
20+
options: None,
21+
});
22+
23+
let response = client.register(request).await?;
24+
25+
println!("RESPONSE={:?}", response);
26+
Ok(())
27+
}

0 commit comments

Comments
 (0)