From de6926b7d841bffd648523eb89d55b57178cc3fc Mon Sep 17 00:00:00 2001 From: Erikson Tung Date: Tue, 16 Feb 2021 10:41:34 -0800 Subject: [PATCH] migrations: add `add-static-pods` migration Adds a new migration for new k8s static-pods settings --- Release.toml | 2 +- sources/Cargo.lock | 7 ++++++ sources/Cargo.toml | 1 + .../v1.0.6/add-static-pods/Cargo.toml | 12 ++++++++++ .../v1.0.6/add-static-pods/src/main.rs | 24 +++++++++++++++++++ 5 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 sources/api/migration/migrations/v1.0.6/add-static-pods/Cargo.toml create mode 100644 sources/api/migration/migrations/v1.0.6/add-static-pods/src/main.rs diff --git a/Release.toml b/Release.toml index 317c3971ae0..01e66888a45 100644 --- a/Release.toml +++ b/Release.toml @@ -20,5 +20,5 @@ version = "1.0.5" "migrate_v1.0.5_add-proxy-restart.lz4", "migrate_v1.0.5_add-proxy-services.lz4" ] -"(1.0.5, 1.0.6)" = ["migrate_v1.0.6_metricdog-init.lz4"] +"(1.0.5, 1.0.6)" = ["migrate_v1.0.6_metricdog-init.lz4", "migrate_v1.0.6_add-static-pods.lz4"] diff --git a/sources/Cargo.lock b/sources/Cargo.lock index 7b2bf635cb5..5e4dfac2ef9 100644 --- a/sources/Cargo.lock +++ b/sources/Cargo.lock @@ -301,6 +301,13 @@ dependencies = [ "migration-helpers", ] +[[package]] +name = "add-static-pods" +version = "0.1.0" +dependencies = [ + "migration-helpers", +] + [[package]] name = "add-sysctl" version = "0.1.0" diff --git a/sources/Cargo.toml b/sources/Cargo.toml index e97d192f503..f9219de9028 100644 --- a/sources/Cargo.toml +++ b/sources/Cargo.toml @@ -39,6 +39,7 @@ members = [ "api/migration/migrations/v1.0.5/add-proxy-restart", "api/migration/migrations/v1.0.5/add-proxy-services", "api/migration/migrations/v1.0.6/metricdog-init", + "api/migration/migrations/v1.0.6/add-static-pods", "bottlerocket-release", diff --git a/sources/api/migration/migrations/v1.0.6/add-static-pods/Cargo.toml b/sources/api/migration/migrations/v1.0.6/add-static-pods/Cargo.toml new file mode 100644 index 00000000000..a258f278a0f --- /dev/null +++ b/sources/api/migration/migrations/v1.0.6/add-static-pods/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "add-static-pods" +version = "0.1.0" +authors = ["Erikson Tung "] +license = "Apache-2.0 OR MIT" +edition = "2018" +publish = false +# Don't rebuild crate just because of changes to README. +exclude = ["README.md"] + +[dependencies] +migration-helpers = { path = "../../../migration-helpers" } diff --git a/sources/api/migration/migrations/v1.0.6/add-static-pods/src/main.rs b/sources/api/migration/migrations/v1.0.6/add-static-pods/src/main.rs new file mode 100644 index 00000000000..a1a803b4050 --- /dev/null +++ b/sources/api/migration/migrations/v1.0.6/add-static-pods/src/main.rs @@ -0,0 +1,24 @@ +#![deny(rust_2018_idioms)] + +use migration_helpers::common_migrations::AddPrefixesMigration; +use migration_helpers::{migrate, Result}; +use std::process; + +/// We added new settings for defining k8s static pods. +/// Remove `settings.kubernetes.static-pods`, `services.static-pods` prefixes when we downgrade. +fn run() -> Result<()> { + migrate(AddPrefixesMigration(vec![ + "settings.kubernetes.static-pods", + "services.static-pods", + ])) +} + +// 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); + } +}