-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #536 from amazonlinux/host-containers-version-migr…
…ations migrations: Adds new migration for bumping host container versions
- Loading branch information
Showing
5 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
workspaces/api/migration/migrations/v0.1/host-containers-version/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "host-containers-version-migration" | ||
version = "0.1.0" | ||
authors = ["Erikson Tung <[email protected]>"] | ||
edition = "2018" | ||
publish = false | ||
|
||
[dependencies] | ||
migration-helpers = { path = "../../../migration-helpers" } | ||
serde_json = "1.0" | ||
snafu = "0.5" |
63 changes: 63 additions & 0 deletions
63
workspaces/api/migration/migrations/v0.1/host-containers-version/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#![deny(rust_2018_idioms)] | ||
|
||
use migration_helpers::{migrate, Migration, MigrationData, Result}; | ||
|
||
/// We bumped the versions of the default admin container and the default control container from v0.1 to v0.2 | ||
struct HostContainersVersionMigration; | ||
const DEFAULT_ADMIN_CTR_IMG_OLD: &str = | ||
"328549459982.dkr.ecr.us-west-2.amazonaws.com/thar-admin:v0.1"; | ||
const DEFAULT_ADMIN_CTR_IMG_NEW: &str = | ||
"328549459982.dkr.ecr.us-west-2.amazonaws.com/thar-admin:v0.2"; | ||
const DEFAULT_CONTROL_CTR_IMG_OLD: &str = | ||
"328549459982.dkr.ecr.us-west-2.amazonaws.com/thar-control:v0.1"; | ||
const DEFAULT_CONTROL_CTR_IMG_NEW: &str = | ||
"328549459982.dkr.ecr.us-west-2.amazonaws.com/thar-control:v0.2"; | ||
|
||
impl Migration for HostContainersVersionMigration { | ||
fn forward(&mut self, mut input: MigrationData) -> Result<MigrationData> { | ||
if let Some(admin_ctr_source) = input.data.get_mut("settings.host-containers.admin.source") | ||
{ | ||
// Need to bump versions if the default admin container version source matches its older version | ||
if admin_ctr_source.as_str() == Some(DEFAULT_ADMIN_CTR_IMG_OLD) { | ||
*admin_ctr_source = | ||
serde_json::Value::String(DEFAULT_ADMIN_CTR_IMG_NEW.to_string()); | ||
} | ||
} | ||
if let Some(control_ctr_source) = input | ||
.data | ||
.get_mut("settings.host-containers.control.source") | ||
{ | ||
// Need to bump versions if the default control container version source matches its older version | ||
if control_ctr_source.as_str() == Some(DEFAULT_CONTROL_CTR_IMG_OLD) { | ||
*control_ctr_source = | ||
serde_json::Value::String(DEFAULT_CONTROL_CTR_IMG_NEW.to_string()); | ||
} | ||
} | ||
Ok(input) | ||
} | ||
|
||
fn backward(&mut self, mut input: MigrationData) -> Result<MigrationData> { | ||
if let Some(admin_ctr_source) = input.data.get_mut("settings.host-containers.admin.source") | ||
{ | ||
// The default admin container v0.2 image needs OS changes adding persistent host container storage | ||
if admin_ctr_source.as_str() == Some(DEFAULT_ADMIN_CTR_IMG_NEW) { | ||
*admin_ctr_source = | ||
serde_json::Value::String(DEFAULT_ADMIN_CTR_IMG_OLD.to_string()); | ||
} | ||
} | ||
if let Some(control_ctr_source) = input | ||
.data | ||
.get_mut("settings.host-containers.control.source") | ||
{ | ||
if control_ctr_source.as_str() == Some(DEFAULT_CONTROL_CTR_IMG_NEW) { | ||
*control_ctr_source = | ||
serde_json::Value::String(DEFAULT_CONTROL_CTR_IMG_OLD.to_string()); | ||
} | ||
} | ||
Ok(input) | ||
} | ||
} | ||
|
||
fn main() -> Result<()> { | ||
migrate(HostContainersVersionMigration) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters