-
Notifications
You must be signed in to change notification settings - Fork 516
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 #653 from amazonlinux/ctrd-cfg-migration
Add migration for changed containerd config template path
- Loading branch information
Showing
7 changed files
with
77 additions
and
6 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -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"] |
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 |
---|---|---|
@@ -1 +1 @@ | ||
0.1 | ||
0.2 |
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.2/containerd-config-path/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 = "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" |
49 changes: 49 additions & 0 deletions
49
workspaces/api/migration/migrations/v0.2/containerd-config-path/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,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); | ||
} | ||
} |
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