Skip to content

Commit

Permalink
Merge pull request #1100 from mkulke/ecs-spot-instance-draining-option
Browse files Browse the repository at this point in the history
Added option to enable spot instance draining
  • Loading branch information
samuelkarp authored Sep 24, 2020
2 parents 87566b0 + 58493ad commit 17c1e29
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ These settings can be changed at any time.
Bottlerocket sets this value to false by default.
* `settings.ecs.loglevel`: The level of verbosity for the ECS agent's logs.
Supported values are `debug`, `info`, `warn`, `error`, and `crit`, and the default is `info`.
* `settings.ecs.enable-spot-instance-draining`: If the instance receives a spot termination notice, the agent will set the instance's state to `DRAINING`, so the workload can be moved gracefully before the instance is removed. Defaults to `false`.

#### Updates settings

Expand Down
3 changes: 2 additions & 1 deletion Release.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "1.0.1"
version = "1.0.2"

[migrations]
"(0.3.1, 0.3.2)" = ["migrate_v0.3.2_admin-container-v0-5-0.lz4"]
Expand All @@ -9,3 +9,4 @@ version = "1.0.1"
"(0.4.1, 0.5.0)" = ["migrate_v0.5.0_add-cluster-domain.lz4", "migrate_v0.5.0_admin-container-v0-5-2.lz4", "migrate_v0.5.0_control-container-v0-4-1.lz4"]
"(0.5.0, 1.0.0)" = ["migrate_v1.0.0_ecr-helper-admin.lz4", "migrate_v1.0.0_ecr-helper-control.lz4"]
"(1.0.0, 1.0.1)" = []
"(1.0.1, 1.0.2)" = ["migrate_v1.0.2_add-enable-spot-instance-draining.lz4"]
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 @@ -27,6 +27,7 @@ members = [
"api/migration/migrations/v0.5.0/add-cluster-domain",
"api/migration/migrations/v1.0.0/ecr-helper-admin",
"api/migration/migrations/v1.0.0/ecr-helper-control",
"api/migration/migrations/v1.0.2/add-enable-spot-instance-draining",

"bottlerocket-release",

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

#[serde(rename = "OverrideAWSLogsExecutionRole")]
override_awslogs_execution_role: bool,

#[serde(skip_serializing_if = "Option::is_none")]
spot_instance_draining_enabled: Option<bool>,
}

// Returning a Result from main makes it print a Debug representation of the error, but with Snafu
Expand Down Expand Up @@ -79,6 +82,7 @@ fn run() -> Result<()> {
.iter()
.map(|s| s.to_string())
.collect(),
spot_instance_draining_enabled: ecs.enable_spot_instance_draining,

// Task role support is always enabled
task_iam_role_enabled: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "add-enable-spot-instance-draining"
version = "0.1.0"
authors = ["Magnus Kulke <[email protected]>"]
license = "Apache-2.0 OR MIT"
edition = "2018"
publish = false
# Don't rebuild crate just because of changes to README.
exclude = ["README.md"]

[dependencies]
migration-helpers = { path = "../../../migration-helpers" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#![deny(rust_2018_idioms)]

use migration_helpers::common_migrations::AddSettingsMigration;
use migration_helpers::{migrate, Result};
use std::process;

/// We added a new setting, `ecs.enable-spot-instance-draining`
fn run() -> Result<()> {
migrate(AddSettingsMigration(&[
"settings.ecs.enable-spot-instance-draining",
]))
}

// 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);
}
}
1 change: 1 addition & 0 deletions sources/models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ struct ECSSettings {
allow_privileged_containers: bool,
logging_drivers: Vec<SingleLineString>,
loglevel: ECSAgentLogLevel,
enable_spot_instance_draining: bool,
}

// Update settings. Taken from userdata. The 'seed' setting is generated
Expand Down

0 comments on commit 17c1e29

Please sign in to comment.