Skip to content

Commit

Permalink
Merge pull request #653 from amazonlinux/ctrd-cfg-migration
Browse files Browse the repository at this point in the history
Add migration for changed containerd config template path
  • Loading branch information
tjkirch authored Jan 15, 2020
2 parents abdcef8 + 81e12f0 commit 356222b
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 6 deletions.
10 changes: 5 additions & 5 deletions RELEASE.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version = "0.2.0"
datastore_version = "0.1"
version = "0.2.1"
datastore_version = "0.2"

[[migrations]]
from = "0.1.6"
to = "0.2.0"
names = ["migrate_0.1_borkseed", "migrate_0.1_host-containers-version-migration"]
from = "0.2.0"
to = "0.2.1"
names = ["migrate_0.2_containerd-config-path"]
2 changes: 1 addition & 1 deletion packages/workspaces/data-store-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1
0.2
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 @@ -20,6 +20,7 @@ members = [
# workspace member when we add cross-workspace dependencies.
"api/migration/migrations/v0.1/borkseed",
"api/migration/migrations/v0.1/host-containers-version",
"api/migration/migrations/v0.2/containerd-config-path",

"models",

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "containerd-config-path"
version = "0.1.0"
authors = ["Tom Kirchner <[email protected]>"]
edition = "2018"
publish = false

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

use migration_helpers::{migrate, Migration, MigrationData, Result};
use std::process;

/// We changed the path to our containerd configuration template so that we could support image
/// variants with different configs. We need to update old images to the new path, and on
/// downgrade, new images to the old path.
struct ContainerdConfigPath;

const SETTING: &str = "configuration-files.containerd-config-toml.template-path";
// Old version with no variant
const DEFAULT_CTRD_CONFIG_OLD: &str = "/usr/share/templates/containerd-config-toml";
// Any users coming from old versions would be using the aws-k8s variant because no other existed :)
const DEFAULT_CTRD_CONFIG_NEW: &str = "/usr/share/templates/containerd-config-toml_aws-k8s";

impl Migration for ContainerdConfigPath {
fn forward(&mut self, mut input: MigrationData) -> Result<MigrationData> {
if let Some(cfg_path) = input.data.get_mut(SETTING) {
if cfg_path.as_str() == Some(DEFAULT_CTRD_CONFIG_OLD) {
*cfg_path = serde_json::Value::String(DEFAULT_CTRD_CONFIG_NEW.to_string());
}
}
Ok(input)
}

fn backward(&mut self, mut input: MigrationData) -> Result<MigrationData> {
if let Some(cfg_path) = input.data.get_mut(SETTING) {
if cfg_path.as_str() == Some(DEFAULT_CTRD_CONFIG_NEW) {
*cfg_path = serde_json::Value::String(DEFAULT_CTRD_CONFIG_OLD.to_string());
}
}
Ok(input)
}
}

fn run() -> Result<()> {
migrate(ContainerdConfigPath)
}

// 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 workspaces/deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ skip = [
{ name = "block-party", licenses = [] },
{ name = "bork", licenses = [] },
{ name = "borkseed-migration", licenses = [] },
{ name = "containerd-config-path", licenses = [] },
{ name = "data_store_version", licenses = [] },
{ name = "growpart", licenses = [] },
{ name = "host-containers", licenses = [] },
Expand Down

0 comments on commit 356222b

Please sign in to comment.