Skip to content

Commit

Permalink
Merge pull request #561 from johnsonshih/user/jshih/device-plugin-env…
Browse files Browse the repository at this point in the history
…-var

Append hash of device usage id to device property key name
  • Loading branch information
yujinkim-msft authored Apr 7, 2023
2 parents 3477694 + 69c29b6 commit 8125977
Show file tree
Hide file tree
Showing 28 changed files with 162 additions and 57 deletions.
29 changes: 15 additions & 14 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion agent/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "agent"
version = "0.9.5"
version = "0.10.0"
authors = ["Kate Goldenring <[email protected]>", "<[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
3 changes: 3 additions & 0 deletions agent/src/util/device_plugin_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub trait DevicePluginBuilderInterface: Send + Sync {
async fn build_device_plugin(
&self,
instance_name: String,
instance_id: String,
config: &Configuration,
shared: bool,
instance_map: InstanceMap,
Expand Down Expand Up @@ -65,6 +66,7 @@ impl DevicePluginBuilderInterface for DevicePluginBuilder {
async fn build_device_plugin(
&self,
instance_name: String,
instance_id: String,
config: &Configuration,
shared: bool,
instance_map: InstanceMap,
Expand All @@ -85,6 +87,7 @@ impl DevicePluginBuilderInterface for DevicePluginBuilder {
mpsc::channel(DEVICE_PLUGIN_SERVER_ENDER_CHANNEL_CAPACITY);
let device_plugin_service = DevicePluginService {
instance_name: instance_name.clone(),
instance_id: instance_id.clone(),
endpoint: device_endpoint.clone(),
config: config.spec.clone(),
config_name: config.metadata.name.clone().unwrap(),
Expand Down
30 changes: 27 additions & 3 deletions agent/src/util/device_plugin_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ pub type InstanceMap = Arc<RwLock<HashMap<String, InstanceInfo>>>;
pub struct DevicePluginService {
/// Instance CRD name
pub instance_name: String,
/// Instance hash id
pub instance_id: String,
/// Socket endpoint
pub endpoint: String,
/// Instance's Configuration
Expand Down Expand Up @@ -280,6 +282,8 @@ impl DevicePluginService {
kube_interface: Arc<impl KubeInterface>,
) -> Result<Response<AllocateResponse>, Status> {
let mut container_responses: Vec<v1beta1::ContainerAllocateResponse> = Vec::new();
// suffix to add to each device property
let device_property_suffix = self.instance_id.to_uppercase();

for request in requests.into_inner().container_requests {
trace!(
Expand All @@ -288,6 +292,7 @@ impl DevicePluginService {
request,
);
let mut akri_annotations = HashMap::new();
let mut akri_device_properties = HashMap::new();
for device_usage_id in request.devices_i_ds {
trace!(
"internal_allocate - for Instance {} processing request for device usage slot id {}",
Expand All @@ -300,6 +305,20 @@ impl DevicePluginService {
device_usage_id.clone(),
);

// add suffix _<instance_id> to each device property
let converted_properties = self
.device
.properties
.iter()
.map(|(key, value)| {
(
format!("{}_{}", key, &device_property_suffix),
value.to_string(),
)
})
.collect::<HashMap<String, String>>();
akri_device_properties.extend(converted_properties);

if let Err(e) = try_update_instance_device_usage(
&device_usage_id,
&self.node_name,
Expand All @@ -324,7 +343,7 @@ impl DevicePluginService {
// Successfully reserved device_usage_slot[s] for this node.
// Add response to list of responses
let broker_properties =
get_all_broker_properties(&self.config.broker_properties, &self.device.properties);
get_all_broker_properties(&self.config.broker_properties, &akri_device_properties);
let response = build_container_allocate_response(
broker_properties,
akri_annotations,
Expand Down Expand Up @@ -829,11 +848,12 @@ mod device_plugin_service_tests {
add_to_instance_map: bool,
) -> (DevicePluginService, DevicePluginServiceReceivers) {
let path_to_config = "../test/yaml/config-a.yaml";
let instance_id = "b494b6";
let kube_akri_config_yaml =
fs::read_to_string(path_to_config).expect("Unable to read file");
let kube_akri_config: Configuration = serde_yaml::from_str(&kube_akri_config_yaml).unwrap();
let config_name = kube_akri_config.metadata.name.as_ref().unwrap();
let device_instance_name = get_device_instance_name("b494b6", config_name);
let device_instance_name = get_device_instance_name(instance_id, config_name);
let unique_time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH);
let device_endpoint: String = format!(
"{}-{}.sock",
Expand Down Expand Up @@ -863,6 +883,7 @@ mod device_plugin_service_tests {
};
let dps = DevicePluginService {
instance_name: device_instance_name,
instance_id: instance_id.to_uppercase(),
endpoint: device_endpoint,
config: kube_akri_config.spec.clone(),
config_name: config_name.to_string(),
Expand Down Expand Up @@ -1379,7 +1400,10 @@ mod device_plugin_service_tests {
assert_eq!(broker_envs.get("RESOLUTION_HEIGHT").unwrap(), "600");
// Check that Device properties are set as env vars by checking for
// property of device created in `create_device_plugin_service`
assert_eq!(broker_envs.get("DEVICE_LOCATION_INFO").unwrap(), "endpoint");
assert_eq!(
broker_envs.get("DEVICE_LOCATION_INFO_B494B6").unwrap(),
"endpoint"
);
assert!(device_plugin_service_receivers
.list_and_watch_message_receiver
.try_recv()
Expand Down
3 changes: 2 additions & 1 deletion agent/src/util/discovery_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ impl DiscoveryOperator {
if let Err(e) = device_plugin_builder
.build_device_plugin(
instance_name,
id,
&self.config,
shared,
instance_map,
Expand Down Expand Up @@ -1146,7 +1147,7 @@ pub mod tests {
mock_device_plugin_builder
.expect_build_device_plugin()
.times(2)
.returning(move |_, _, _, _, _| Ok(()));
.returning(move |_, _, _, _, _, _| Ok(()));
discovery_operator
.handle_discovery_results(
mock_kube_interface,
Expand Down
2 changes: 1 addition & 1 deletion controller/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "controller"
version = "0.9.5"
version = "0.10.0"
authors = ["<[email protected]>", "<[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
4 changes: 2 additions & 2 deletions deployment/helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,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.9.5
version: 0.10.0

# 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.9.5
appVersion: 0.10.0
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "debug-echo-discovery-handler"
version = "0.9.5"
version = "0.10.0"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "onvif-discovery-handler"
version = "0.9.5"
version = "0.10.0"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "opcua-discovery-handler"
version = "0.9.5"
version = "0.10.0"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "udev-discovery-handler"
version = "0.9.5"
version = "0.10.0"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
2 changes: 1 addition & 1 deletion discovery-handlers/debug-echo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "akri-debug-echo"
version = "0.9.5"
version = "0.10.0"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
2 changes: 1 addition & 1 deletion discovery-handlers/onvif/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "akri-onvif"
version = "0.9.5"
version = "0.10.0"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
2 changes: 1 addition & 1 deletion discovery-handlers/opcua/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "akri-opcua"
version = "0.9.5"
version = "0.10.0"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
2 changes: 1 addition & 1 deletion discovery-handlers/udev/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "akri-udev"
version = "0.9.5"
version = "0.10.0"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
2 changes: 1 addition & 1 deletion discovery-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "akri-discovery-utils"
version = "0.9.5"
version = "0.10.0"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.63.0"
Expand Down
Loading

0 comments on commit 8125977

Please sign in to comment.