k8s_deviceplugin/lib.rs
1//! `k8s-deviceplugin` provides API bindings for Kubernetes device plugins.
2//!
3//! # Example
4//!
5//! ```rust,no_run
6//! use k8s_deviceplugin::v1beta1::registration_client::RegistrationClient;
7//! use k8s_deviceplugin::v1beta1;
8//! use tokio::net::UnixStream;
9//! use std::convert::TryFrom;
10//! use tonic::transport::{Endpoint, Uri};
11//! use tower::service_fn;
12//!
13//! #[tokio::main]
14//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
15//! let channel = Endpoint::try_from("http://[::]:50051")?
16//! .connect_with_connector(service_fn(|_: Uri| {
17//! UnixStream::connect(v1beta1::KUBELET_SOCKET)
18//! }))
19//! .await?;
20//! let mut client = RegistrationClient::new(channel);
21//! let request = tonic::Request::new(v1beta1::RegisterRequest {
22//! endpoint: format!("{}/fpgk8s.sock", v1beta1::KUBELET_SOCKET),
23//! resource_name: "fpgk8s.io/fpga".into(),
24//! version: v1beta1::VERSION.into(),
25//! options: None,
26//! });
27//!
28//! let response = client.register(request).await?;
29//!
30//! println!("RESPONSE={:?}", response);
31//! Ok(())
32//! }
33//! ```
34//!
35
36pub mod v1beta1 {
37 tonic::include_proto!("v1beta1");
38
39 /// Means that the device is healthy.
40 pub const HEALTHY: &str = "Healthy";
41
42 /// Means that the device is unhealthy.
43 pub const UNHEALTHY: &str = "Unhealthy";
44
45 /// Means current version of the API supported by kubelet.
46 pub const VERSION: &str = "v1beta1";
47
48 /// The folder the Device Plugin is expecting sockets to be on. Only
49 /// privileged pods have access to this path. Note: Placeholder until we
50 /// find a "standard path".
51 pub const DEVICE_PLUGIN_PATH: &str = "/var/lib/kubelet/device-plugins/";
52
53 /// The path of the kubelet registry socket.
54 pub const KUBELET_SOCKET: &str = "/var/lib/kubelet/device-plugins/kubelet.sock";
55
56 /// Avoid failed to run kubelet: bad socketPath, must be an absolute path:
57 /// /var/lib/kubelet/device-plugins/kubelet.sock
58 /// https://github.com/kubernetes/kubernetes/issues/93262
59 /// https://github.com/kubernetes/kubernetes/pull/93285#discussion_r458140701
60 pub const DEVICE_PLUGIN_WINDOWS: &str = "\\var\\lib\\kubelet\\device-plugins\\";
61
62 /// The path of the Kubelet registry socket on windows.T
63 pub const KUBELET_SOCKET_WINDOWS: &str = "\\var\\lib\\kubelet\\device-plugins\\kubelet.sock";
64
65 /// Timeout duration in secs for PreStartContainer RPC.
66 pub const KUBELET_PRE_START_CONTAINER_RPC_TIMEOUT_IN_SECS: u64 = 30;
67}
68
69pub mod v1alpha {
70 tonic::include_proto!("deviceplugin");
71
72 /// Means that the device is healthy.
73 pub const HEALTHY: &str = "Healthy";
74
75 /// Means that the device is unhealthy.
76 pub const UNHEALTHY: &str = "Unhealthy";
77
78 /// The folder the Device Plugin is expecting sockets to be on. Only
79 /// privileged pods have access to this path. Note: Placeholder until we
80 /// find a "standard path".
81 pub const DEVICE_PLUGIN_PATH: &str = "/var/lib/kubelet/device-plugins/";
82
83 /// The path of the Kubelet registry socket.
84 pub const KUBELET_SOCKET: &str = "/var/lib/kubelet/device-plugins/kubelet.sock";
85}