From 6efbea0ec5f1f5438769dc8e7a94ac9cb59fe84d Mon Sep 17 00:00:00 2001 From: gakulkar Date: Tue, 18 Apr 2023 14:50:34 -0700 Subject: [PATCH 1/2] Rename ImagePruneSettings to Settings and ImagePruneData to ImageGarbageCollectionData --- edgelet/aziot-edged/src/main.rs | 4 ++-- .../edgelet-docker/src/image_prune_data.rs | 22 +++++++++---------- edgelet/edgelet-docker/src/lib.rs | 4 ++-- edgelet/edgelet-docker/src/runtime.rs | 6 ++--- edgelet/edgelet-image-cleanup/src/image_gc.rs | 10 ++++----- edgelet/edgelet-settings/src/base/image.rs | 12 +++++----- edgelet/edgelet-settings/src/base/mod.rs | 8 +++---- edgelet/edgelet-settings/src/docker/mod.rs | 2 +- edgelet/edgelet-test-utils/src/settings.rs | 2 +- edgelet/iotedge/src/config/import/mod.rs | 4 ++-- edgelet/iotedge/src/config/super_config.rs | 4 ++-- 11 files changed, 39 insertions(+), 39 deletions(-) diff --git a/edgelet/aziot-edged/src/main.rs b/edgelet/aziot-edged/src/main.rs index 5b02e00a782..d7ef9021757 100644 --- a/edgelet/aziot-edged/src/main.rs +++ b/edgelet/aziot-edged/src/main.rs @@ -12,7 +12,7 @@ mod workload_manager; use std::sync::atomic; use edgelet_core::{module::ModuleAction, ModuleRuntime, WatchdogAction}; -use edgelet_docker::{ImagePruneData, MakeModuleRuntime}; +use edgelet_docker::{ImageGarbageCollectionData, MakeModuleRuntime}; use edgelet_image_cleanup::image_gc; use edgelet_settings::RuntimeSettings; @@ -97,7 +97,7 @@ async fn run() -> Result<(), EdgedError> { let gc_settings = settings.image_garbage_collection().clone(); - let image_use_data = ImagePruneData::new(&gc_dir, gc_settings.clone()) + let image_use_data = ImageGarbageCollectionData::new(&gc_dir, gc_settings.clone()) .map_err(|err| EdgedError::from_err("Failed to set up image garbage collection", err))?; let runtime = edgelet_docker::DockerModuleRuntime::make_runtime( diff --git a/edgelet/edgelet-docker/src/image_prune_data.rs b/edgelet/edgelet-docker/src/image_prune_data.rs index 9eadd35c36e..4da1d5da8de 100644 --- a/edgelet/edgelet-docker/src/image_prune_data.rs +++ b/edgelet/edgelet-docker/src/image_prune_data.rs @@ -6,7 +6,7 @@ use std::sync::{Arc, Mutex}; use std::time::UNIX_EPOCH; use std::{collections::HashMap, collections::HashSet, fs, time::Duration}; -use edgelet_settings::base::image::ImagePruneSettings; +use edgelet_settings::base::image::Settings; use crate::Error; @@ -17,7 +17,7 @@ const TMP_FILENAME: &str = "image_use_tmp"; struct ImagePruneInner { image_use_filepath: String, tmp_filepath: String, - settings: ImagePruneSettings, + settings: Settings, } /// @@ -25,12 +25,12 @@ struct ImagePruneInner { /// feature. As such, this struct does not hold any user data, but simply holds information /// needed to collect/process state that (eventually) enables unused image garbage collection. #[derive(Debug, Clone)] -pub struct ImagePruneData { +pub struct ImageGarbageCollectionData { inner: Arc>, } -impl ImagePruneData { - pub fn new(homedir: &Path, settings: ImagePruneSettings) -> Result { +impl ImageGarbageCollectionData { + pub fn new(homedir: &Path, settings: Settings) -> Result { let fp: PathBuf = homedir.join(IMAGE_USE_FILENAME); let tmp_fp: PathBuf = homedir.join(TMP_FILENAME); @@ -283,7 +283,7 @@ mod tests { }; use chrono::{Timelike, Utc}; - use edgelet_settings::base::image::ImagePruneSettings; + use edgelet_settings::base::image::Settings; use nix::libc::sleep; use serial_test::serial; @@ -291,7 +291,7 @@ mod tests { image_prune_data::{ get_images_with_timestamp, process_state, IMAGE_USE_FILENAME, TMP_FILENAME, }, - ImagePruneData, + ImageGarbageCollectionData, }; use super::write_images_with_timestamp; @@ -311,13 +311,13 @@ mod tests { } std::fs::create_dir(Path::new(&test_file_dir)).unwrap(); - let settings = ImagePruneSettings::new( + let settings = Settings::new( Duration::from_secs(30), Duration::from_secs(10), curr_time, false, ); - let image_use_data = ImagePruneData::new(&test_file_dir, settings).unwrap(); + let image_use_data = ImageGarbageCollectionData::new(&test_file_dir, settings).unwrap(); // write new image image_use_data @@ -427,13 +427,13 @@ mod tests { ); let curr_time = (Utc::now().hour() * 60 + Utc::now().minute()).into(); - let settings = ImagePruneSettings::new( + let settings = Settings::new( Duration::from_secs(30), Duration::from_secs(5), curr_time, true, ); - let image_use_data = ImagePruneData::new(&test_file_dir, settings).unwrap(); + let image_use_data = ImageGarbageCollectionData::new(&test_file_dir, settings).unwrap(); let mut in_use_image_ids: HashSet = HashSet::new(); in_use_image_ids.insert( diff --git a/edgelet/edgelet-docker/src/lib.rs b/edgelet/edgelet-docker/src/lib.rs index 6fa5b70cda7..e89d435d2de 100644 --- a/edgelet/edgelet-docker/src/lib.rs +++ b/edgelet/edgelet-docker/src/lib.rs @@ -18,7 +18,7 @@ mod module; mod runtime; pub use error::Error; -pub use image_prune_data::ImagePruneData; +pub use image_prune_data::ImageGarbageCollectionData; pub use module::{DockerModule, MODULE_TYPE}; pub use runtime::{init_client, DockerModuleRuntime}; @@ -36,6 +36,6 @@ pub trait MakeModuleRuntime { async fn make_runtime( settings: &Self::Settings, create_socket_channel: UnboundedSender, - image_use_data: ImagePruneData, + image_use_data: ImageGarbageCollectionData, ) -> anyhow::Result; } diff --git a/edgelet/edgelet-docker/src/runtime.rs b/edgelet/edgelet-docker/src/runtime.rs index 1f1ae489117..c396dee4073 100644 --- a/edgelet/edgelet-docker/src/runtime.rs +++ b/edgelet/edgelet-docker/src/runtime.rs @@ -25,7 +25,7 @@ use http_common::Connector; use crate::error::Error; use crate::module::{runtime_state, DockerModule, MODULE_TYPE as DOCKER_MODULE_TYPE}; -use crate::{ImagePruneData, MakeModuleRuntime}; +use crate::{ImageGarbageCollectionData, MakeModuleRuntime}; type Deserializer = &'static mut serde_json::Deserializer>; @@ -41,7 +41,7 @@ pub struct DockerModuleRuntime { create_socket_channel: UnboundedSender, allow_elevated_docker_permissions: bool, additional_info: BTreeMap, - image_use_data: ImagePruneData, + image_use_data: ImageGarbageCollectionData, } fn merge_env(cur_env: Option<&[String]>, new_env: &BTreeMap) -> Vec { @@ -166,7 +166,7 @@ impl MakeModuleRuntime for DockerModuleRuntime { async fn make_runtime( settings: &Settings, create_socket_channel: UnboundedSender, - image_use_data: ImagePruneData, + image_use_data: ImageGarbageCollectionData, ) -> anyhow::Result { log::info!("Initializing module runtime..."); diff --git a/edgelet/edgelet-image-cleanup/src/image_gc.rs b/edgelet/edgelet-image-cleanup/src/image_gc.rs index acbbd510bd7..c115a6357e0 100644 --- a/edgelet/edgelet-image-cleanup/src/image_gc.rs +++ b/edgelet/edgelet-image-cleanup/src/image_gc.rs @@ -4,8 +4,8 @@ use std::{collections::HashSet, time::Duration}; use chrono::Timelike; use edgelet_core::{ModuleRegistry, ModuleRuntime}; -use edgelet_docker::ImagePruneData; -use edgelet_settings::base::image::ImagePruneSettings; +use edgelet_docker::ImageGarbageCollectionData; +use edgelet_settings::base::image::Settings; use crate::error::ImageCleanupError; @@ -22,9 +22,9 @@ const TOTAL_MINS_IN_DAY: u64 = 1440; /// Finally, it puts itself back to sleep till it's time for the next run. pub async fn image_garbage_collect( edge_agent_bootstrap: String, - settings: ImagePruneSettings, + settings: Settings, runtime: &edgelet_docker::DockerModuleRuntime, - image_use_data: ImagePruneData, + image_use_data: ImageGarbageCollectionData, ) -> Result<(), ImageCleanupError> { log::info!("Starting image garbage collection task..."); @@ -79,7 +79,7 @@ pub async fn image_garbage_collect( async fn remove_unused_images( runtime: &edgelet_docker::DockerModuleRuntime, - image_use_data: ImagePruneData, + image_use_data: ImageGarbageCollectionData, bootstrap_image_id_option: Option, ) -> Result<(), ImageCleanupError> { log::info!("Image Garbage Collection starting scheduled run"); diff --git a/edgelet/edgelet-settings/src/base/image.rs b/edgelet/edgelet-settings/src/base/image.rs index d93a816627b..c3cd94c9067 100644 --- a/edgelet/edgelet-settings/src/base/image.rs +++ b/edgelet/edgelet-settings/src/base/image.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; /// This struct is a wrapper for options that allow a user to override the defaults of /// the image gabage collection job and customize their settings. #[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)] -pub struct ImagePruneSettings { +pub struct Settings { #[serde( default = "default_cleanup_recurrence", deserialize_with = "validate_recurrence", @@ -28,14 +28,14 @@ pub struct ImagePruneSettings { enabled: bool, } -impl ImagePruneSettings { +impl Settings { pub fn new( cleanup_recurrence: Duration, image_age_cleanup_threshold: Duration, cleanup_time: u64, enabled: bool, - ) -> ImagePruneSettings { - ImagePruneSettings { + ) -> Settings { + Settings { cleanup_recurrence, image_age_cleanup_threshold, cleanup_time, @@ -128,9 +128,9 @@ mod hhmm_as_minutes { } } -impl Default for ImagePruneSettings { +impl Default for Settings { fn default() -> Self { - ImagePruneSettings { + Settings { cleanup_recurrence: default_cleanup_recurrence(), image_age_cleanup_threshold: default_image_age_cleanup_threshold(), cleanup_time: 0, diff --git a/edgelet/edgelet-settings/src/base/mod.rs b/edgelet/edgelet-settings/src/base/mod.rs index 2b990f2d7ce..8b143859a81 100644 --- a/edgelet/edgelet-settings/src/base/mod.rs +++ b/edgelet/edgelet-settings/src/base/mod.rs @@ -39,7 +39,7 @@ pub trait RuntimeSettings { fn additional_info(&self) -> &std::collections::BTreeMap; - fn image_garbage_collection(&self) -> &image::ImagePruneSettings; + fn image_garbage_collection(&self) -> &image::Settings; } #[derive(Clone, Debug, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize)] @@ -128,8 +128,8 @@ pub struct Settings { #[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")] pub additional_info: std::collections::BTreeMap, - #[serde(default, skip_serializing_if = "image::ImagePruneSettings::is_default")] - pub image_garbage_collection: image::ImagePruneSettings, + #[serde(default, skip_serializing_if = "image::Settings::is_default")] + pub image_garbage_collection: image::Settings, } pub(crate) fn default_allow_elevated_docker_permissions() -> bool { @@ -211,7 +211,7 @@ impl RuntimeSettings for Settings { &self.additional_info } - fn image_garbage_collection(&self) -> &image::ImagePruneSettings { + fn image_garbage_collection(&self) -> &image::Settings { &self.image_garbage_collection } } diff --git a/edgelet/edgelet-settings/src/docker/mod.rs b/edgelet/edgelet-settings/src/docker/mod.rs index e0233ef945a..1c9a896c03f 100644 --- a/edgelet/edgelet-settings/src/docker/mod.rs +++ b/edgelet/edgelet-settings/src/docker/mod.rs @@ -127,7 +127,7 @@ impl crate::RuntimeSettings for Settings { self.base.additional_info() } - fn image_garbage_collection(&self) -> &crate::base::image::ImagePruneSettings { + fn image_garbage_collection(&self) -> &crate::base::image::Settings { self.base.image_garbage_collection() } } diff --git a/edgelet/edgelet-test-utils/src/settings.rs b/edgelet/edgelet-test-utils/src/settings.rs index 7c5ab928b77..b565389bcdb 100644 --- a/edgelet/edgelet-test-utils/src/settings.rs +++ b/edgelet/edgelet-test-utils/src/settings.rs @@ -88,7 +88,7 @@ impl edgelet_settings::RuntimeSettings for Settings { unimplemented!() } - fn image_garbage_collection(&self) -> &edgelet_settings::base::image::ImagePruneSettings { + fn image_garbage_collection(&self) -> &edgelet_settings::base::image::Settings { unimplemented!() } } diff --git a/edgelet/iotedge/src/config/import/mod.rs b/edgelet/iotedge/src/config/import/mod.rs index beeedd19289..b6cb916265f 100644 --- a/edgelet/iotedge/src/config/import/mod.rs +++ b/edgelet/iotedge/src/config/import/mod.rs @@ -14,7 +14,7 @@ mod old_config; use std::path::{Path, PathBuf}; -use edgelet_settings::base::image::ImagePruneSettings; +use edgelet_settings::base::image::Settings; use edgelet_utils::YamlFileSource; use aziotctl_common::config as common_config; @@ -600,7 +600,7 @@ fn execute_inner( .transpose()?, } }, - image_garbage_collection: ImagePruneSettings::default(), + image_garbage_collection: Settings::default(), }; let config = diff --git a/edgelet/iotedge/src/config/super_config.rs b/edgelet/iotedge/src/config/super_config.rs index dbb063afda8..15f5e3567c8 100644 --- a/edgelet/iotedge/src/config/super_config.rs +++ b/edgelet/iotedge/src/config/super_config.rs @@ -63,8 +63,8 @@ pub struct Config { #[serde(default)] pub moby_runtime: MobyRuntime, - #[serde(default, skip_serializing_if = "image::ImagePruneSettings::is_default")] - pub image_garbage_collection: image::ImagePruneSettings, + #[serde(default, skip_serializing_if = "image::Settings::is_default")] + pub image_garbage_collection: image::Settings, } pub fn default_agent() -> edgelet_settings::ModuleSpec { From 57a5963bb8ae2f2b50285a967c5a82149ad35779 Mon Sep 17 00:00:00 2001 From: gakulkar Date: Tue, 18 Apr 2023 14:55:50 -0700 Subject: [PATCH 2/2] Rename image.rs to image_gc_settings.rs --- edgelet/edgelet-docker/src/image_prune_data.rs | 4 ++-- edgelet/edgelet-image-cleanup/src/image_gc.rs | 2 +- .../src/base/{image.rs => image_gc_settings.rs} | 0 edgelet/edgelet-settings/src/base/mod.rs | 13 ++++++++----- edgelet/edgelet-settings/src/docker/mod.rs | 2 +- edgelet/edgelet-test-utils/src/settings.rs | 2 +- edgelet/iotedge/src/config/import/mod.rs | 2 +- edgelet/iotedge/src/config/super_config.rs | 9 ++++++--- 8 files changed, 20 insertions(+), 14 deletions(-) rename edgelet/edgelet-settings/src/base/{image.rs => image_gc_settings.rs} (100%) diff --git a/edgelet/edgelet-docker/src/image_prune_data.rs b/edgelet/edgelet-docker/src/image_prune_data.rs index 4da1d5da8de..0421e620f06 100644 --- a/edgelet/edgelet-docker/src/image_prune_data.rs +++ b/edgelet/edgelet-docker/src/image_prune_data.rs @@ -6,7 +6,7 @@ use std::sync::{Arc, Mutex}; use std::time::UNIX_EPOCH; use std::{collections::HashMap, collections::HashSet, fs, time::Duration}; -use edgelet_settings::base::image::Settings; +use edgelet_settings::base::image_gc_settings::Settings; use crate::Error; @@ -283,7 +283,7 @@ mod tests { }; use chrono::{Timelike, Utc}; - use edgelet_settings::base::image::Settings; + use edgelet_settings::base::image_gc_settings::Settings; use nix::libc::sleep; use serial_test::serial; diff --git a/edgelet/edgelet-image-cleanup/src/image_gc.rs b/edgelet/edgelet-image-cleanup/src/image_gc.rs index c115a6357e0..5cd462a17a2 100644 --- a/edgelet/edgelet-image-cleanup/src/image_gc.rs +++ b/edgelet/edgelet-image-cleanup/src/image_gc.rs @@ -5,7 +5,7 @@ use std::{collections::HashSet, time::Duration}; use chrono::Timelike; use edgelet_core::{ModuleRegistry, ModuleRuntime}; use edgelet_docker::ImageGarbageCollectionData; -use edgelet_settings::base::image::Settings; +use edgelet_settings::base::image_gc_settings::Settings; use crate::error::ImageCleanupError; diff --git a/edgelet/edgelet-settings/src/base/image.rs b/edgelet/edgelet-settings/src/base/image_gc_settings.rs similarity index 100% rename from edgelet/edgelet-settings/src/base/image.rs rename to edgelet/edgelet-settings/src/base/image_gc_settings.rs diff --git a/edgelet/edgelet-settings/src/base/mod.rs b/edgelet/edgelet-settings/src/base/mod.rs index 8b143859a81..9315364975b 100644 --- a/edgelet/edgelet-settings/src/base/mod.rs +++ b/edgelet/edgelet-settings/src/base/mod.rs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. pub mod aziot; -pub mod image; +pub mod image_gc_settings; pub mod module; pub mod uri; pub mod watchdog; @@ -39,7 +39,7 @@ pub trait RuntimeSettings { fn additional_info(&self) -> &std::collections::BTreeMap; - fn image_garbage_collection(&self) -> &image::Settings; + fn image_garbage_collection(&self) -> &image_gc_settings::Settings; } #[derive(Clone, Debug, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize)] @@ -128,8 +128,11 @@ pub struct Settings { #[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")] pub additional_info: std::collections::BTreeMap, - #[serde(default, skip_serializing_if = "image::Settings::is_default")] - pub image_garbage_collection: image::Settings, + #[serde( + default, + skip_serializing_if = "image_gc_settings::Settings::is_default" + )] + pub image_garbage_collection: image_gc_settings::Settings, } pub(crate) fn default_allow_elevated_docker_permissions() -> bool { @@ -211,7 +214,7 @@ impl RuntimeSettings for Settings { &self.additional_info } - fn image_garbage_collection(&self) -> &image::Settings { + fn image_garbage_collection(&self) -> &image_gc_settings::Settings { &self.image_garbage_collection } } diff --git a/edgelet/edgelet-settings/src/docker/mod.rs b/edgelet/edgelet-settings/src/docker/mod.rs index 1c9a896c03f..208315167bb 100644 --- a/edgelet/edgelet-settings/src/docker/mod.rs +++ b/edgelet/edgelet-settings/src/docker/mod.rs @@ -127,7 +127,7 @@ impl crate::RuntimeSettings for Settings { self.base.additional_info() } - fn image_garbage_collection(&self) -> &crate::base::image::Settings { + fn image_garbage_collection(&self) -> &crate::base::image_gc_settings::Settings { self.base.image_garbage_collection() } } diff --git a/edgelet/edgelet-test-utils/src/settings.rs b/edgelet/edgelet-test-utils/src/settings.rs index b565389bcdb..918f26784ff 100644 --- a/edgelet/edgelet-test-utils/src/settings.rs +++ b/edgelet/edgelet-test-utils/src/settings.rs @@ -88,7 +88,7 @@ impl edgelet_settings::RuntimeSettings for Settings { unimplemented!() } - fn image_garbage_collection(&self) -> &edgelet_settings::base::image::Settings { + fn image_garbage_collection(&self) -> &edgelet_settings::base::image_gc_settings::Settings { unimplemented!() } } diff --git a/edgelet/iotedge/src/config/import/mod.rs b/edgelet/iotedge/src/config/import/mod.rs index b6cb916265f..9aab1f62755 100644 --- a/edgelet/iotedge/src/config/import/mod.rs +++ b/edgelet/iotedge/src/config/import/mod.rs @@ -14,7 +14,7 @@ mod old_config; use std::path::{Path, PathBuf}; -use edgelet_settings::base::image::Settings; +use edgelet_settings::base::image_gc_settings::Settings; use edgelet_utils::YamlFileSource; use aziotctl_common::config as common_config; diff --git a/edgelet/iotedge/src/config/super_config.rs b/edgelet/iotedge/src/config/super_config.rs index 15f5e3567c8..47a8aa2bb20 100644 --- a/edgelet/iotedge/src/config/super_config.rs +++ b/edgelet/iotedge/src/config/super_config.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; -use edgelet_settings::base::image; +use edgelet_settings::base::image_gc_settings; use url::Url; use aziotctl_common::config as common_config; @@ -63,8 +63,11 @@ pub struct Config { #[serde(default)] pub moby_runtime: MobyRuntime, - #[serde(default, skip_serializing_if = "image::Settings::is_default")] - pub image_garbage_collection: image::Settings, + #[serde( + default, + skip_serializing_if = "image_gc_settings::Settings::is_default" + )] + pub image_garbage_collection: image_gc_settings::Settings, } pub fn default_agent() -> edgelet_settings::ModuleSpec {