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

Add container images cleanup settings to API #3215

Merged
Merged
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,13 @@ Valid time units include `s`, `m`, and `h`, e.g. `1h`, `1m1s`.
* `settings.ecs.metadata-service-burst`: The burst rate limit of the throttling configurations set for the task metadata service.
* `settings.ecs.reserved-memory`: The amount of memory, in MiB, reserved for critical system processes.
* `settings.ecs.task-cleanup-wait`: Time to wait before the task's containers are removed after they are stopped.
Valid time units are `s`, `m`, and `h`, e.g. `1h`, `1m1s`.
* `settings.ecs.image-cleanup-wait`: Time to wait between image cleanup cycles.
Valid time units are `s`, `m`, and `h`, e.g. `1h`, `1m1s`.
* `settings.ecs.image-cleanup-delete-per-cycle`: Number of images to delete in a single image cleanup cycle.
* `settings.ecs.image-cleanup-enabled`: Enable automatic images clean up after the tasks have been removed.
Defaults to `false`
* `settings.ecs.image-cleanup-age`: Time since the image was pulled to be considered for clean up.
Valid time units are `s`, `m`, and `h`, e.g. `1h`, `1m1s`.

stmcginnis marked this conversation as resolved.
Show resolved Hide resolved
**Note**: `metadata-service-rps` and `metadata-service-burst` directly map to the values set by the `ECS_TASK_METADATA_RPS_LIMIT` environment variable.
Expand Down
6 changes: 6 additions & 0 deletions packages/ecs-agent/ecs.config
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ ECS_CONTAINER_STOP_TIMEOUT="{{settings.ecs.container-stop-timeout}}"
{{#if settings.ecs.task-cleanup-wait}}
ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION="{{settings.ecs.task-cleanup-wait}}"
{{/if}}
{{#if settings.ecs.image-cleanup-wait}}
ECS_IMAGE_CLEANUP_INTERVAL="{{settings.ecs.image-cleanup-wait}}"
{{/if}}
{{# if settings.ecs.image-cleanup-age}}
ECS_IMAGE_MINIMUM_CLEANUP_AGE="{{settings.ecs.image-cleanup-age}}"
{{/if}}
stmcginnis marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions sources/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sources/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ members = [
"api/migration/migrations/v1.14.0/public-admin-container-v0-10-1",
"api/migration/migrations/v1.14.0/aws-control-container-v0-7-2",
"api/migration/migrations/v1.14.0/public-control-container-v0-7-2",
"api/migration/migrations/v1.14.2/ecs-images-cleanup",

"bottlerocket-release",

Expand Down
10 changes: 10 additions & 0 deletions sources/api/ecs-settings-applier/src/ecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ struct ECSConfig {

#[serde(rename = "ReservedMemory", skip_serializing_if = "Option::is_none")]
reserved_memory: Option<u16>,

#[serde(
rename = "NumImagesToDeletePerCycle",
skip_serializing_if = "Option::is_none"
)]
image_cleanup_delete_per_cycle: Option<i64>,

image_cleanup_disabled: bool,
}

// Returning a Result from main makes it print a Debug representation of the error, but with Snafu
Expand Down Expand Up @@ -141,6 +149,8 @@ async fn run() -> Result<()> {
reserved_memory: ecs.reserved_memory,
metadata_service_rps: ecs.metadata_service_rps,
metadata_service_burst: ecs.metadata_service_burst,
image_cleanup_delete_per_cycle: ecs.image_cleanup_delete_per_cycle,
image_cleanup_disabled: !ecs.image_cleanup_enabled.unwrap_or(true),
..Default::default()
};
if let Some(os) = settings.os {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "ecs-images-cleanup"
version = "0.1.0"
edition = "2018"
authors = ["Arnaldo Garcia Rincon <[email protected]>"]
license = "Apache-2.0 OR MIT"
publish = false
# Don't rebuild crate just because of changes to README.
exclude = ["README.md"]

[dependencies]
migration-helpers = { path = "../../../migration-helpers", version = "0.1.0"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use migration_helpers::common_migrations::AddSettingsMigration;
use migration_helpers::{migrate, Result};
use std::process;

/// We added additional configurations for the ECS agent
fn run() -> Result<()> {
migrate(AddSettingsMigration(&[
"settings.ecs.image-cleanup-wait",
"settings.ecs.image-cleanup-delete-per-cycle",
"settings.ecs.image-cleanup-enabled",
"settings.ecs.image-cleanup-age",
]))
}

// Returning a Result from main makes it print a Debug representation of the error, but with Snafu
// we have nice Display representations of the error, so we wrap "main" (run) and print any error.
// https://github.com/shepmaster/snafu/issues/110
fn main() {
if let Err(e) = run() {
eprintln!("{}", e);
process::exit(1);
}
}
4 changes: 4 additions & 0 deletions sources/models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ struct ECSSettings {
metadata_service_rps: i64,
metadata_service_burst: i64,
reserved_memory: u16,
image_cleanup_wait: ECSDurationValue,
image_cleanup_delete_per_cycle: i64,
image_cleanup_enabled: bool,
image_cleanup_age: ECSDurationValue,
}

#[model]
Expand Down