Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion edgelet/aziot-edged/src/watchdog.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

use edgelet_core::ModuleRuntime;
use edgelet_core::{Module, ModuleRuntime};
use edgelet_settings::RuntimeSettings;

use crate::error::Error as EdgedError;
Expand All @@ -24,6 +24,8 @@ pub(crate) async fn run_until_shutdown(
let shutdown_loop = shutdown_rx.recv();
futures_util::pin_mut!(shutdown_loop);

remove_old_edge_runtime(&settings, device_info, &runtime, identity_client).await?;

log::info!("Starting watchdog with 60 second period...");

loop {
Expand Down Expand Up @@ -69,6 +71,43 @@ pub(crate) async fn run_until_shutdown(
}
}

async fn remove_old_edge_runtime(
settings: &edgelet_settings::docker::Settings,
device_info: &aziot_identity_common::AzureIoTSpec,
runtime: &edgelet_docker::DockerModuleRuntime,
identity_client: &aziot_identity_client_async::Client,
) -> Result<(), EdgedError> {
let gen_id = agent_gen_id(identity_client).await?;
let new_env = agent_env(gen_id, settings, device_info);

let agent_name = settings.agent().name();
if let Ok((module, _)) = runtime.get(agent_name).await {
let config = module.config();
if let Some(envs) = config.create_options().env() {
for env in envs {
let env_split: Vec<&str> = env.split("=").collect();
if env_split.len() != 2 {
continue;
}
let cur_key = env_split[0];
let cur_value = env_split[1];
if let Some(new_value) = new_env.get(cur_key) {
if new_value != cur_value {
// Remove old edgeAgent only if edgeAgent's config changes.
log::info!("Remove old Edge runtime");
runtime.remove(agent_name).await.map_err(|err| {
EdgedError::from_err("Failed to remove old Edge runtime", err)
})?;
return Ok(());
}
}
}
}
}

Ok(())
}

async fn watchdog(
settings: &edgelet_settings::docker::Settings,
device_info: &aziot_identity_common::AzureIoTSpec,
Expand Down
4 changes: 4 additions & 0 deletions edgelet/edgelet-docker/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,10 @@ impl ModuleRuntime for DockerModuleRuntime {

create_options.set_labels(btree_labels);
}

if let Some(env) = config.env() {
create_options.set_env(env.to_vec());
}
}

let mut config = DockerConfig::new(
Expand Down