From 2cce410f1d9788aadf5fa979fbe49f19897205bb Mon Sep 17 00:00:00 2001 From: Marcel Bindseil Date: Fri, 17 Jan 2025 16:42:57 +0100 Subject: [PATCH 01/19] added configuring of device mount permissions in udev discovery handler #726 Signed-off-by: Marcel Bindseil --- deployment/helm/templates/udev-configuration.yaml | 1 + deployment/helm/values.yaml | 3 +++ discovery-handlers/udev/src/discovery_handler.rs | 9 +++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/deployment/helm/templates/udev-configuration.yaml b/deployment/helm/templates/udev-configuration.yaml index aecb505fb..8dc4da7af 100644 --- a/deployment/helm/templates/udev-configuration.yaml +++ b/deployment/helm/templates/udev-configuration.yaml @@ -10,6 +10,7 @@ spec: groupRecursive: {{ .Values.udev.configuration.discoveryDetails.groupRecursive }} udevRules: {{- required "Please set at least one udev rule with `--set udev.configuration.discoveryDetails.udevRules[0]==\"\"' to specify what you want discovered. See the udev Configuration document at https://docs.akri.sh/discovery-handlers/udev for more information." .Values.udev.configuration.discoveryDetails.udevRules | toYaml | nindent 6 }} + permissions: {{ .Values.udev.configuration.discoveryDetails.permissions }} {{- if or .Values.udev.configuration.brokerPod.image.repository .Values.udev.configuration.brokerJob.image.repository }} {{- /* Only add brokerSpec if a broker image is provided */}} brokerSpec: diff --git a/deployment/helm/values.yaml b/deployment/helm/values.yaml index 34a9d176d..ab40298d6 100644 --- a/deployment/helm/values.yaml +++ b/deployment/helm/values.yaml @@ -714,6 +714,9 @@ udev: # udevRules is the list of udev rules used to find instances created as a result of # applying this udev configuration udevRules: + # permissions is the list of Cgroups permissions of the device + # combination of r (read), w (write), m (modify) + permissions: rwm # capacity is the capacity for any instances created as a result of # applying this udev configuration capacity: 1 diff --git a/discovery-handlers/udev/src/discovery_handler.rs b/discovery-handlers/udev/src/discovery_handler.rs index 343a0343a..13b35faae 100644 --- a/discovery-handlers/udev/src/discovery_handler.rs +++ b/discovery-handlers/udev/src/discovery_handler.rs @@ -30,6 +30,9 @@ pub struct UdevDiscoveryDetails { #[serde(default)] pub group_recursive: bool, + + #[serde(default = "rwm")] + pub permissions: String, } /// `DiscoveryHandlerImpl` discovers udev instances by parsing the udev rules in `discovery_handler_config.udev_rules`. @@ -105,7 +108,7 @@ impl DiscoveryHandler for DiscoveryHandlerImpl { device_specs.push(DeviceSpec { container_path: devnode.clone(), host_path: devnode, - permissions: "rwm".to_string(), + permissions: discovery_handler_config.permissions.clone(), }) } } @@ -178,7 +181,7 @@ mod tests { let udev_dh_config: UdevDiscoveryDetails = deserialize_discovery_details(yaml).unwrap(); assert!(udev_dh_config.udev_rules.is_empty()); let serialized = serde_json::to_string(&udev_dh_config).unwrap(); - let expected_deserialized = r#"{"udevRules":[],"groupRecursive":false}"#; + let expected_deserialized = r#"{"udevRules":[],"groupRecursive":false,"permissions":"rwm"}"#; assert_eq!(expected_deserialized, serialized); } @@ -187,9 +190,11 @@ mod tests { let yaml = r#" udevRules: - 'KERNEL=="video[0-9]*"' + permissions: rwm "#; let udev_dh_config: UdevDiscoveryDetails = deserialize_discovery_details(yaml).unwrap(); assert_eq!(udev_dh_config.udev_rules.len(), 1); assert_eq!(&udev_dh_config.udev_rules[0], "KERNEL==\"video[0-9]*\""); + assert_eq!(&udev_dh_config.permissions, "rwm"); } } From 22793c10bff280ec6e1fa0eb0c55a9cc8bb2ce06 Mon Sep 17 00:00:00 2001 From: Marcel Bindseil Date: Fri, 17 Jan 2025 16:54:52 +0100 Subject: [PATCH 02/19] incremented version Signed-off-by: Marcel Bindseil --- Cargo.lock | 28 +- Cargo.toml | 2 +- agent/src/plugin_manager/v1.rs | 131 ++++--- agent/src/plugin_manager/v1beta1.rs | 361 ++++++++++++------ discovery-utils/src/discovery/v0.rs | 176 +++++---- .../udev-video-broker/src/util/camera.rs | 63 +-- 6 files changed, 488 insertions(+), 273 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a519ce241..68bddb20f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -224,7 +224,7 @@ checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" [[package]] name = "agent" -version = "0.13.9" +version = "0.13.10" dependencies = [ "akri-debug-echo", "akri-discovery-utils", @@ -288,7 +288,7 @@ dependencies = [ [[package]] name = "akri-debug-echo" -version = "0.13.9" +version = "0.13.10" dependencies = [ "akri-discovery-utils", "akri-shared", @@ -306,7 +306,7 @@ dependencies = [ [[package]] name = "akri-discovery-utils" -version = "0.13.9" +version = "0.13.10" dependencies = [ "akri-shared", "anyhow", @@ -328,7 +328,7 @@ dependencies = [ [[package]] name = "akri-onvif" -version = "0.13.9" +version = "0.13.10" dependencies = [ "akri-discovery-utils", "anyhow", @@ -357,7 +357,7 @@ dependencies = [ [[package]] name = "akri-opcua" -version = "0.13.9" +version = "0.13.10" dependencies = [ "akri-discovery-utils", "anyhow", @@ -377,7 +377,7 @@ dependencies = [ [[package]] name = "akri-shared" -version = "0.13.9" +version = "0.13.10" dependencies = [ "anyhow", "async-trait", @@ -402,7 +402,7 @@ dependencies = [ [[package]] name = "akri-udev" -version = "0.13.9" +version = "0.13.10" dependencies = [ "akri-discovery-utils", "anyhow", @@ -935,7 +935,7 @@ dependencies = [ [[package]] name = "controller" -version = "0.13.9" +version = "0.13.10" dependencies = [ "akri-shared", "anyhow", @@ -1109,7 +1109,7 @@ checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" [[package]] name = "debug-echo-discovery-handler" -version = "0.13.9" +version = "0.13.10" dependencies = [ "akri-debug-echo", "akri-discovery-utils", @@ -2508,7 +2508,7 @@ checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "onvif-discovery-handler" -version = "0.13.9" +version = "0.13.10" dependencies = [ "akri-discovery-utils", "akri-onvif", @@ -2557,7 +2557,7 @@ dependencies = [ [[package]] name = "opcua-discovery-handler" -version = "0.13.9" +version = "0.13.10" dependencies = [ "akri-discovery-utils", "akri-opcua", @@ -4055,7 +4055,7 @@ dependencies = [ [[package]] name = "udev-discovery-handler" -version = "0.13.9" +version = "0.13.10" dependencies = [ "akri-discovery-utils", "akri-udev", @@ -4066,7 +4066,7 @@ dependencies = [ [[package]] name = "udev-video-broker" -version = "0.13.9" +version = "0.13.10" dependencies = [ "akri-shared", "env_logger", @@ -4331,7 +4331,7 @@ dependencies = [ [[package]] name = "webhook-configuration" -version = "0.13.9" +version = "0.13.10" dependencies = [ "actix-rt", "actix-web", diff --git a/Cargo.toml b/Cargo.toml index 0e0697c11..d8f4f7492 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ members = [ resolver = "2" [workspace.package] -version = "0.13.9" +version = "0.13.10" edition = "2021" license = "Apache-2.0" homepage = "https://docs.akri.sh/" diff --git a/agent/src/plugin_manager/v1.rs b/agent/src/plugin_manager/v1.rs index 7f3183f3f..f016fb20b 100644 --- a/agent/src/plugin_manager/v1.rs +++ b/agent/src/plugin_manager/v1.rs @@ -87,8 +87,8 @@ pub struct NumaNode { /// Generated client implementations. pub mod pod_resources_lister_client { #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] - use tonic::codegen::http::Uri; use tonic::codegen::*; + use tonic::codegen::http::Uri; /// PodResourcesLister is a service provided by the kubelet that provides information about the /// node resources consumed by pods and containers on the node #[derive(Debug, Clone)] @@ -134,8 +134,9 @@ pub mod pod_resources_lister_client { >::ResponseBody, >, >, - >>::Error: - Into + Send + Sync, + , + >>::Error: Into + Send + Sync, { PodResourcesListerClient::new(InterceptedService::new(inner, interceptor)) } @@ -173,16 +174,23 @@ pub mod pod_resources_lister_client { pub async fn list( &mut self, request: impl tonic::IntoRequest, - ) -> std::result::Result, tonic::Status> - { - self.inner.ready().await.map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); - let path = http::uri::PathAndQuery::from_static("/v1.PodResourcesLister/List"); + let path = http::uri::PathAndQuery::from_static( + "/v1.PodResourcesLister/List", + ); let mut req = request.into_request(); req.extensions_mut() .insert(GrpcMethod::new("v1.PodResourcesLister", "List")); @@ -191,23 +199,28 @@ pub mod pod_resources_lister_client { pub async fn get_allocatable_resources( &mut self, request: impl tonic::IntoRequest, - ) -> std::result::Result, tonic::Status> - { - self.inner.ready().await.map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); let path = http::uri::PathAndQuery::from_static( "/v1.PodResourcesLister/GetAllocatableResources", ); let mut req = request.into_request(); - req.extensions_mut().insert(GrpcMethod::new( - "v1.PodResourcesLister", - "GetAllocatableResources", - )); + req.extensions_mut() + .insert( + GrpcMethod::new("v1.PodResourcesLister", "GetAllocatableResources"), + ); self.inner.unary(req, path, codec).await } } @@ -222,11 +235,17 @@ pub mod pod_resources_lister_server { async fn list( &self, request: tonic::Request, - ) -> std::result::Result, tonic::Status>; + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; async fn get_allocatable_resources( &self, request: tonic::Request, - ) -> std::result::Result, tonic::Status>; + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; } /// PodResourcesLister is a service provided by the kubelet that provides information about the /// node resources consumed by pods and containers on the node @@ -253,7 +272,10 @@ pub mod pod_resources_lister_server { max_encoding_message_size: None, } } - pub fn with_interceptor(inner: T, interceptor: F) -> InterceptedService + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> InterceptedService where F: tonic::service::Interceptor, { @@ -309,11 +331,15 @@ pub mod pod_resources_lister_server { "/v1.PodResourcesLister/List" => { #[allow(non_camel_case_types)] struct ListSvc(pub Arc); - impl - tonic::server::UnaryService for ListSvc - { + impl< + T: PodResourcesLister, + > tonic::server::UnaryService + for ListSvc { type Response = super::ListPodResourcesResponse; - type Future = BoxFuture, tonic::Status>; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; fn call( &mut self, request: tonic::Request, @@ -351,12 +377,15 @@ pub mod pod_resources_lister_server { "/v1.PodResourcesLister/GetAllocatableResources" => { #[allow(non_camel_case_types)] struct GetAllocatableResourcesSvc(pub Arc); - impl - tonic::server::UnaryService - for GetAllocatableResourcesSvc - { + impl< + T: PodResourcesLister, + > tonic::server::UnaryService + for GetAllocatableResourcesSvc { type Response = super::AllocatableResourcesResponse; - type Future = BoxFuture, tonic::Status>; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; fn call( &mut self, request: tonic::Request, @@ -364,9 +393,10 @@ pub mod pod_resources_lister_server { let inner = Arc::clone(&self.0); let fut = async move { ::get_allocatable_resources( - &inner, request, - ) - .await + &inner, + request, + ) + .await }; Box::pin(fut) } @@ -394,14 +424,18 @@ pub mod pod_resources_lister_server { }; Box::pin(fut) } - _ => Box::pin(async move { - Ok(http::Response::builder() - .status(200) - .header("grpc-status", "12") - .header("content-type", "application/grpc") - .body(empty_body()) - .unwrap()) - }), + _ => { + Box::pin(async move { + Ok( + http::Response::builder() + .status(200) + .header("grpc-status", "12") + .header("content-type", "application/grpc") + .body(empty_body()) + .unwrap(), + ) + }) + } } } } @@ -427,7 +461,8 @@ pub mod pod_resources_lister_server { write!(f, "{:?}", self.0) } } - impl tonic::server::NamedService for PodResourcesListerServer { + impl tonic::server::NamedService + for PodResourcesListerServer { const NAME: &'static str = "v1.PodResourcesLister"; } } diff --git a/agent/src/plugin_manager/v1beta1.rs b/agent/src/plugin_manager/v1beta1.rs index a88570f4d..7b068ecab 100644 --- a/agent/src/plugin_manager/v1beta1.rs +++ b/agent/src/plugin_manager/v1beta1.rs @@ -96,7 +96,9 @@ pub struct PreStartContainerResponse {} #[derive(Clone, PartialEq, ::prost::Message)] pub struct PreferredAllocationRequest { #[prost(message, repeated, tag = "1")] - pub container_requests: ::prost::alloc::vec::Vec, + pub container_requests: ::prost::alloc::vec::Vec< + ContainerPreferredAllocationRequest, + >, } #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] @@ -106,7 +108,9 @@ pub struct ContainerPreferredAllocationRequest { pub available_device_i_ds: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, /// List of deviceIDs that must be included in the preferred allocation #[prost(string, repeated, tag = "2")] - pub must_include_device_i_ds: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, + pub must_include_device_i_ds: ::prost::alloc::vec::Vec< + ::prost::alloc::string::String, + >, /// Number of devices to include in the preferred allocation #[prost(int32, tag = "3")] pub allocation_size: i32, @@ -117,7 +121,9 @@ pub struct ContainerPreferredAllocationRequest { #[derive(Clone, PartialEq, ::prost::Message)] pub struct PreferredAllocationResponse { #[prost(message, repeated, tag = "1")] - pub container_responses: ::prost::alloc::vec::Vec, + pub container_responses: ::prost::alloc::vec::Vec< + ContainerPreferredAllocationResponse, + >, } #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] @@ -162,8 +168,10 @@ pub struct AllocateResponse { pub struct ContainerAllocateResponse { /// List of environment variable to be set in the container to access one of more devices. #[prost(map = "string, string", tag = "1")] - pub envs: - ::std::collections::HashMap<::prost::alloc::string::String, ::prost::alloc::string::String>, + pub envs: ::std::collections::HashMap< + ::prost::alloc::string::String, + ::prost::alloc::string::String, + >, /// Mounts for the container. #[prost(message, repeated, tag = "2")] pub mounts: ::prost::alloc::vec::Vec, @@ -172,8 +180,10 @@ pub struct ContainerAllocateResponse { pub devices: ::prost::alloc::vec::Vec, /// Container annotations to pass to the container runtime #[prost(map = "string, string", tag = "4")] - pub annotations: - ::std::collections::HashMap<::prost::alloc::string::String, ::prost::alloc::string::String>, + pub annotations: ::std::collections::HashMap< + ::prost::alloc::string::String, + ::prost::alloc::string::String, + >, } /// Mount specifies a host volume to mount into a container. /// where device library or tools are installed on host and container @@ -210,8 +220,8 @@ pub struct DeviceSpec { /// Generated client implementations. pub mod registration_client { #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] - use tonic::codegen::http::Uri; use tonic::codegen::*; + use tonic::codegen::http::Uri; /// Registration is the service advertised by the Kubelet /// Only when Kubelet answers with a success code to a Register Request /// may Device Plugins start their service @@ -261,8 +271,9 @@ pub mod registration_client { >::ResponseBody, >, >, - >>::Error: - Into + Send + Sync, + , + >>::Error: Into + Send + Sync, { RegistrationClient::new(InterceptedService::new(inner, interceptor)) } @@ -301,14 +312,19 @@ pub mod registration_client { &mut self, request: impl tonic::IntoRequest, ) -> std::result::Result, tonic::Status> { - self.inner.ready().await.map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); - let path = http::uri::PathAndQuery::from_static("/v1beta1.Registration/Register"); + let path = http::uri::PathAndQuery::from_static( + "/v1beta1.Registration/Register", + ); let mut req = request.into_request(); req.extensions_mut() .insert(GrpcMethod::new("v1beta1.Registration", "Register")); @@ -319,8 +335,8 @@ pub mod registration_client { /// Generated client implementations. pub mod device_plugin_client { #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] - use tonic::codegen::http::Uri; use tonic::codegen::*; + use tonic::codegen::http::Uri; /// DevicePlugin is the service advertised by Device Plugins #[derive(Debug, Clone)] pub struct DevicePluginClient { @@ -365,8 +381,9 @@ pub mod device_plugin_client { >::ResponseBody, >, >, - >>::Error: - Into + Send + Sync, + , + >>::Error: Into + Send + Sync, { DevicePluginClient::new(InterceptedService::new(inner, interceptor)) } @@ -406,23 +423,28 @@ pub mod device_plugin_client { pub async fn get_device_plugin_options( &mut self, request: impl tonic::IntoRequest, - ) -> std::result::Result, tonic::Status> - { - self.inner.ready().await.map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); let path = http::uri::PathAndQuery::from_static( "/v1beta1.DevicePlugin/GetDevicePluginOptions", ); let mut req = request.into_request(); - req.extensions_mut().insert(GrpcMethod::new( - "v1beta1.DevicePlugin", - "GetDevicePluginOptions", - )); + req.extensions_mut() + .insert( + GrpcMethod::new("v1beta1.DevicePlugin", "GetDevicePluginOptions"), + ); self.inner.unary(req, path, codec).await } /// ListAndWatch returns a stream of List of Devices @@ -435,14 +457,19 @@ pub mod device_plugin_client { tonic::Response>, tonic::Status, > { - self.inner.ready().await.map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); - let path = http::uri::PathAndQuery::from_static("/v1beta1.DevicePlugin/ListAndWatch"); + let path = http::uri::PathAndQuery::from_static( + "/v1beta1.DevicePlugin/ListAndWatch", + ); let mut req = request.into_request(); req.extensions_mut() .insert(GrpcMethod::new("v1beta1.DevicePlugin", "ListAndWatch")); @@ -456,23 +483,28 @@ pub mod device_plugin_client { pub async fn get_preferred_allocation( &mut self, request: impl tonic::IntoRequest, - ) -> std::result::Result, tonic::Status> - { - self.inner.ready().await.map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); let path = http::uri::PathAndQuery::from_static( "/v1beta1.DevicePlugin/GetPreferredAllocation", ); let mut req = request.into_request(); - req.extensions_mut().insert(GrpcMethod::new( - "v1beta1.DevicePlugin", - "GetPreferredAllocation", - )); + req.extensions_mut() + .insert( + GrpcMethod::new("v1beta1.DevicePlugin", "GetPreferredAllocation"), + ); self.inner.unary(req, path, codec).await } /// Allocate is called during container creation so that the Device @@ -481,15 +513,23 @@ pub mod device_plugin_client { pub async fn allocate( &mut self, request: impl tonic::IntoRequest, - ) -> std::result::Result, tonic::Status> { - self.inner.ready().await.map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); - let path = http::uri::PathAndQuery::from_static("/v1beta1.DevicePlugin/Allocate"); + let path = http::uri::PathAndQuery::from_static( + "/v1beta1.DevicePlugin/Allocate", + ); let mut req = request.into_request(); req.extensions_mut() .insert(GrpcMethod::new("v1beta1.DevicePlugin", "Allocate")); @@ -501,17 +541,23 @@ pub mod device_plugin_client { pub async fn pre_start_container( &mut self, request: impl tonic::IntoRequest, - ) -> std::result::Result, tonic::Status> - { - self.inner.ready().await.map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); - let path = - http::uri::PathAndQuery::from_static("/v1beta1.DevicePlugin/PreStartContainer"); + let path = http::uri::PathAndQuery::from_static( + "/v1beta1.DevicePlugin/PreStartContainer", + ); let mut req = request.into_request(); req.extensions_mut() .insert(GrpcMethod::new("v1beta1.DevicePlugin", "PreStartContainer")); @@ -560,7 +606,10 @@ pub mod registration_server { max_encoding_message_size: None, } } - pub fn with_interceptor(inner: T, interceptor: F) -> InterceptedService + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> InterceptedService where F: tonic::service::Interceptor, { @@ -616,16 +665,23 @@ pub mod registration_server { "/v1beta1.Registration/Register" => { #[allow(non_camel_case_types)] struct RegisterSvc(pub Arc); - impl tonic::server::UnaryService for RegisterSvc { + impl< + T: Registration, + > tonic::server::UnaryService + for RegisterSvc { type Response = super::Empty; - type Future = BoxFuture, tonic::Status>; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; fn call( &mut self, request: tonic::Request, ) -> Self::Future { let inner = Arc::clone(&self.0); - let fut = - async move { ::register(&inner, request).await }; + let fut = async move { + ::register(&inner, request).await + }; Box::pin(fut) } } @@ -652,14 +708,18 @@ pub mod registration_server { }; Box::pin(fut) } - _ => Box::pin(async move { - Ok(http::Response::builder() - .status(200) - .header("grpc-status", "12") - .header("content-type", "application/grpc") - .body(empty_body()) - .unwrap()) - }), + _ => { + Box::pin(async move { + Ok( + http::Response::builder() + .status(200) + .header("grpc-status", "12") + .header("content-type", "application/grpc") + .body(empty_body()) + .unwrap(), + ) + }) + } } } } @@ -701,11 +761,15 @@ pub mod device_plugin_server { async fn get_device_plugin_options( &self, request: tonic::Request, - ) -> std::result::Result, tonic::Status>; + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; /// Server streaming response type for the ListAndWatch method. type ListAndWatchStream: tonic::codegen::tokio_stream::Stream< Item = std::result::Result, - > + Send + > + + Send + 'static; /// ListAndWatch returns a stream of List of Devices /// Whenever a Device state change or a Device disappears, ListAndWatch @@ -713,7 +777,10 @@ pub mod device_plugin_server { async fn list_and_watch( &self, request: tonic::Request, - ) -> std::result::Result, tonic::Status>; + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; /// GetPreferredAllocation returns a preferred set of devices to allocate /// from a list of available ones. The resulting preferred allocation is not /// guaranteed to be the allocation ultimately performed by the @@ -722,21 +789,30 @@ pub mod device_plugin_server { async fn get_preferred_allocation( &self, request: tonic::Request, - ) -> std::result::Result, tonic::Status>; + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; /// Allocate is called during container creation so that the Device /// Plugin can run device specific operations and instruct Kubelet /// of the steps to make the Device available in the container async fn allocate( &self, request: tonic::Request, - ) -> std::result::Result, tonic::Status>; + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; /// PreStartContainer is called, if indicated by Device Plugin during registeration phase, /// before each container start. Device plugin can run device specific operations /// such as resetting the device before making devices available to the container async fn pre_start_container( &self, request: tonic::Request, - ) -> std::result::Result, tonic::Status>; + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; } /// DevicePlugin is the service advertised by Device Plugins #[derive(Debug)] @@ -762,7 +838,10 @@ pub mod device_plugin_server { max_encoding_message_size: None, } } - pub fn with_interceptor(inner: T, interceptor: F) -> InterceptedService + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> InterceptedService where F: tonic::service::Interceptor, { @@ -818,13 +897,23 @@ pub mod device_plugin_server { "/v1beta1.DevicePlugin/GetDevicePluginOptions" => { #[allow(non_camel_case_types)] struct GetDevicePluginOptionsSvc(pub Arc); - impl tonic::server::UnaryService for GetDevicePluginOptionsSvc { + impl tonic::server::UnaryService + for GetDevicePluginOptionsSvc { type Response = super::DevicePluginOptions; - type Future = BoxFuture, tonic::Status>; - fn call(&mut self, request: tonic::Request) -> Self::Future { + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { let inner = Arc::clone(&self.0); let fut = async move { - ::get_device_plugin_options(&inner, request) + ::get_device_plugin_options( + &inner, + request, + ) .await }; Box::pin(fut) @@ -856,12 +945,20 @@ pub mod device_plugin_server { "/v1beta1.DevicePlugin/ListAndWatch" => { #[allow(non_camel_case_types)] struct ListAndWatchSvc(pub Arc); - impl tonic::server::ServerStreamingService for ListAndWatchSvc { + impl< + T: DevicePlugin, + > tonic::server::ServerStreamingService + for ListAndWatchSvc { type Response = super::ListAndWatchResponse; type ResponseStream = T::ListAndWatchStream; - type Future = - BoxFuture, tonic::Status>; - fn call(&mut self, request: tonic::Request) -> Self::Future { + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { let inner = Arc::clone(&self.0); let fut = async move { ::list_and_watch(&inner, request).await @@ -895,19 +992,26 @@ pub mod device_plugin_server { "/v1beta1.DevicePlugin/GetPreferredAllocation" => { #[allow(non_camel_case_types)] struct GetPreferredAllocationSvc(pub Arc); - impl - tonic::server::UnaryService - for GetPreferredAllocationSvc - { + impl< + T: DevicePlugin, + > tonic::server::UnaryService + for GetPreferredAllocationSvc { type Response = super::PreferredAllocationResponse; - type Future = BoxFuture, tonic::Status>; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; fn call( &mut self, request: tonic::Request, ) -> Self::Future { let inner = Arc::clone(&self.0); let fut = async move { - ::get_preferred_allocation(&inner, request).await + ::get_preferred_allocation( + &inner, + request, + ) + .await }; Box::pin(fut) } @@ -938,16 +1042,23 @@ pub mod device_plugin_server { "/v1beta1.DevicePlugin/Allocate" => { #[allow(non_camel_case_types)] struct AllocateSvc(pub Arc); - impl tonic::server::UnaryService for AllocateSvc { + impl< + T: DevicePlugin, + > tonic::server::UnaryService + for AllocateSvc { type Response = super::AllocateResponse; - type Future = BoxFuture, tonic::Status>; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; fn call( &mut self, request: tonic::Request, ) -> Self::Future { let inner = Arc::clone(&self.0); - let fut = - async move { ::allocate(&inner, request).await }; + let fut = async move { + ::allocate(&inner, request).await + }; Box::pin(fut) } } @@ -977,19 +1088,23 @@ pub mod device_plugin_server { "/v1beta1.DevicePlugin/PreStartContainer" => { #[allow(non_camel_case_types)] struct PreStartContainerSvc(pub Arc); - impl - tonic::server::UnaryService - for PreStartContainerSvc - { + impl< + T: DevicePlugin, + > tonic::server::UnaryService + for PreStartContainerSvc { type Response = super::PreStartContainerResponse; - type Future = BoxFuture, tonic::Status>; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; fn call( &mut self, request: tonic::Request, ) -> Self::Future { let inner = Arc::clone(&self.0); let fut = async move { - ::pre_start_container(&inner, request).await + ::pre_start_container(&inner, request) + .await }; Box::pin(fut) } @@ -1017,14 +1132,18 @@ pub mod device_plugin_server { }; Box::pin(fut) } - _ => Box::pin(async move { - Ok(http::Response::builder() - .status(200) - .header("grpc-status", "12") - .header("content-type", "application/grpc") - .body(empty_body()) - .unwrap()) - }), + _ => { + Box::pin(async move { + Ok( + http::Response::builder() + .status(200) + .header("grpc-status", "12") + .header("content-type", "application/grpc") + .body(empty_body()) + .unwrap(), + ) + }) + } } } } diff --git a/discovery-utils/src/discovery/v0.rs b/discovery-utils/src/discovery/v0.rs index 08781a68e..a20490c38 100644 --- a/discovery-utils/src/discovery/v0.rs +++ b/discovery-utils/src/discovery/v0.rs @@ -9,10 +9,7 @@ pub struct RegisterDiscoveryHandlerRequest { /// Endpoint for the registering `DiscoveryHandler` #[prost(string, tag = "2")] pub endpoint: ::prost::alloc::string::String, - #[prost( - enumeration = "register_discovery_handler_request::EndpointType", - tag = "3" - )] + #[prost(enumeration = "register_discovery_handler_request::EndpointType", tag = "3")] pub endpoint_type: i32, /// Specifies whether this device could be used by multiple nodes (e.g. an IP camera) /// or can only be ever be discovered by a single node (e.g. a local USB device) @@ -22,7 +19,17 @@ pub struct RegisterDiscoveryHandlerRequest { /// Nested message and enum types in `RegisterDiscoveryHandlerRequest`. pub mod register_discovery_handler_request { /// Specifies the type of endpoint. - #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] + #[derive( + Clone, + Copy, + Debug, + PartialEq, + Eq, + Hash, + PartialOrd, + Ord, + ::prost::Enumeration + )] #[repr(i32)] pub enum EndpointType { Uds = 0, @@ -68,7 +75,10 @@ pub struct DiscoverRequest { /// list of Key-value pairs containing additional information /// for the 'DiscoveryHandler' to discover devices #[prost(map = "string, message", tag = "2")] - pub discovery_properties: ::std::collections::HashMap<::prost::alloc::string::String, ByteData>, + pub discovery_properties: ::std::collections::HashMap< + ::prost::alloc::string::String, + ByteData, + >, } #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] @@ -87,8 +97,10 @@ pub struct Device { /// and set as environment variables in the device's broker Pods. May be information /// about where to find the device such as an RTSP URL or a device node (e.g. `/dev/video1`) #[prost(map = "string, string", tag = "2")] - pub properties: - ::std::collections::HashMap<::prost::alloc::string::String, ::prost::alloc::string::String>, + pub properties: ::std::collections::HashMap< + ::prost::alloc::string::String, + ::prost::alloc::string::String, + >, /// Optionally specify mounts for Pods that request this device as a resource #[prost(message, repeated, tag = "3")] pub mounts: ::prost::alloc::vec::Vec, @@ -133,8 +145,8 @@ pub struct DeviceSpec { /// Generated client implementations. pub mod registration_client { #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] - use tonic::codegen::http::Uri; use tonic::codegen::*; + use tonic::codegen::http::Uri; /// Registration is the service advertised by the Akri Agent. /// Any `DiscoveryHandler` can register with the Akri Agent. #[derive(Debug, Clone)] @@ -180,8 +192,9 @@ pub mod registration_client { >::ResponseBody, >, >, - >>::Error: - Into + Send + Sync, + , + >>::Error: Into + Send + Sync, { RegistrationClient::new(InterceptedService::new(inner, interceptor)) } @@ -220,20 +233,22 @@ pub mod registration_client { &mut self, request: impl tonic::IntoRequest, ) -> std::result::Result, tonic::Status> { - self.inner.ready().await.map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); - let path = - http::uri::PathAndQuery::from_static("/v0.Registration/RegisterDiscoveryHandler"); + let path = http::uri::PathAndQuery::from_static( + "/v0.Registration/RegisterDiscoveryHandler", + ); let mut req = request.into_request(); - req.extensions_mut().insert(GrpcMethod::new( - "v0.Registration", - "RegisterDiscoveryHandler", - )); + req.extensions_mut() + .insert(GrpcMethod::new("v0.Registration", "RegisterDiscoveryHandler")); self.inner.unary(req, path, codec).await } } @@ -241,8 +256,8 @@ pub mod registration_client { /// Generated client implementations. pub mod discovery_handler_client { #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] - use tonic::codegen::http::Uri; use tonic::codegen::*; + use tonic::codegen::http::Uri; #[derive(Debug, Clone)] pub struct DiscoveryHandlerClient { inner: tonic::client::Grpc, @@ -286,8 +301,9 @@ pub mod discovery_handler_client { >::ResponseBody, >, >, - >>::Error: - Into + Send + Sync, + , + >>::Error: Into + Send + Sync, { DiscoveryHandlerClient::new(InterceptedService::new(inner, interceptor)) } @@ -329,14 +345,19 @@ pub mod discovery_handler_client { tonic::Response>, tonic::Status, > { - self.inner.ready().await.map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); - let path = http::uri::PathAndQuery::from_static("/v0.DiscoveryHandler/Discover"); + let path = http::uri::PathAndQuery::from_static( + "/v0.DiscoveryHandler/Discover", + ); let mut req = request.into_request(); req.extensions_mut() .insert(GrpcMethod::new("v0.DiscoveryHandler", "Discover")); @@ -381,7 +402,10 @@ pub mod registration_server { max_encoding_message_size: None, } } - pub fn with_interceptor(inner: T, interceptor: F) -> InterceptedService + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> InterceptedService where F: tonic::service::Interceptor, { @@ -437,19 +461,27 @@ pub mod registration_server { "/v0.Registration/RegisterDiscoveryHandler" => { #[allow(non_camel_case_types)] struct RegisterDiscoveryHandlerSvc(pub Arc); - impl - tonic::server::UnaryService - for RegisterDiscoveryHandlerSvc - { + impl< + T: Registration, + > tonic::server::UnaryService + for RegisterDiscoveryHandlerSvc { type Response = super::Empty; - type Future = BoxFuture, tonic::Status>; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; fn call( &mut self, - request: tonic::Request, + request: tonic::Request< + super::RegisterDiscoveryHandlerRequest, + >, ) -> Self::Future { let inner = Arc::clone(&self.0); let fut = async move { - ::register_discovery_handler(&inner, request) + ::register_discovery_handler( + &inner, + request, + ) .await }; Box::pin(fut) @@ -478,14 +510,18 @@ pub mod registration_server { }; Box::pin(fut) } - _ => Box::pin(async move { - Ok(http::Response::builder() - .status(200) - .header("grpc-status", "12") - .header("content-type", "application/grpc") - .body(empty_body()) - .unwrap()) - }), + _ => { + Box::pin(async move { + Ok( + http::Response::builder() + .status(200) + .header("grpc-status", "12") + .header("content-type", "application/grpc") + .body(empty_body()) + .unwrap(), + ) + }) + } } } } @@ -525,7 +561,8 @@ pub mod discovery_handler_server { /// Server streaming response type for the Discover method. type DiscoverStream: tonic::codegen::tokio_stream::Stream< Item = std::result::Result, - > + Send + > + + Send + 'static; async fn discover( &self, @@ -555,7 +592,10 @@ pub mod discovery_handler_server { max_encoding_message_size: None, } } - pub fn with_interceptor(inner: T, interceptor: F) -> InterceptedService + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> InterceptedService where F: tonic::service::Interceptor, { @@ -611,14 +651,16 @@ pub mod discovery_handler_server { "/v0.DiscoveryHandler/Discover" => { #[allow(non_camel_case_types)] struct DiscoverSvc(pub Arc); - impl - tonic::server::ServerStreamingService - for DiscoverSvc - { + impl< + T: DiscoveryHandler, + > tonic::server::ServerStreamingService + for DiscoverSvc { type Response = super::DiscoverResponse; type ResponseStream = T::DiscoverStream; - type Future = - BoxFuture, tonic::Status>; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; fn call( &mut self, request: tonic::Request, @@ -653,14 +695,18 @@ pub mod discovery_handler_server { }; Box::pin(fut) } - _ => Box::pin(async move { - Ok(http::Response::builder() - .status(200) - .header("grpc-status", "12") - .header("content-type", "application/grpc") - .body(empty_body()) - .unwrap()) - }), + _ => { + Box::pin(async move { + Ok( + http::Response::builder() + .status(200) + .header("grpc-status", "12") + .header("content-type", "application/grpc") + .body(empty_body()) + .unwrap(), + ) + }) + } } } } diff --git a/samples/brokers/udev-video-broker/src/util/camera.rs b/samples/brokers/udev-video-broker/src/util/camera.rs index 437b09cd8..4bd208251 100644 --- a/samples/brokers/udev-video-broker/src/util/camera.rs +++ b/samples/brokers/udev-video-broker/src/util/camera.rs @@ -13,8 +13,8 @@ pub struct NotifyResponse { /// Generated client implementations. pub mod camera_client { #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] - use tonic::codegen::http::Uri; use tonic::codegen::*; + use tonic::codegen::http::Uri; #[derive(Debug, Clone)] pub struct CameraClient { inner: tonic::client::Grpc, @@ -58,8 +58,9 @@ pub mod camera_client { >::ResponseBody, >, >, - >>::Error: - Into + Send + Sync, + , + >>::Error: Into + Send + Sync, { CameraClient::new(InterceptedService::new(inner, interceptor)) } @@ -98,17 +99,19 @@ pub mod camera_client { &mut self, request: impl tonic::IntoRequest, ) -> std::result::Result, tonic::Status> { - self.inner.ready().await.map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); let path = http::uri::PathAndQuery::from_static("/camera.Camera/GetFrame"); let mut req = request.into_request(); - req.extensions_mut() - .insert(GrpcMethod::new("camera.Camera", "GetFrame")); + req.extensions_mut().insert(GrpcMethod::new("camera.Camera", "GetFrame")); self.inner.unary(req, path, codec).await } } @@ -148,7 +151,10 @@ pub mod camera_server { max_encoding_message_size: None, } } - pub fn with_interceptor(inner: T, interceptor: F) -> InterceptedService + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> InterceptedService where F: tonic::service::Interceptor, { @@ -204,16 +210,21 @@ pub mod camera_server { "/camera.Camera/GetFrame" => { #[allow(non_camel_case_types)] struct GetFrameSvc(pub Arc); - impl tonic::server::UnaryService for GetFrameSvc { + impl tonic::server::UnaryService + for GetFrameSvc { type Response = super::NotifyResponse; - type Future = BoxFuture, tonic::Status>; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; fn call( &mut self, request: tonic::Request, ) -> Self::Future { let inner = Arc::clone(&self.0); - let fut = - async move { ::get_frame(&inner, request).await }; + let fut = async move { + ::get_frame(&inner, request).await + }; Box::pin(fut) } } @@ -240,14 +251,18 @@ pub mod camera_server { }; Box::pin(fut) } - _ => Box::pin(async move { - Ok(http::Response::builder() - .status(200) - .header("grpc-status", "12") - .header("content-type", "application/grpc") - .body(empty_body()) - .unwrap()) - }), + _ => { + Box::pin(async move { + Ok( + http::Response::builder() + .status(200) + .header("grpc-status", "12") + .header("content-type", "application/grpc") + .body(empty_body()) + .unwrap(), + ) + }) + } } } } From 202a64c53b250786a394cf39054b9f3c3e06981e Mon Sep 17 00:00:00 2001 From: Marcel Bindseil Date: Fri, 17 Jan 2025 17:02:47 +0100 Subject: [PATCH 03/19] formatting Signed-off-by: Marcel Bindseil --- agent/src/plugin_manager/v1.rs | 131 +++---- agent/src/plugin_manager/v1beta1.rs | 361 ++++++------------ .../udev/src/discovery_handler.rs | 3 +- discovery-utils/src/discovery/v0.rs | 176 ++++----- .../udev-video-broker/src/util/camera.rs | 63 ++- 5 files changed, 260 insertions(+), 474 deletions(-) diff --git a/agent/src/plugin_manager/v1.rs b/agent/src/plugin_manager/v1.rs index f016fb20b..7f3183f3f 100644 --- a/agent/src/plugin_manager/v1.rs +++ b/agent/src/plugin_manager/v1.rs @@ -87,8 +87,8 @@ pub struct NumaNode { /// Generated client implementations. pub mod pod_resources_lister_client { #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] - use tonic::codegen::*; use tonic::codegen::http::Uri; + use tonic::codegen::*; /// PodResourcesLister is a service provided by the kubelet that provides information about the /// node resources consumed by pods and containers on the node #[derive(Debug, Clone)] @@ -134,9 +134,8 @@ pub mod pod_resources_lister_client { >::ResponseBody, >, >, - , - >>::Error: Into + Send + Sync, + >>::Error: + Into + Send + Sync, { PodResourcesListerClient::new(InterceptedService::new(inner, interceptor)) } @@ -174,23 +173,16 @@ pub mod pod_resources_lister_client { pub async fn list( &mut self, request: impl tonic::IntoRequest, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - > { - self.inner - .ready() - .await - .map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + ) -> std::result::Result, tonic::Status> + { + self.inner.ready().await.map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); - let path = http::uri::PathAndQuery::from_static( - "/v1.PodResourcesLister/List", - ); + let path = http::uri::PathAndQuery::from_static("/v1.PodResourcesLister/List"); let mut req = request.into_request(); req.extensions_mut() .insert(GrpcMethod::new("v1.PodResourcesLister", "List")); @@ -199,28 +191,23 @@ pub mod pod_resources_lister_client { pub async fn get_allocatable_resources( &mut self, request: impl tonic::IntoRequest, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - > { - self.inner - .ready() - .await - .map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + ) -> std::result::Result, tonic::Status> + { + self.inner.ready().await.map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); let path = http::uri::PathAndQuery::from_static( "/v1.PodResourcesLister/GetAllocatableResources", ); let mut req = request.into_request(); - req.extensions_mut() - .insert( - GrpcMethod::new("v1.PodResourcesLister", "GetAllocatableResources"), - ); + req.extensions_mut().insert(GrpcMethod::new( + "v1.PodResourcesLister", + "GetAllocatableResources", + )); self.inner.unary(req, path, codec).await } } @@ -235,17 +222,11 @@ pub mod pod_resources_lister_server { async fn list( &self, request: tonic::Request, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - >; + ) -> std::result::Result, tonic::Status>; async fn get_allocatable_resources( &self, request: tonic::Request, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - >; + ) -> std::result::Result, tonic::Status>; } /// PodResourcesLister is a service provided by the kubelet that provides information about the /// node resources consumed by pods and containers on the node @@ -272,10 +253,7 @@ pub mod pod_resources_lister_server { max_encoding_message_size: None, } } - pub fn with_interceptor( - inner: T, - interceptor: F, - ) -> InterceptedService + pub fn with_interceptor(inner: T, interceptor: F) -> InterceptedService where F: tonic::service::Interceptor, { @@ -331,15 +309,11 @@ pub mod pod_resources_lister_server { "/v1.PodResourcesLister/List" => { #[allow(non_camel_case_types)] struct ListSvc(pub Arc); - impl< - T: PodResourcesLister, - > tonic::server::UnaryService - for ListSvc { + impl + tonic::server::UnaryService for ListSvc + { type Response = super::ListPodResourcesResponse; - type Future = BoxFuture< - tonic::Response, - tonic::Status, - >; + type Future = BoxFuture, tonic::Status>; fn call( &mut self, request: tonic::Request, @@ -377,15 +351,12 @@ pub mod pod_resources_lister_server { "/v1.PodResourcesLister/GetAllocatableResources" => { #[allow(non_camel_case_types)] struct GetAllocatableResourcesSvc(pub Arc); - impl< - T: PodResourcesLister, - > tonic::server::UnaryService - for GetAllocatableResourcesSvc { + impl + tonic::server::UnaryService + for GetAllocatableResourcesSvc + { type Response = super::AllocatableResourcesResponse; - type Future = BoxFuture< - tonic::Response, - tonic::Status, - >; + type Future = BoxFuture, tonic::Status>; fn call( &mut self, request: tonic::Request, @@ -393,10 +364,9 @@ pub mod pod_resources_lister_server { let inner = Arc::clone(&self.0); let fut = async move { ::get_allocatable_resources( - &inner, - request, - ) - .await + &inner, request, + ) + .await }; Box::pin(fut) } @@ -424,18 +394,14 @@ pub mod pod_resources_lister_server { }; Box::pin(fut) } - _ => { - Box::pin(async move { - Ok( - http::Response::builder() - .status(200) - .header("grpc-status", "12") - .header("content-type", "application/grpc") - .body(empty_body()) - .unwrap(), - ) - }) - } + _ => Box::pin(async move { + Ok(http::Response::builder() + .status(200) + .header("grpc-status", "12") + .header("content-type", "application/grpc") + .body(empty_body()) + .unwrap()) + }), } } } @@ -461,8 +427,7 @@ pub mod pod_resources_lister_server { write!(f, "{:?}", self.0) } } - impl tonic::server::NamedService - for PodResourcesListerServer { + impl tonic::server::NamedService for PodResourcesListerServer { const NAME: &'static str = "v1.PodResourcesLister"; } } diff --git a/agent/src/plugin_manager/v1beta1.rs b/agent/src/plugin_manager/v1beta1.rs index 7b068ecab..a88570f4d 100644 --- a/agent/src/plugin_manager/v1beta1.rs +++ b/agent/src/plugin_manager/v1beta1.rs @@ -96,9 +96,7 @@ pub struct PreStartContainerResponse {} #[derive(Clone, PartialEq, ::prost::Message)] pub struct PreferredAllocationRequest { #[prost(message, repeated, tag = "1")] - pub container_requests: ::prost::alloc::vec::Vec< - ContainerPreferredAllocationRequest, - >, + pub container_requests: ::prost::alloc::vec::Vec, } #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] @@ -108,9 +106,7 @@ pub struct ContainerPreferredAllocationRequest { pub available_device_i_ds: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, /// List of deviceIDs that must be included in the preferred allocation #[prost(string, repeated, tag = "2")] - pub must_include_device_i_ds: ::prost::alloc::vec::Vec< - ::prost::alloc::string::String, - >, + pub must_include_device_i_ds: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, /// Number of devices to include in the preferred allocation #[prost(int32, tag = "3")] pub allocation_size: i32, @@ -121,9 +117,7 @@ pub struct ContainerPreferredAllocationRequest { #[derive(Clone, PartialEq, ::prost::Message)] pub struct PreferredAllocationResponse { #[prost(message, repeated, tag = "1")] - pub container_responses: ::prost::alloc::vec::Vec< - ContainerPreferredAllocationResponse, - >, + pub container_responses: ::prost::alloc::vec::Vec, } #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] @@ -168,10 +162,8 @@ pub struct AllocateResponse { pub struct ContainerAllocateResponse { /// List of environment variable to be set in the container to access one of more devices. #[prost(map = "string, string", tag = "1")] - pub envs: ::std::collections::HashMap< - ::prost::alloc::string::String, - ::prost::alloc::string::String, - >, + pub envs: + ::std::collections::HashMap<::prost::alloc::string::String, ::prost::alloc::string::String>, /// Mounts for the container. #[prost(message, repeated, tag = "2")] pub mounts: ::prost::alloc::vec::Vec, @@ -180,10 +172,8 @@ pub struct ContainerAllocateResponse { pub devices: ::prost::alloc::vec::Vec, /// Container annotations to pass to the container runtime #[prost(map = "string, string", tag = "4")] - pub annotations: ::std::collections::HashMap< - ::prost::alloc::string::String, - ::prost::alloc::string::String, - >, + pub annotations: + ::std::collections::HashMap<::prost::alloc::string::String, ::prost::alloc::string::String>, } /// Mount specifies a host volume to mount into a container. /// where device library or tools are installed on host and container @@ -220,8 +210,8 @@ pub struct DeviceSpec { /// Generated client implementations. pub mod registration_client { #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] - use tonic::codegen::*; use tonic::codegen::http::Uri; + use tonic::codegen::*; /// Registration is the service advertised by the Kubelet /// Only when Kubelet answers with a success code to a Register Request /// may Device Plugins start their service @@ -271,9 +261,8 @@ pub mod registration_client { >::ResponseBody, >, >, - , - >>::Error: Into + Send + Sync, + >>::Error: + Into + Send + Sync, { RegistrationClient::new(InterceptedService::new(inner, interceptor)) } @@ -312,19 +301,14 @@ pub mod registration_client { &mut self, request: impl tonic::IntoRequest, ) -> std::result::Result, tonic::Status> { - self.inner - .ready() - .await - .map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + self.inner.ready().await.map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); - let path = http::uri::PathAndQuery::from_static( - "/v1beta1.Registration/Register", - ); + let path = http::uri::PathAndQuery::from_static("/v1beta1.Registration/Register"); let mut req = request.into_request(); req.extensions_mut() .insert(GrpcMethod::new("v1beta1.Registration", "Register")); @@ -335,8 +319,8 @@ pub mod registration_client { /// Generated client implementations. pub mod device_plugin_client { #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] - use tonic::codegen::*; use tonic::codegen::http::Uri; + use tonic::codegen::*; /// DevicePlugin is the service advertised by Device Plugins #[derive(Debug, Clone)] pub struct DevicePluginClient { @@ -381,9 +365,8 @@ pub mod device_plugin_client { >::ResponseBody, >, >, - , - >>::Error: Into + Send + Sync, + >>::Error: + Into + Send + Sync, { DevicePluginClient::new(InterceptedService::new(inner, interceptor)) } @@ -423,28 +406,23 @@ pub mod device_plugin_client { pub async fn get_device_plugin_options( &mut self, request: impl tonic::IntoRequest, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - > { - self.inner - .ready() - .await - .map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + ) -> std::result::Result, tonic::Status> + { + self.inner.ready().await.map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); let path = http::uri::PathAndQuery::from_static( "/v1beta1.DevicePlugin/GetDevicePluginOptions", ); let mut req = request.into_request(); - req.extensions_mut() - .insert( - GrpcMethod::new("v1beta1.DevicePlugin", "GetDevicePluginOptions"), - ); + req.extensions_mut().insert(GrpcMethod::new( + "v1beta1.DevicePlugin", + "GetDevicePluginOptions", + )); self.inner.unary(req, path, codec).await } /// ListAndWatch returns a stream of List of Devices @@ -457,19 +435,14 @@ pub mod device_plugin_client { tonic::Response>, tonic::Status, > { - self.inner - .ready() - .await - .map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + self.inner.ready().await.map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); - let path = http::uri::PathAndQuery::from_static( - "/v1beta1.DevicePlugin/ListAndWatch", - ); + let path = http::uri::PathAndQuery::from_static("/v1beta1.DevicePlugin/ListAndWatch"); let mut req = request.into_request(); req.extensions_mut() .insert(GrpcMethod::new("v1beta1.DevicePlugin", "ListAndWatch")); @@ -483,28 +456,23 @@ pub mod device_plugin_client { pub async fn get_preferred_allocation( &mut self, request: impl tonic::IntoRequest, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - > { - self.inner - .ready() - .await - .map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + ) -> std::result::Result, tonic::Status> + { + self.inner.ready().await.map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); let path = http::uri::PathAndQuery::from_static( "/v1beta1.DevicePlugin/GetPreferredAllocation", ); let mut req = request.into_request(); - req.extensions_mut() - .insert( - GrpcMethod::new("v1beta1.DevicePlugin", "GetPreferredAllocation"), - ); + req.extensions_mut().insert(GrpcMethod::new( + "v1beta1.DevicePlugin", + "GetPreferredAllocation", + )); self.inner.unary(req, path, codec).await } /// Allocate is called during container creation so that the Device @@ -513,23 +481,15 @@ pub mod device_plugin_client { pub async fn allocate( &mut self, request: impl tonic::IntoRequest, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - > { - self.inner - .ready() - .await - .map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + ) -> std::result::Result, tonic::Status> { + self.inner.ready().await.map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); - let path = http::uri::PathAndQuery::from_static( - "/v1beta1.DevicePlugin/Allocate", - ); + let path = http::uri::PathAndQuery::from_static("/v1beta1.DevicePlugin/Allocate"); let mut req = request.into_request(); req.extensions_mut() .insert(GrpcMethod::new("v1beta1.DevicePlugin", "Allocate")); @@ -541,23 +501,17 @@ pub mod device_plugin_client { pub async fn pre_start_container( &mut self, request: impl tonic::IntoRequest, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - > { - self.inner - .ready() - .await - .map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + ) -> std::result::Result, tonic::Status> + { + self.inner.ready().await.map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); - let path = http::uri::PathAndQuery::from_static( - "/v1beta1.DevicePlugin/PreStartContainer", - ); + let path = + http::uri::PathAndQuery::from_static("/v1beta1.DevicePlugin/PreStartContainer"); let mut req = request.into_request(); req.extensions_mut() .insert(GrpcMethod::new("v1beta1.DevicePlugin", "PreStartContainer")); @@ -606,10 +560,7 @@ pub mod registration_server { max_encoding_message_size: None, } } - pub fn with_interceptor( - inner: T, - interceptor: F, - ) -> InterceptedService + pub fn with_interceptor(inner: T, interceptor: F) -> InterceptedService where F: tonic::service::Interceptor, { @@ -665,23 +616,16 @@ pub mod registration_server { "/v1beta1.Registration/Register" => { #[allow(non_camel_case_types)] struct RegisterSvc(pub Arc); - impl< - T: Registration, - > tonic::server::UnaryService - for RegisterSvc { + impl tonic::server::UnaryService for RegisterSvc { type Response = super::Empty; - type Future = BoxFuture< - tonic::Response, - tonic::Status, - >; + type Future = BoxFuture, tonic::Status>; fn call( &mut self, request: tonic::Request, ) -> Self::Future { let inner = Arc::clone(&self.0); - let fut = async move { - ::register(&inner, request).await - }; + let fut = + async move { ::register(&inner, request).await }; Box::pin(fut) } } @@ -708,18 +652,14 @@ pub mod registration_server { }; Box::pin(fut) } - _ => { - Box::pin(async move { - Ok( - http::Response::builder() - .status(200) - .header("grpc-status", "12") - .header("content-type", "application/grpc") - .body(empty_body()) - .unwrap(), - ) - }) - } + _ => Box::pin(async move { + Ok(http::Response::builder() + .status(200) + .header("grpc-status", "12") + .header("content-type", "application/grpc") + .body(empty_body()) + .unwrap()) + }), } } } @@ -761,15 +701,11 @@ pub mod device_plugin_server { async fn get_device_plugin_options( &self, request: tonic::Request, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - >; + ) -> std::result::Result, tonic::Status>; /// Server streaming response type for the ListAndWatch method. type ListAndWatchStream: tonic::codegen::tokio_stream::Stream< Item = std::result::Result, - > - + Send + > + Send + 'static; /// ListAndWatch returns a stream of List of Devices /// Whenever a Device state change or a Device disappears, ListAndWatch @@ -777,10 +713,7 @@ pub mod device_plugin_server { async fn list_and_watch( &self, request: tonic::Request, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - >; + ) -> std::result::Result, tonic::Status>; /// GetPreferredAllocation returns a preferred set of devices to allocate /// from a list of available ones. The resulting preferred allocation is not /// guaranteed to be the allocation ultimately performed by the @@ -789,30 +722,21 @@ pub mod device_plugin_server { async fn get_preferred_allocation( &self, request: tonic::Request, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - >; + ) -> std::result::Result, tonic::Status>; /// Allocate is called during container creation so that the Device /// Plugin can run device specific operations and instruct Kubelet /// of the steps to make the Device available in the container async fn allocate( &self, request: tonic::Request, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - >; + ) -> std::result::Result, tonic::Status>; /// PreStartContainer is called, if indicated by Device Plugin during registeration phase, /// before each container start. Device plugin can run device specific operations /// such as resetting the device before making devices available to the container async fn pre_start_container( &self, request: tonic::Request, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - >; + ) -> std::result::Result, tonic::Status>; } /// DevicePlugin is the service advertised by Device Plugins #[derive(Debug)] @@ -838,10 +762,7 @@ pub mod device_plugin_server { max_encoding_message_size: None, } } - pub fn with_interceptor( - inner: T, - interceptor: F, - ) -> InterceptedService + pub fn with_interceptor(inner: T, interceptor: F) -> InterceptedService where F: tonic::service::Interceptor, { @@ -897,23 +818,13 @@ pub mod device_plugin_server { "/v1beta1.DevicePlugin/GetDevicePluginOptions" => { #[allow(non_camel_case_types)] struct GetDevicePluginOptionsSvc(pub Arc); - impl tonic::server::UnaryService - for GetDevicePluginOptionsSvc { + impl tonic::server::UnaryService for GetDevicePluginOptionsSvc { type Response = super::DevicePluginOptions; - type Future = BoxFuture< - tonic::Response, - tonic::Status, - >; - fn call( - &mut self, - request: tonic::Request, - ) -> Self::Future { + type Future = BoxFuture, tonic::Status>; + fn call(&mut self, request: tonic::Request) -> Self::Future { let inner = Arc::clone(&self.0); let fut = async move { - ::get_device_plugin_options( - &inner, - request, - ) + ::get_device_plugin_options(&inner, request) .await }; Box::pin(fut) @@ -945,20 +856,12 @@ pub mod device_plugin_server { "/v1beta1.DevicePlugin/ListAndWatch" => { #[allow(non_camel_case_types)] struct ListAndWatchSvc(pub Arc); - impl< - T: DevicePlugin, - > tonic::server::ServerStreamingService - for ListAndWatchSvc { + impl tonic::server::ServerStreamingService for ListAndWatchSvc { type Response = super::ListAndWatchResponse; type ResponseStream = T::ListAndWatchStream; - type Future = BoxFuture< - tonic::Response, - tonic::Status, - >; - fn call( - &mut self, - request: tonic::Request, - ) -> Self::Future { + type Future = + BoxFuture, tonic::Status>; + fn call(&mut self, request: tonic::Request) -> Self::Future { let inner = Arc::clone(&self.0); let fut = async move { ::list_and_watch(&inner, request).await @@ -992,26 +895,19 @@ pub mod device_plugin_server { "/v1beta1.DevicePlugin/GetPreferredAllocation" => { #[allow(non_camel_case_types)] struct GetPreferredAllocationSvc(pub Arc); - impl< - T: DevicePlugin, - > tonic::server::UnaryService - for GetPreferredAllocationSvc { + impl + tonic::server::UnaryService + for GetPreferredAllocationSvc + { type Response = super::PreferredAllocationResponse; - type Future = BoxFuture< - tonic::Response, - tonic::Status, - >; + type Future = BoxFuture, tonic::Status>; fn call( &mut self, request: tonic::Request, ) -> Self::Future { let inner = Arc::clone(&self.0); let fut = async move { - ::get_preferred_allocation( - &inner, - request, - ) - .await + ::get_preferred_allocation(&inner, request).await }; Box::pin(fut) } @@ -1042,23 +938,16 @@ pub mod device_plugin_server { "/v1beta1.DevicePlugin/Allocate" => { #[allow(non_camel_case_types)] struct AllocateSvc(pub Arc); - impl< - T: DevicePlugin, - > tonic::server::UnaryService - for AllocateSvc { + impl tonic::server::UnaryService for AllocateSvc { type Response = super::AllocateResponse; - type Future = BoxFuture< - tonic::Response, - tonic::Status, - >; + type Future = BoxFuture, tonic::Status>; fn call( &mut self, request: tonic::Request, ) -> Self::Future { let inner = Arc::clone(&self.0); - let fut = async move { - ::allocate(&inner, request).await - }; + let fut = + async move { ::allocate(&inner, request).await }; Box::pin(fut) } } @@ -1088,23 +977,19 @@ pub mod device_plugin_server { "/v1beta1.DevicePlugin/PreStartContainer" => { #[allow(non_camel_case_types)] struct PreStartContainerSvc(pub Arc); - impl< - T: DevicePlugin, - > tonic::server::UnaryService - for PreStartContainerSvc { + impl + tonic::server::UnaryService + for PreStartContainerSvc + { type Response = super::PreStartContainerResponse; - type Future = BoxFuture< - tonic::Response, - tonic::Status, - >; + type Future = BoxFuture, tonic::Status>; fn call( &mut self, request: tonic::Request, ) -> Self::Future { let inner = Arc::clone(&self.0); let fut = async move { - ::pre_start_container(&inner, request) - .await + ::pre_start_container(&inner, request).await }; Box::pin(fut) } @@ -1132,18 +1017,14 @@ pub mod device_plugin_server { }; Box::pin(fut) } - _ => { - Box::pin(async move { - Ok( - http::Response::builder() - .status(200) - .header("grpc-status", "12") - .header("content-type", "application/grpc") - .body(empty_body()) - .unwrap(), - ) - }) - } + _ => Box::pin(async move { + Ok(http::Response::builder() + .status(200) + .header("grpc-status", "12") + .header("content-type", "application/grpc") + .body(empty_body()) + .unwrap()) + }), } } } diff --git a/discovery-handlers/udev/src/discovery_handler.rs b/discovery-handlers/udev/src/discovery_handler.rs index 13b35faae..0415b9f0c 100644 --- a/discovery-handlers/udev/src/discovery_handler.rs +++ b/discovery-handlers/udev/src/discovery_handler.rs @@ -181,7 +181,8 @@ mod tests { let udev_dh_config: UdevDiscoveryDetails = deserialize_discovery_details(yaml).unwrap(); assert!(udev_dh_config.udev_rules.is_empty()); let serialized = serde_json::to_string(&udev_dh_config).unwrap(); - let expected_deserialized = r#"{"udevRules":[],"groupRecursive":false,"permissions":"rwm"}"#; + let expected_deserialized = + r#"{"udevRules":[],"groupRecursive":false,"permissions":"rwm"}"#; assert_eq!(expected_deserialized, serialized); } diff --git a/discovery-utils/src/discovery/v0.rs b/discovery-utils/src/discovery/v0.rs index a20490c38..08781a68e 100644 --- a/discovery-utils/src/discovery/v0.rs +++ b/discovery-utils/src/discovery/v0.rs @@ -9,7 +9,10 @@ pub struct RegisterDiscoveryHandlerRequest { /// Endpoint for the registering `DiscoveryHandler` #[prost(string, tag = "2")] pub endpoint: ::prost::alloc::string::String, - #[prost(enumeration = "register_discovery_handler_request::EndpointType", tag = "3")] + #[prost( + enumeration = "register_discovery_handler_request::EndpointType", + tag = "3" + )] pub endpoint_type: i32, /// Specifies whether this device could be used by multiple nodes (e.g. an IP camera) /// or can only be ever be discovered by a single node (e.g. a local USB device) @@ -19,17 +22,7 @@ pub struct RegisterDiscoveryHandlerRequest { /// Nested message and enum types in `RegisterDiscoveryHandlerRequest`. pub mod register_discovery_handler_request { /// Specifies the type of endpoint. - #[derive( - Clone, - Copy, - Debug, - PartialEq, - Eq, - Hash, - PartialOrd, - Ord, - ::prost::Enumeration - )] + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] #[repr(i32)] pub enum EndpointType { Uds = 0, @@ -75,10 +68,7 @@ pub struct DiscoverRequest { /// list of Key-value pairs containing additional information /// for the 'DiscoveryHandler' to discover devices #[prost(map = "string, message", tag = "2")] - pub discovery_properties: ::std::collections::HashMap< - ::prost::alloc::string::String, - ByteData, - >, + pub discovery_properties: ::std::collections::HashMap<::prost::alloc::string::String, ByteData>, } #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] @@ -97,10 +87,8 @@ pub struct Device { /// and set as environment variables in the device's broker Pods. May be information /// about where to find the device such as an RTSP URL or a device node (e.g. `/dev/video1`) #[prost(map = "string, string", tag = "2")] - pub properties: ::std::collections::HashMap< - ::prost::alloc::string::String, - ::prost::alloc::string::String, - >, + pub properties: + ::std::collections::HashMap<::prost::alloc::string::String, ::prost::alloc::string::String>, /// Optionally specify mounts for Pods that request this device as a resource #[prost(message, repeated, tag = "3")] pub mounts: ::prost::alloc::vec::Vec, @@ -145,8 +133,8 @@ pub struct DeviceSpec { /// Generated client implementations. pub mod registration_client { #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] - use tonic::codegen::*; use tonic::codegen::http::Uri; + use tonic::codegen::*; /// Registration is the service advertised by the Akri Agent. /// Any `DiscoveryHandler` can register with the Akri Agent. #[derive(Debug, Clone)] @@ -192,9 +180,8 @@ pub mod registration_client { >::ResponseBody, >, >, - , - >>::Error: Into + Send + Sync, + >>::Error: + Into + Send + Sync, { RegistrationClient::new(InterceptedService::new(inner, interceptor)) } @@ -233,22 +220,20 @@ pub mod registration_client { &mut self, request: impl tonic::IntoRequest, ) -> std::result::Result, tonic::Status> { - self.inner - .ready() - .await - .map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + self.inner.ready().await.map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); - let path = http::uri::PathAndQuery::from_static( - "/v0.Registration/RegisterDiscoveryHandler", - ); + let path = + http::uri::PathAndQuery::from_static("/v0.Registration/RegisterDiscoveryHandler"); let mut req = request.into_request(); - req.extensions_mut() - .insert(GrpcMethod::new("v0.Registration", "RegisterDiscoveryHandler")); + req.extensions_mut().insert(GrpcMethod::new( + "v0.Registration", + "RegisterDiscoveryHandler", + )); self.inner.unary(req, path, codec).await } } @@ -256,8 +241,8 @@ pub mod registration_client { /// Generated client implementations. pub mod discovery_handler_client { #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] - use tonic::codegen::*; use tonic::codegen::http::Uri; + use tonic::codegen::*; #[derive(Debug, Clone)] pub struct DiscoveryHandlerClient { inner: tonic::client::Grpc, @@ -301,9 +286,8 @@ pub mod discovery_handler_client { >::ResponseBody, >, >, - , - >>::Error: Into + Send + Sync, + >>::Error: + Into + Send + Sync, { DiscoveryHandlerClient::new(InterceptedService::new(inner, interceptor)) } @@ -345,19 +329,14 @@ pub mod discovery_handler_client { tonic::Response>, tonic::Status, > { - self.inner - .ready() - .await - .map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + self.inner.ready().await.map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); - let path = http::uri::PathAndQuery::from_static( - "/v0.DiscoveryHandler/Discover", - ); + let path = http::uri::PathAndQuery::from_static("/v0.DiscoveryHandler/Discover"); let mut req = request.into_request(); req.extensions_mut() .insert(GrpcMethod::new("v0.DiscoveryHandler", "Discover")); @@ -402,10 +381,7 @@ pub mod registration_server { max_encoding_message_size: None, } } - pub fn with_interceptor( - inner: T, - interceptor: F, - ) -> InterceptedService + pub fn with_interceptor(inner: T, interceptor: F) -> InterceptedService where F: tonic::service::Interceptor, { @@ -461,27 +437,19 @@ pub mod registration_server { "/v0.Registration/RegisterDiscoveryHandler" => { #[allow(non_camel_case_types)] struct RegisterDiscoveryHandlerSvc(pub Arc); - impl< - T: Registration, - > tonic::server::UnaryService - for RegisterDiscoveryHandlerSvc { + impl + tonic::server::UnaryService + for RegisterDiscoveryHandlerSvc + { type Response = super::Empty; - type Future = BoxFuture< - tonic::Response, - tonic::Status, - >; + type Future = BoxFuture, tonic::Status>; fn call( &mut self, - request: tonic::Request< - super::RegisterDiscoveryHandlerRequest, - >, + request: tonic::Request, ) -> Self::Future { let inner = Arc::clone(&self.0); let fut = async move { - ::register_discovery_handler( - &inner, - request, - ) + ::register_discovery_handler(&inner, request) .await }; Box::pin(fut) @@ -510,18 +478,14 @@ pub mod registration_server { }; Box::pin(fut) } - _ => { - Box::pin(async move { - Ok( - http::Response::builder() - .status(200) - .header("grpc-status", "12") - .header("content-type", "application/grpc") - .body(empty_body()) - .unwrap(), - ) - }) - } + _ => Box::pin(async move { + Ok(http::Response::builder() + .status(200) + .header("grpc-status", "12") + .header("content-type", "application/grpc") + .body(empty_body()) + .unwrap()) + }), } } } @@ -561,8 +525,7 @@ pub mod discovery_handler_server { /// Server streaming response type for the Discover method. type DiscoverStream: tonic::codegen::tokio_stream::Stream< Item = std::result::Result, - > - + Send + > + Send + 'static; async fn discover( &self, @@ -592,10 +555,7 @@ pub mod discovery_handler_server { max_encoding_message_size: None, } } - pub fn with_interceptor( - inner: T, - interceptor: F, - ) -> InterceptedService + pub fn with_interceptor(inner: T, interceptor: F) -> InterceptedService where F: tonic::service::Interceptor, { @@ -651,16 +611,14 @@ pub mod discovery_handler_server { "/v0.DiscoveryHandler/Discover" => { #[allow(non_camel_case_types)] struct DiscoverSvc(pub Arc); - impl< - T: DiscoveryHandler, - > tonic::server::ServerStreamingService - for DiscoverSvc { + impl + tonic::server::ServerStreamingService + for DiscoverSvc + { type Response = super::DiscoverResponse; type ResponseStream = T::DiscoverStream; - type Future = BoxFuture< - tonic::Response, - tonic::Status, - >; + type Future = + BoxFuture, tonic::Status>; fn call( &mut self, request: tonic::Request, @@ -695,18 +653,14 @@ pub mod discovery_handler_server { }; Box::pin(fut) } - _ => { - Box::pin(async move { - Ok( - http::Response::builder() - .status(200) - .header("grpc-status", "12") - .header("content-type", "application/grpc") - .body(empty_body()) - .unwrap(), - ) - }) - } + _ => Box::pin(async move { + Ok(http::Response::builder() + .status(200) + .header("grpc-status", "12") + .header("content-type", "application/grpc") + .body(empty_body()) + .unwrap()) + }), } } } diff --git a/samples/brokers/udev-video-broker/src/util/camera.rs b/samples/brokers/udev-video-broker/src/util/camera.rs index 4bd208251..437b09cd8 100644 --- a/samples/brokers/udev-video-broker/src/util/camera.rs +++ b/samples/brokers/udev-video-broker/src/util/camera.rs @@ -13,8 +13,8 @@ pub struct NotifyResponse { /// Generated client implementations. pub mod camera_client { #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] - use tonic::codegen::*; use tonic::codegen::http::Uri; + use tonic::codegen::*; #[derive(Debug, Clone)] pub struct CameraClient { inner: tonic::client::Grpc, @@ -58,9 +58,8 @@ pub mod camera_client { >::ResponseBody, >, >, - , - >>::Error: Into + Send + Sync, + >>::Error: + Into + Send + Sync, { CameraClient::new(InterceptedService::new(inner, interceptor)) } @@ -99,19 +98,17 @@ pub mod camera_client { &mut self, request: impl tonic::IntoRequest, ) -> std::result::Result, tonic::Status> { - self.inner - .ready() - .await - .map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + self.inner.ready().await.map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); let path = http::uri::PathAndQuery::from_static("/camera.Camera/GetFrame"); let mut req = request.into_request(); - req.extensions_mut().insert(GrpcMethod::new("camera.Camera", "GetFrame")); + req.extensions_mut() + .insert(GrpcMethod::new("camera.Camera", "GetFrame")); self.inner.unary(req, path, codec).await } } @@ -151,10 +148,7 @@ pub mod camera_server { max_encoding_message_size: None, } } - pub fn with_interceptor( - inner: T, - interceptor: F, - ) -> InterceptedService + pub fn with_interceptor(inner: T, interceptor: F) -> InterceptedService where F: tonic::service::Interceptor, { @@ -210,21 +204,16 @@ pub mod camera_server { "/camera.Camera/GetFrame" => { #[allow(non_camel_case_types)] struct GetFrameSvc(pub Arc); - impl tonic::server::UnaryService - for GetFrameSvc { + impl tonic::server::UnaryService for GetFrameSvc { type Response = super::NotifyResponse; - type Future = BoxFuture< - tonic::Response, - tonic::Status, - >; + type Future = BoxFuture, tonic::Status>; fn call( &mut self, request: tonic::Request, ) -> Self::Future { let inner = Arc::clone(&self.0); - let fut = async move { - ::get_frame(&inner, request).await - }; + let fut = + async move { ::get_frame(&inner, request).await }; Box::pin(fut) } } @@ -251,18 +240,14 @@ pub mod camera_server { }; Box::pin(fut) } - _ => { - Box::pin(async move { - Ok( - http::Response::builder() - .status(200) - .header("grpc-status", "12") - .header("content-type", "application/grpc") - .body(empty_body()) - .unwrap(), - ) - }) - } + _ => Box::pin(async move { + Ok(http::Response::builder() + .status(200) + .header("grpc-status", "12") + .header("content-type", "application/grpc") + .body(empty_body()) + .unwrap()) + }), } } } From e128934045d2812ef0fe604546ce0f4a575a184e Mon Sep 17 00:00:00 2001 From: Marcel Bindseil Date: Fri, 17 Jan 2025 17:06:03 +0100 Subject: [PATCH 04/19] fixed version Signed-off-by: Marcel Bindseil --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index 9c356d58a..8a642c7a3 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.13.9 +0.13.10 From bd46a4403dabc814b09c0e10c9c70482c6e287f7 Mon Sep 17 00:00:00 2001 From: Marcel Bindseil Date: Fri, 17 Jan 2025 17:10:07 +0100 Subject: [PATCH 05/19] updated helm chart version Signed-off-by: Marcel Bindseil --- deployment/helm/Chart.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deployment/helm/Chart.yaml b/deployment/helm/Chart.yaml index 8a1e7e9c8..a1ed5c1ec 100644 --- a/deployment/helm/Chart.yaml +++ b/deployment/helm/Chart.yaml @@ -16,9 +16,9 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.13.9 +version: 0.13.10 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. -appVersion: 0.13.9 +appVersion: 0.13.10 From 382d3b9f134bbdcf3d92ed889455f49e768345f5 Mon Sep 17 00:00:00 2001 From: Marcel Bindseil Date: Fri, 17 Jan 2025 17:21:40 +0100 Subject: [PATCH 06/19] updated rust version Signed-off-by: Marcel Bindseil --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index d8f4f7492..c24edff2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,5 +28,5 @@ edition = "2021" license = "Apache-2.0" homepage = "https://docs.akri.sh/" repository = "https://github.com/project-akri/akri" -rust-version = "1.79" +rust-version = "1.81" authors = ["The Akri Team"] \ No newline at end of file From 8802c884719c69c34199661de4acb330f1e8cd48 Mon Sep 17 00:00:00 2001 From: Marcel Bindseil Date: Fri, 17 Jan 2025 17:26:51 +0100 Subject: [PATCH 07/19] updated rust version to 1.84 Signed-off-by: Marcel Bindseil --- .github/workflows/check-rust.yml | 2 +- .github/workflows/run-tarpaulin.yml | 2 +- Cargo.toml | 2 +- README.md | 2 +- build/containers/Dockerfile.rust | 2 +- build/setup.sh | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/check-rust.yml b/.github/workflows/check-rust.yml index 96e3a1d43..6331a19e7 100644 --- a/.github/workflows/check-rust.yml +++ b/.github/workflows/check-rust.yml @@ -33,7 +33,7 @@ jobs: - name: Rust install uses: dtolnay/rust-toolchain@master with: - toolchain: 1.79.0 + toolchain: 1.84.0 components: clippy, rustfmt - name: Install Linux requirements # TODO: When ubuntu-latest gets updated to >= 23.04 replace the wget+unzip with just protobuf-compiler in apt diff --git a/.github/workflows/run-tarpaulin.yml b/.github/workflows/run-tarpaulin.yml index 94449d66a..66a2038b4 100644 --- a/.github/workflows/run-tarpaulin.yml +++ b/.github/workflows/run-tarpaulin.yml @@ -16,7 +16,7 @@ on: env: CARGO_TERM_COLOR: always - CARGO_VERSION: 1.79.0 + CARGO_VERSION: 1.84.0 jobs: build: diff --git a/Cargo.toml b/Cargo.toml index c24edff2b..c404c14a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,5 +28,5 @@ edition = "2021" license = "Apache-2.0" homepage = "https://docs.akri.sh/" repository = "https://github.com/project-akri/akri" -rust-version = "1.81" +rust-version = "1.84" authors = ["The Akri Team"] \ No newline at end of file diff --git a/README.md b/README.md index 51da88b47..438ba7d66 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@

Akri Logo

[![Slack channel #akri](https://img.shields.io/badge/slack-akri-blueviolet.svg?logo=slack)](https://kubernetes.slack.com/messages/akri) -[![Rust Version](https://img.shields.io/badge/rustc-1.79.0-blue.svg)](https://blog.rust-lang.org/2023/03/31/Rust-1.79.0.html) +[![Rust Version](https://img.shields.io/badge/rustc-1.84.0-blue.svg)](https://blog.rust-lang.org/2025/01/09/Rust-1.84.0.html) [![Kubernetes Version](https://img.shields.io/badge/kubernetes-≥%201.16-blue.svg)](https://kubernetes.io/) [![codecov](https://codecov.io/gh/project-akri/akri/branch/main/graph/badge.svg?token=V468HO7CDE)](https://codecov.io/gh/project-akri/akri) [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/5339/badge)](https://bestpractices.coreinfrastructure.org/projects/5339) diff --git a/build/containers/Dockerfile.rust b/build/containers/Dockerfile.rust index 0a021bbd1..3819a8c7a 100644 --- a/build/containers/Dockerfile.rust +++ b/build/containers/Dockerfile.rust @@ -1,6 +1,6 @@ FROM --platform=$BUILDPLATFORM tonistiigi/xx:master AS xx -FROM --platform=$BUILDPLATFORM rust:1.79-slim-bookworm AS build +FROM --platform=$BUILDPLATFORM rust:1.84-slim-bookworm AS build RUN rustup component add rustfmt RUN apt-get update && apt-get install -y clang lld protobuf-compiler pkg-config mmdebstrap wget COPY --from=xx / / diff --git a/build/setup.sh b/build/setup.sh index 06214e1dc..8ad221ad4 100755 --- a/build/setup.sh +++ b/build/setup.sh @@ -23,10 +23,10 @@ then if [ -x "$(command -v sudo)" ]; then echo "Install rustup" - sudo curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=1.79.0 + sudo curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=1.84.0 else echo "Install rustup" - curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=1.79.0 + curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=1.84.0 fi else echo "Found rustup" From 802f4b18dfa85d76e932d21b99cb9460c706cb8c Mon Sep 17 00:00:00 2001 From: Marcel Bindseil Date: Fri, 17 Jan 2025 18:05:43 +0100 Subject: [PATCH 08/19] fixed default for permissions Signed-off-by: Marcel Bindseil --- discovery-handlers/udev/src/discovery_handler.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discovery-handlers/udev/src/discovery_handler.rs b/discovery-handlers/udev/src/discovery_handler.rs index 0415b9f0c..191e95caf 100644 --- a/discovery-handlers/udev/src/discovery_handler.rs +++ b/discovery-handlers/udev/src/discovery_handler.rs @@ -31,7 +31,7 @@ pub struct UdevDiscoveryDetails { #[serde(default)] pub group_recursive: bool, - #[serde(default = "rwm")] + #[serde(default)] pub permissions: String, } From 9ebea3c66eebeed247475a48c8139790bf5201b4 Mon Sep 17 00:00:00 2001 From: Marcel Bindseil Date: Fri, 17 Jan 2025 18:07:29 +0100 Subject: [PATCH 09/19] added default func for permissions Signed-off-by: Marcel Bindseil --- discovery-handlers/udev/src/discovery_handler.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/discovery-handlers/udev/src/discovery_handler.rs b/discovery-handlers/udev/src/discovery_handler.rs index 191e95caf..d25ce6b60 100644 --- a/discovery-handlers/udev/src/discovery_handler.rs +++ b/discovery-handlers/udev/src/discovery_handler.rs @@ -31,10 +31,15 @@ pub struct UdevDiscoveryDetails { #[serde(default)] pub group_recursive: bool, - #[serde(default)] + #[serde(default = "default_permissions")] pub permissions: String, } +/// Default permissions for devices +fn default_permissions() -> String { + "rwm".to_string() +} + /// `DiscoveryHandlerImpl` discovers udev instances by parsing the udev rules in `discovery_handler_config.udev_rules`. pub struct DiscoveryHandlerImpl { register_sender: Option>, From 1939fbb8bbe7d0d69055916d0c4bf921297b7cfd Mon Sep 17 00:00:00 2001 From: Marcel Bindseil Date: Sat, 18 Jan 2025 13:26:30 +0100 Subject: [PATCH 10/19] updated rust version to 1.81 Signed-off-by: Marcel Bindseil --- .github/workflows/check-rust.yml | 2 +- .github/workflows/run-tarpaulin.yml | 2 +- Cargo.toml | 2 +- README.md | 2 +- build/containers/Dockerfile.rust | 2 +- build/setup.sh | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/check-rust.yml b/.github/workflows/check-rust.yml index 6331a19e7..0f0cd1275 100644 --- a/.github/workflows/check-rust.yml +++ b/.github/workflows/check-rust.yml @@ -33,7 +33,7 @@ jobs: - name: Rust install uses: dtolnay/rust-toolchain@master with: - toolchain: 1.84.0 + toolchain: 1.81.0 components: clippy, rustfmt - name: Install Linux requirements # TODO: When ubuntu-latest gets updated to >= 23.04 replace the wget+unzip with just protobuf-compiler in apt diff --git a/.github/workflows/run-tarpaulin.yml b/.github/workflows/run-tarpaulin.yml index 66a2038b4..2f8005b8b 100644 --- a/.github/workflows/run-tarpaulin.yml +++ b/.github/workflows/run-tarpaulin.yml @@ -16,7 +16,7 @@ on: env: CARGO_TERM_COLOR: always - CARGO_VERSION: 1.84.0 + CARGO_VERSION: 1.81.0 jobs: build: diff --git a/Cargo.toml b/Cargo.toml index c404c14a7..c24edff2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,5 +28,5 @@ edition = "2021" license = "Apache-2.0" homepage = "https://docs.akri.sh/" repository = "https://github.com/project-akri/akri" -rust-version = "1.84" +rust-version = "1.81" authors = ["The Akri Team"] \ No newline at end of file diff --git a/README.md b/README.md index 438ba7d66..252d2a703 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@

Akri Logo

[![Slack channel #akri](https://img.shields.io/badge/slack-akri-blueviolet.svg?logo=slack)](https://kubernetes.slack.com/messages/akri) -[![Rust Version](https://img.shields.io/badge/rustc-1.84.0-blue.svg)](https://blog.rust-lang.org/2025/01/09/Rust-1.84.0.html) +[![Rust Version](https://img.shields.io/badge/rustc-1.81.0-blue.svg)](https://blog.rust-lang.org/2025/01/09/Rust-1.81.0.html) [![Kubernetes Version](https://img.shields.io/badge/kubernetes-≥%201.16-blue.svg)](https://kubernetes.io/) [![codecov](https://codecov.io/gh/project-akri/akri/branch/main/graph/badge.svg?token=V468HO7CDE)](https://codecov.io/gh/project-akri/akri) [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/5339/badge)](https://bestpractices.coreinfrastructure.org/projects/5339) diff --git a/build/containers/Dockerfile.rust b/build/containers/Dockerfile.rust index 3819a8c7a..7a09d240c 100644 --- a/build/containers/Dockerfile.rust +++ b/build/containers/Dockerfile.rust @@ -1,6 +1,6 @@ FROM --platform=$BUILDPLATFORM tonistiigi/xx:master AS xx -FROM --platform=$BUILDPLATFORM rust:1.84-slim-bookworm AS build +FROM --platform=$BUILDPLATFORM rust:1.81-slim-bookworm AS build RUN rustup component add rustfmt RUN apt-get update && apt-get install -y clang lld protobuf-compiler pkg-config mmdebstrap wget COPY --from=xx / / diff --git a/build/setup.sh b/build/setup.sh index 8ad221ad4..cdb17ad6a 100755 --- a/build/setup.sh +++ b/build/setup.sh @@ -23,10 +23,10 @@ then if [ -x "$(command -v sudo)" ]; then echo "Install rustup" - sudo curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=1.84.0 + sudo curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=1.81.0 else echo "Install rustup" - curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=1.84.0 + curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=1.81.0 fi else echo "Found rustup" From 7639e8373d4d1caf65b02f6c3dbea149b597717f Mon Sep 17 00:00:00 2001 From: Marcel Bindseil Date: Wed, 22 Jan 2025 08:25:51 +0100 Subject: [PATCH 11/19] Update discovery-handlers/udev/src/discovery_handler.rs Co-authored-by: Kate Goldenring Signed-off-by: Marcel Bindseil --- .../udev/src/discovery_handler.rs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/discovery-handlers/udev/src/discovery_handler.rs b/discovery-handlers/udev/src/discovery_handler.rs index d25ce6b60..1e868cfb6 100644 --- a/discovery-handlers/udev/src/discovery_handler.rs +++ b/discovery-handlers/udev/src/discovery_handler.rs @@ -31,10 +31,30 @@ pub struct UdevDiscoveryDetails { #[serde(default)] pub group_recursive: bool, - #[serde(default = "default_permissions")] + #[serde(default = "default_permissions", )] + #[serde(deserialize_with = "validate_permissions")] pub permissions: String, } +// Validate the permissible set of cgroups `permissions` +fn validate_permissions<'de, D>(deserializer: D) -> Result +where + D: Deserializer<'de>, +{ + let value: String = Deserialize::deserialize(deserializer)?; + + // Validating that the string only contains allowed combinations of 'r', 'w', 'm' + let valid_permissions = ["r", "w", "m", "rw", "rm", "rwm", "mw"]; + if valid_permissions.contains(&value.as_str()) { + Ok(value) + } else { + Err(de::Error::invalid_value( + de::Unexpected::Str(&value), + &"a valid permission combination ('r', 'w', 'm', 'rw', 'rm', 'rwm', 'mw')", + )) + } +} + /// Default permissions for devices fn default_permissions() -> String { "rwm".to_string() From dcfe3060efe98d55601cf8a2812a30baff650c99 Mon Sep 17 00:00:00 2001 From: Marcel Bindseil Date: Wed, 22 Jan 2025 11:17:40 +0100 Subject: [PATCH 12/19] added unit test and added dependencies Signed-off-by: Marcel Bindseil --- .../udev/src/discovery_handler.rs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/discovery-handlers/udev/src/discovery_handler.rs b/discovery-handlers/udev/src/discovery_handler.rs index 1e868cfb6..52165e1ed 100644 --- a/discovery-handlers/udev/src/discovery_handler.rs +++ b/discovery-handlers/udev/src/discovery_handler.rs @@ -17,6 +17,7 @@ use std::time::Duration; use tokio::sync::mpsc; use tokio::time::sleep; use tonic::{Response, Status}; +use serde::{Deserialize, Deserializer, de}; // TODO: make this configurable pub const DISCOVERY_INTERVAL_SECS: u64 = 10; @@ -31,7 +32,7 @@ pub struct UdevDiscoveryDetails { #[serde(default)] pub group_recursive: bool, - #[serde(default = "default_permissions", )] + #[serde(default = "default_permissions")] #[serde(deserialize_with = "validate_permissions")] pub permissions: String, } @@ -44,13 +45,13 @@ where let value: String = Deserialize::deserialize(deserializer)?; // Validating that the string only contains allowed combinations of 'r', 'w', 'm' - let valid_permissions = ["r", "w", "m", "rw", "rm", "rwm", "mw"]; + let valid_permissions = ["r", "w", "m", "rw", "rm", "rwm", "wm"]; if valid_permissions.contains(&value.as_str()) { Ok(value) } else { Err(de::Error::invalid_value( de::Unexpected::Str(&value), - &"a valid permission combination ('r', 'w', 'm', 'rw', 'rm', 'rwm', 'mw')", + &"a valid permission combination ('r', 'w', 'm', 'rw', 'rm', 'rwm', 'wm')", )) } } @@ -209,6 +210,7 @@ mod tests { let expected_deserialized = r#"{"udevRules":[],"groupRecursive":false,"permissions":"rwm"}"#; assert_eq!(expected_deserialized, serialized); + } #[test] @@ -223,4 +225,16 @@ mod tests { assert_eq!(&udev_dh_config.udev_rules[0], "KERNEL==\"video[0-9]*\""); assert_eq!(&udev_dh_config.permissions, "rwm"); } + + #[test] + fn test_deserialize_discovery_details_permissions_invalid() { + let yaml = r#" + udevRules: + - 'KERNEL=="video[0-9]*"' + permissions: xyz + "#; + assert_eq!(deserialize_discovery_details(yaml).unwrap(), Err(de::Error::invalid_value( + de::Unexpected::Str(&value), + &"a valid permission combination ('r', 'w', 'm', 'rw', 'rm', 'rwm', 'wm')", + )));} } From e8ffe394dbddd237ce4b1da4b35203d4ae2545f3 Mon Sep 17 00:00:00 2001 From: Marcel Bindseil Date: Wed, 22 Jan 2025 13:15:39 +0100 Subject: [PATCH 13/19] test for permissions Signed-off-by: Marcel Bindseil --- .../udev/src/discovery_handler.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/discovery-handlers/udev/src/discovery_handler.rs b/discovery-handlers/udev/src/discovery_handler.rs index 52165e1ed..705853dad 100644 --- a/discovery-handlers/udev/src/discovery_handler.rs +++ b/discovery-handlers/udev/src/discovery_handler.rs @@ -12,12 +12,12 @@ use akri_discovery_utils::discovery::{ }; use async_trait::async_trait; use log::{error, info, trace}; +use serde::{de, Deserialize, Deserializer}; use std::collections::{HashMap, HashSet}; use std::time::Duration; use tokio::sync::mpsc; use tokio::time::sleep; use tonic::{Response, Status}; -use serde::{Deserialize, Deserializer, de}; // TODO: make this configurable pub const DISCOVERY_INTERVAL_SECS: u64 = 10; @@ -210,7 +210,6 @@ mod tests { let expected_deserialized = r#"{"udevRules":[],"groupRecursive":false,"permissions":"rwm"}"#; assert_eq!(expected_deserialized, serialized); - } #[test] @@ -227,14 +226,20 @@ mod tests { } #[test] + #[should_panic] fn test_deserialize_discovery_details_permissions_invalid() { let yaml = r#" udevRules: - 'KERNEL=="video[0-9]*"' permissions: xyz "#; - assert_eq!(deserialize_discovery_details(yaml).unwrap(), Err(de::Error::invalid_value( - de::Unexpected::Str(&value), - &"a valid permission combination ('r', 'w', 'm', 'rw', 'rm', 'rwm', 'wm')", - )));} + let config: UdevDiscoveryDetails = deserialize_discovery_details(yaml).unwrap(); + // assert_eq!( + // deserialize_discovery_details(yaml).unwrap(), + // Err(de::Error::invalid_value( + // de::Unexpected::Str(&value), + // &"a valid permission combination ('r', 'w', 'm', 'rw', 'rm', 'rwm', 'wm')", + // )) + // ); + } } From 462d649ce08fc2cc05d9eba58b3b8170be39ab3e Mon Sep 17 00:00:00 2001 From: Marcel Bindseil Date: Wed, 22 Jan 2025 13:35:08 +0100 Subject: [PATCH 14/19] removed unused var Signed-off-by: Marcel Bindseil --- discovery-handlers/udev/src/discovery_handler.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discovery-handlers/udev/src/discovery_handler.rs b/discovery-handlers/udev/src/discovery_handler.rs index 705853dad..bf0030ff8 100644 --- a/discovery-handlers/udev/src/discovery_handler.rs +++ b/discovery-handlers/udev/src/discovery_handler.rs @@ -233,7 +233,7 @@ mod tests { - 'KERNEL=="video[0-9]*"' permissions: xyz "#; - let config: UdevDiscoveryDetails = deserialize_discovery_details(yaml).unwrap(); + deserialize_discovery_details(yaml).unwrap(); // assert_eq!( // deserialize_discovery_details(yaml).unwrap(), // Err(de::Error::invalid_value( From c14d2fe03b156926ec49f114f3b6565d2ed0018e Mon Sep 17 00:00:00 2001 From: Marcel Bindseil Date: Wed, 22 Jan 2025 13:42:42 +0100 Subject: [PATCH 15/19] restructured test Signed-off-by: Marcel Bindseil --- discovery-handlers/udev/src/discovery_handler.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/discovery-handlers/udev/src/discovery_handler.rs b/discovery-handlers/udev/src/discovery_handler.rs index bf0030ff8..40f011b8c 100644 --- a/discovery-handlers/udev/src/discovery_handler.rs +++ b/discovery-handlers/udev/src/discovery_handler.rs @@ -233,13 +233,13 @@ mod tests { - 'KERNEL=="video[0-9]*"' permissions: xyz "#; - deserialize_discovery_details(yaml).unwrap(); - // assert_eq!( - // deserialize_discovery_details(yaml).unwrap(), - // Err(de::Error::invalid_value( - // de::Unexpected::Str(&value), - // &"a valid permission combination ('r', 'w', 'm', 'rw', 'rm', 'rwm', 'wm')", - // )) - // ); + let config: UdevDiscoveryDetails = deserialize_discovery_details(yaml).unwrap(); + assert_eq!( + config, + Err(de::Error::invalid_value( + de::Unexpected::Str(&value), + &"a valid permission combination ('r', 'w', 'm', 'rw', 'rm', 'rwm', 'wm')", + )) + ); } } From be86a9c5aac6b6354c45f59dd0db1e9548471f48 Mon Sep 17 00:00:00 2001 From: Marcel Bindseil Date: Wed, 22 Jan 2025 13:48:14 +0100 Subject: [PATCH 16/19] fixed test Signed-off-by: Marcel Bindseil --- discovery-handlers/udev/src/discovery_handler.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/discovery-handlers/udev/src/discovery_handler.rs b/discovery-handlers/udev/src/discovery_handler.rs index 40f011b8c..451522ef1 100644 --- a/discovery-handlers/udev/src/discovery_handler.rs +++ b/discovery-handlers/udev/src/discovery_handler.rs @@ -234,12 +234,6 @@ mod tests { permissions: xyz "#; let config: UdevDiscoveryDetails = deserialize_discovery_details(yaml).unwrap(); - assert_eq!( - config, - Err(de::Error::invalid_value( - de::Unexpected::Str(&value), - &"a valid permission combination ('r', 'w', 'm', 'rw', 'rm', 'rwm', 'wm')", - )) - ); + assert_eq!(&config.permissions, "xyz") } } From 0eb45b7114e6d0f1a998e0ea0df7c3d6db758fc1 Mon Sep 17 00:00:00 2001 From: Marcel Bindseil Date: Wed, 22 Jan 2025 14:25:14 +0100 Subject: [PATCH 17/19] added default permissions for lint files Signed-off-by: Marcel Bindseil --- test/helm-lint-values-jobs.yaml | 1 + test/helm-lint-values.yaml | 1 + test/yaml/akri-udev-video-configuration.yaml | 1 + 3 files changed, 3 insertions(+) diff --git a/test/helm-lint-values-jobs.yaml b/test/helm-lint-values-jobs.yaml index c83e0c836..00c1f01a4 100644 --- a/test/helm-lint-values-jobs.yaml +++ b/test/helm-lint-values-jobs.yaml @@ -22,6 +22,7 @@ udev: discoveryDetails: udevRules: - 'KERNEL=="video[0-9]*"' + permissions: "rwm" brokerJob: image: repository: "busybox" diff --git a/test/helm-lint-values.yaml b/test/helm-lint-values.yaml index b3e457802..424a6cd6d 100644 --- a/test/helm-lint-values.yaml +++ b/test/helm-lint-values.yaml @@ -22,6 +22,7 @@ udev: groupRecursive: true udevRules: - 'KERNEL=="video[0-9]*"' + permissions: "rwm" brokerPod: image: repository: "nginx" diff --git a/test/yaml/akri-udev-video-configuration.yaml b/test/yaml/akri-udev-video-configuration.yaml index ef95be2c8..29431fd1f 100644 --- a/test/yaml/akri-udev-video-configuration.yaml +++ b/test/yaml/akri-udev-video-configuration.yaml @@ -8,6 +8,7 @@ spec: discoveryDetails: |+ udevRules: - 'KERNEL=="video[0-9]*"' + permissions: "rwm" brokerSpec: brokerPodSpec: containers: From 444c209f49af6a994e7366858557e4bfff1cdbcc Mon Sep 17 00:00:00 2001 From: Marcel Bindseil Date: Wed, 22 Jan 2025 20:50:30 +0100 Subject: [PATCH 18/19] signoff Signed-off-by: Marcel Bindseil Signed-off-by: Marcel Bindseil --- discovery-handlers/udev/src/discovery_handler.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/discovery-handlers/udev/src/discovery_handler.rs b/discovery-handlers/udev/src/discovery_handler.rs index 451522ef1..fb5e16a1c 100644 --- a/discovery-handlers/udev/src/discovery_handler.rs +++ b/discovery-handlers/udev/src/discovery_handler.rs @@ -233,7 +233,9 @@ mod tests { - 'KERNEL=="video[0-9]*"' permissions: xyz "#; - let config: UdevDiscoveryDetails = deserialize_discovery_details(yaml).unwrap(); - assert_eq!(&config.permissions, "xyz") + match deserialize_discovery_details::(yaml) { + Ok(_) => panic!("Expected error parsing invalid permissions"), + Err(e) => assert!(e.to_string().contains("a valid permission combination")), + } } } From b2540f4286d53f88b28214d893bca735e60eb1f9 Mon Sep 17 00:00:00 2001 From: Marcel Bindseil Date: Wed, 22 Jan 2025 21:11:31 +0100 Subject: [PATCH 19/19] removed panic Signed-off-by: Marcel Bindseil --- discovery-handlers/udev/src/discovery_handler.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/discovery-handlers/udev/src/discovery_handler.rs b/discovery-handlers/udev/src/discovery_handler.rs index fb5e16a1c..21e49bd8e 100644 --- a/discovery-handlers/udev/src/discovery_handler.rs +++ b/discovery-handlers/udev/src/discovery_handler.rs @@ -226,7 +226,6 @@ mod tests { } #[test] - #[should_panic] fn test_deserialize_discovery_details_permissions_invalid() { let yaml = r#" udevRules: