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

Add migration for changed containerd config template path #653

Merged
merged 1 commit into from
Jan 15, 2020
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
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"
tjkirch marked this conversation as resolved.
Show resolved Hide resolved
datastore_version = "0.2"

[[migrations]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While not directly related to this PR (and perhaps deserving of its own issue), do we want this migrations section to contain only the migrations for the current release? Or all migrations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had talked about it in a team meeting previously and decided it should only be for the current release, but I fully expect this file format to change quite a bit.

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