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

Maintenance: rename a few structs and files for consistency with the rest of the codebase #7001

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions edgelet/aziot-edged/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand Down
22 changes: 11 additions & 11 deletions edgelet/edgelet-docker/src/image_prune_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_gc_settings::Settings;

use crate::Error;

Expand All @@ -17,20 +17,20 @@ const TMP_FILENAME: &str = "image_use_tmp";
struct ImagePruneInner {
image_use_filepath: String,
tmp_filepath: String,
settings: ImagePruneSettings,
settings: Settings,
}

/// <summary>
/// The methods associated with this struct are at the heart of the image garbage collection
/// 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<Mutex<ImagePruneInner>>,
}

impl ImagePruneData {
pub fn new(homedir: &Path, settings: ImagePruneSettings) -> Result<Self, Error> {
impl ImageGarbageCollectionData {
pub fn new(homedir: &Path, settings: Settings) -> Result<Self, Error> {
let fp: PathBuf = homedir.join(IMAGE_USE_FILENAME);
let tmp_fp: PathBuf = homedir.join(TMP_FILENAME);

Expand Down Expand Up @@ -283,15 +283,15 @@ mod tests {
};

use chrono::{Timelike, Utc};
use edgelet_settings::base::image::ImagePruneSettings;
use edgelet_settings::base::image_gc_settings::Settings;
use nix::libc::sleep;
use serial_test::serial;

use crate::{
image_prune_data::{
get_images_with_timestamp, process_state, IMAGE_USE_FILENAME, TMP_FILENAME,
},
ImagePruneData,
ImageGarbageCollectionData,
};

use super::write_images_with_timestamp;
Expand All @@ -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
Expand Down Expand Up @@ -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<String> = HashSet::new();
in_use_image_ids.insert(
Expand Down
4 changes: 2 additions & 2 deletions edgelet/edgelet-docker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -36,6 +36,6 @@ pub trait MakeModuleRuntime {
async fn make_runtime(
settings: &Self::Settings,
create_socket_channel: UnboundedSender<ModuleAction>,
image_use_data: ImagePruneData,
image_use_data: ImageGarbageCollectionData,
) -> anyhow::Result<Self::ModuleRuntime>;
}
6 changes: 3 additions & 3 deletions edgelet/edgelet-docker/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<serde_json::de::IoRead<std::io::Empty>>;

Expand All @@ -41,7 +41,7 @@ pub struct DockerModuleRuntime<C> {
create_socket_channel: UnboundedSender<ModuleAction>,
allow_elevated_docker_permissions: bool,
additional_info: BTreeMap<String, String>,
image_use_data: ImagePruneData,
image_use_data: ImageGarbageCollectionData,
}

fn merge_env(cur_env: Option<&[String]>, new_env: &BTreeMap<String, String>) -> Vec<String> {
Expand Down Expand Up @@ -166,7 +166,7 @@ impl MakeModuleRuntime for DockerModuleRuntime<Connector> {
async fn make_runtime(
settings: &Settings,
create_socket_channel: UnboundedSender<ModuleAction>,
image_use_data: ImagePruneData,
image_use_data: ImageGarbageCollectionData,
) -> anyhow::Result<Self::ModuleRuntime> {
log::info!("Initializing module runtime...");

Expand Down
10 changes: 5 additions & 5 deletions edgelet/edgelet-image-cleanup/src/image_gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_gc_settings::Settings;

use crate::error::ImageCleanupError;

Expand All @@ -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<http_common::Connector>,
image_use_data: ImagePruneData,
image_use_data: ImageGarbageCollectionData,
) -> Result<(), ImageCleanupError> {
log::info!("Starting image garbage collection task...");

Expand Down Expand Up @@ -79,7 +79,7 @@ pub async fn image_garbage_collect(

async fn remove_unused_images(
runtime: &edgelet_docker::DockerModuleRuntime<http_common::Connector>,
image_use_data: ImagePruneData,
image_use_data: ImageGarbageCollectionData,
bootstrap_image_id_option: Option<String>,
) -> Result<(), ImageCleanupError> {
log::info!("Image Garbage Collection starting scheduled run");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 8 additions & 5 deletions edgelet/edgelet-settings/src/base/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -39,7 +39,7 @@ pub trait RuntimeSettings {

fn additional_info(&self) -> &std::collections::BTreeMap<String, String>;

fn image_garbage_collection(&self) -> &image::ImagePruneSettings;
fn image_garbage_collection(&self) -> &image_gc_settings::Settings;
}

#[derive(Clone, Debug, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
Expand Down Expand Up @@ -128,8 +128,11 @@ pub struct Settings<ModuleConfig> {
#[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")]
pub additional_info: std::collections::BTreeMap<String, String>,

#[serde(default, skip_serializing_if = "image::ImagePruneSettings::is_default")]
pub image_garbage_collection: image::ImagePruneSettings,
#[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 {
Expand Down Expand Up @@ -211,7 +214,7 @@ impl<T: Clone> RuntimeSettings for Settings<T> {
&self.additional_info
}

fn image_garbage_collection(&self) -> &image::ImagePruneSettings {
fn image_garbage_collection(&self) -> &image_gc_settings::Settings {
&self.image_garbage_collection
}
}
2 changes: 1 addition & 1 deletion edgelet/edgelet-settings/src/docker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_gc_settings::Settings {
self.base.image_garbage_collection()
}
}
Expand Down
2 changes: 1 addition & 1 deletion edgelet/edgelet-test-utils/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_gc_settings::Settings {
unimplemented!()
}
}
4 changes: 2 additions & 2 deletions edgelet/iotedge/src/config/import/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod old_config;

use std::path::{Path, PathBuf};

use edgelet_settings::base::image::ImagePruneSettings;
use edgelet_settings::base::image_gc_settings::Settings;
use edgelet_utils::YamlFileSource;

use aziotctl_common::config as common_config;
Expand Down Expand Up @@ -600,7 +600,7 @@ fn execute_inner(
.transpose()?,
}
},
image_garbage_collection: ImagePruneSettings::default(),
image_garbage_collection: Settings::default(),
};

let config =
Expand Down
9 changes: 6 additions & 3 deletions edgelet/iotedge/src/config/super_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,8 +63,11 @@ 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_gc_settings::Settings::is_default"
)]
pub image_garbage_collection: image_gc_settings::Settings,
}

pub fn default_agent() -> edgelet_settings::ModuleSpec<edgelet_settings::DockerConfig> {
Expand Down