Skip to content

Commit

Permalink
fix/feat: add duplicate envs without instance suffix
Browse files Browse the repository at this point in the history
Signed-off-by: Kate Goldenring <[email protected]>
  • Loading branch information
kate-goldenring committed Oct 25, 2024
1 parent 49eb225 commit f585b68
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions agent/src/plugin_manager/device_plugin_instance_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,16 +422,28 @@ fn cdi_device_to_car(device: &cdi::Device) -> ContainerAllocateResponse {
.last()
.unwrap_or_default()
.to_uppercase();

// Mount all device environment variables with and without a suffix of the
// instance hash. Envs without a suffix could be undeterministically
// overridden by other allocated instances discovered by the same Discovery
// Handler. Unsuffixed envs should only be referrenced if they are
// additional Configuration.broker_properties or if only one instance of a
// DH is allocated to the broker.
let envs = device
.container_edits
.env
.iter()
.map(|e| match e.split_once('=') {
Some((k, v)) => (k.to_string(), v.to_string()),
None => (e.to_string(), "".to_string()),
});

let suffixed_envs = envs
.clone()
.map(|(k, v)| (format!("{}_{}", k, instance_hash), v));

ContainerAllocateResponse {
envs: device
.container_edits
.env
.iter()
.map(|e| match e.split_once('=') {
Some((k, v)) => (format!("{}_{}", k, instance_hash), v.to_string()),
None => (format!("{}_{}", e, instance_hash), "".to_string()),
})
.collect(),
envs: envs.chain(suffixed_envs).collect(),
mounts: device
.container_edits
.mounts
Expand Down

0 comments on commit f585b68

Please sign in to comment.