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

migrations: Adds new migration for bumping host container versions #536

Merged
merged 1 commit into from
Nov 19, 2019
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
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