Skip to content

Commit

Permalink
Added option to enable spot instance draining
Browse files Browse the repository at this point in the history
Co-authored-by: Samuel Karp <samuelkarp@users.noreply.github.com>
  • Loading branch information
mkulke and samuelkarp committed Sep 2, 2020
1 parent 25acdb4 commit a9a4f9f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,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
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 @@ -90,6 +93,7 @@ fn run() -> Result<()> {
// Always supported with Docker newer than v17.11.0
// See https://github.com/docker/engine/commit/c7cc9d67590dd11343336c121e3629924a9894e9
override_awslogs_execution_role: true,
spot_instance_draining_enabled: ecs.enable_spot_instance_draining,
..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 = "add-enable-spot-instance-draining"
version = "0.1.0"
authors = ["Magnus Kulke <mkulke@gmail.com>"]
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 a9a4f9f

Please sign in to comment.