Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create configuration level device plugin #565

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7f569ee
Set pre_start_required to false in get_device_plugin_options
johnsonshih Feb 28, 2023
c18de5d
Suffix usage slot to annotation key name
johnsonshih Feb 28, 2023
590e570
append hash of device usage id to device property key name
johnsonshih Feb 28, 2023
113ac77
Refine trait DevicePluginBuilderInterface
johnsonshih Mar 2, 2023
7813770
Change build_container_allocate_response to accept a list of devices
johnsonshih Mar 2, 2023
71b7ac6
decouple build_list_and_watch_response from DevicePluginService
johnsonshih Mar 2, 2023
e701738
extract function allocate_for_instance
johnsonshih Mar 2, 2023
c039107
save discovery device in InstanceInfo
johnsonshih Mar 3, 2023
2ffc366
Add usage_update_message_sender to DiscoveryOperator
johnsonshih Mar 3, 2023
23965ac
Add support for Configuration DevicePlugin
johnsonshih Mar 3, 2023
0582c50
Create configuration device plugin
johnsonshih Mar 3, 2023
1aebc5b
CHECK: do we need this semi colon?
johnsonshih Mar 3, 2023
5fc980e
DevicePluginService notify ConfigurationDevicePluginService about usa…
johnsonshih Mar 3, 2023
bcc848e
address clippy warnings
johnsonshih Mar 31, 2023
0b61fac
address clippy warning
johnsonshih Apr 5, 2023
0588b07
Merge branch 'main' into user/jshih/configuration-device-plugin
johnsonshih Apr 5, 2023
ee2e846
Merge branch 'main' into user/jshih/configuration-device-plugin
johnsonshih Apr 7, 2023
85051b3
Update patch version
github-actions[bot] Apr 10, 2023
8705cb3
Merge branch 'main' into user/jshih/configuration-device-plugin
johnsonshih May 17, 2023
7c55f75
refactor code, notify between Configuration and Instance device plugin
johnsonshih May 17, 2023
5f476ab
Update version
johnsonshih May 18, 2023
e7b9353
move definition of DevicePluginService struct to a better location
johnsonshih May 18, 2023
b45e95b
Merge branch 'main' into user/jshih/configuration-device-plugin
johnsonshih Jun 8, 2023
26d5307
use enum for device plugin type
johnsonshih Jun 8, 2023
d9da6a5
cargo fmt
johnsonshih Jun 8, 2023
b4badba
remove uniqueDevices
johnsonshih Jun 10, 2023
f73f342
Merge branch 'main' into user/jshih/configuration-device-plugin
johnsonshih Jun 14, 2023
9f3236e
move function to a different location
johnsonshih Jun 14, 2023
f52cbed
Merge branch 'main' into user/jshih/configuration-device-plugin
johnsonshih Jun 15, 2023
43c3c0a
clippy lint
johnsonshih Jun 15, 2023
61f500a
Merge branch 'user/jshih/configuration-device-plugin' of https://gith…
johnsonshih Jun 15, 2023
29bfb02
Use Default for InstanceConfig
johnsonshih Jun 16, 2023
0aa9783
Check conflict and bail out when updating instance
johnsonshih Jun 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 14 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.10.13"
version = "0.11.0"
authors = ["Kate Goldenring <kate.goldenring@microsoft.com>", "<bfjelds@microsoft.com>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down
19 changes: 11 additions & 8 deletions agent/src/util/config_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::{
DISCOVERY_OPERATOR_STOP_DISCOVERY_CHANNEL_CAPACITY,
},
device_plugin_service,
device_plugin_service::InstanceMap,
device_plugin_service::{InstanceConfig, InstanceMap},
discovery_operator::start_discovery::{start_discovery, DiscoveryOperator},
registration::RegisteredDiscoveryHandlerMap,
};
Expand Down Expand Up @@ -252,7 +252,7 @@ async fn handle_config_add(
config.metadata.name.clone().unwrap(),
);
// Create a new instance map for this config and add it to the config map
let instance_map: InstanceMap = Arc::new(RwLock::new(HashMap::new()));
let instance_map: InstanceMap = Arc::new(RwLock::new(InstanceConfig::default()));
let (stop_discovery_sender, _): (broadcast::Sender<()>, broadcast::Receiver<()>) =
broadcast::channel(DISCOVERY_OPERATOR_STOP_DISCOVERY_CHANNEL_CAPACITY);
let (mut finished_discovery_sender, finished_discovery_receiver) =
Expand Down Expand Up @@ -345,7 +345,10 @@ async fn handle_config_delete(
.clone();
config_map_locked.remove(&config_id);
}
delete_all_instances_in_map(kube_interface, instance_map, config_id).await?;
delete_all_instances_in_map(kube_interface, instance_map.clone(), config_id).await?;
if let Some(sender) = &instance_map.read().await.usage_update_message_sender {
sender.send(device_plugin_service::ListAndWatchMessageKind::End)?;
}
Ok(())
}

Expand Down Expand Up @@ -382,7 +385,7 @@ pub async fn delete_all_instances_in_map(
) -> anyhow::Result<()> {
let mut instance_map_locked = instance_map.write().await;
let instances_to_delete_map = instance_map_locked.clone();
for (instance_name, instance_info) in instances_to_delete_map {
for (instance_name, instance_info) in instances_to_delete_map.instances {
trace!(
"handle_config_delete - found Instance {} associated with deleted config {:?} ... sending message to end list_and_watch",
instance_name,
Expand All @@ -392,7 +395,7 @@ pub async fn delete_all_instances_in_map(
.list_and_watch_message_sender
.send(device_plugin_service::ListAndWatchMessageKind::End)
.unwrap();
instance_map_locked.remove(&instance_name);
instance_map_locked.instances.remove(&instance_name);
try_delete_instance(kube_interface, &instance_name, namespace.as_str()).await?;
}
Ok(())
Expand Down Expand Up @@ -518,7 +521,7 @@ mod config_action_tests {
futures::future::join_all(tasks).await;

// Assert that all instances have been removed from the instance map
assert_eq!(instance_map.read().await.len(), 0);
assert_eq!(instance_map.read().await.instances.len(), 0);
}

#[tokio::test]
Expand Down Expand Up @@ -583,7 +586,7 @@ mod config_action_tests {
futures::future::join_all(tasks).await;

// Assert that all instances have been removed from the instance map
assert_eq!(instance_map.read().await.len(), 0);
assert_eq!(instance_map.read().await.instances.len(), 0);
}

// Tests that when a Configuration is updated,
Expand Down Expand Up @@ -640,7 +643,7 @@ mod config_action_tests {
let (_, finished_discovery_receiver) = mpsc::channel(2);

let config_info = ConfigInfo {
instance_map: Arc::new(RwLock::new(HashMap::new())),
instance_map: Arc::new(RwLock::new(InstanceConfig::default())),
stop_discovery_sender: stop_discovery_sender.clone(),
finished_discovery_receiver,
last_generation: Some(1),
Expand Down
43 changes: 41 additions & 2 deletions agent/src/util/device_plugin_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use super::{
KUBELET_SOCKET, LIST_AND_WATCH_MESSAGE_CHANNEL_CAPACITY,
},
device_plugin_service::{
DevicePluginBehavior, DevicePluginService, InstanceDevicePlugin, InstanceMap,
ListAndWatchMessageKind,
ConfigurationDevicePlugin, DevicePluginBehavior, DevicePluginService, InstanceDevicePlugin,
InstanceMap, ListAndWatchMessageKind,
},
v1beta1,
v1beta1::{
Expand Down Expand Up @@ -45,6 +45,16 @@ pub trait DevicePluginBuilderInterface: Send + Sync {
instance_map: InstanceMap,
device: Device,
) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>;

async fn build_configuration_device_plugin(
&self,
device_plugin_name: String,
config: &Configuration,
instance_map: InstanceMap,
) -> Result<
broadcast::Sender<ListAndWatchMessageKind>,
Box<dyn std::error::Error + Send + Sync + 'static>,
>;
}

/// For each Instance, builds a Device Plugin, registers it with the kubelet, and serves it over UDS.
Expand Down Expand Up @@ -79,6 +89,35 @@ impl DevicePluginBuilderInterface for DevicePluginBuilder {
)
.await
}

/// This creates a new ConfigurationDevicePluginService for a Configuration and registers it with the kubelet
async fn build_configuration_device_plugin(
&self,
device_plugin_name: String,
config: &Configuration,
instance_map: InstanceMap,
) -> Result<
broadcast::Sender<ListAndWatchMessageKind>,
Box<dyn std::error::Error + Send + Sync + 'static>,
> {
info!(
"build_configuration_device_plugin - entered for device {}",
device_plugin_name
);
let device_plugin_behavior =
DevicePluginBehavior::Configuration(ConfigurationDevicePlugin {});
let (list_and_watch_message_sender, _) =
broadcast::channel(LIST_AND_WATCH_MESSAGE_CHANNEL_CAPACITY);
self.build_device_plugin_service(
&device_plugin_name,
config,
instance_map,
device_plugin_behavior,
list_and_watch_message_sender.clone(),
)
.await?;
Ok(list_and_watch_message_sender)
}
}

impl DevicePluginBuilder {
Expand Down