Skip to content

Commit

Permalink
Merge pull request #536 from amazonlinux/host-containers-version-migr…
Browse files Browse the repository at this point in the history
…ations

migrations: Adds new migration for bumping host container versions
  • Loading branch information
etungsten authored Nov 19, 2019
2 parents 91cb20a + a55cd4f commit deb1312
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
9 changes: 9 additions & 0 deletions workspaces/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 workspaces/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ members = [
# Migrations will be listed here. They won't need to be listed as a
# workspace member when we add cross-workspace dependencies.
"api/migration/migrations/v0.1/borkseed",
"api/migration/migrations/v0.1/host-containers-version",

"preinit/laika",

Expand Down
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"
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)
}
1 change: 1 addition & 0 deletions workspaces/deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ skip = [
{ name = "data_store_version", licenses = [] },
{ name = "growpart", licenses = [] },
{ name = "host-containers", licenses = [] },
{ name = "host-containers-version-migration", licenses = [] },
{ name = "laika", licenses = [] },
{ name = "migration-helpers", licenses = [] },
{ name = "migrator", licenses = [] },
Expand Down

0 comments on commit deb1312

Please sign in to comment.