From 7356b2c87f9ddb32919334024aae6a29c2c177d4 Mon Sep 17 00:00:00 2001 From: Shikha Vyaghra Date: Fri, 6 Dec 2024 01:03:41 +0000 Subject: [PATCH] migrations: Change public control host-container source metadata to object This migration will change the public control host-container source to setting-generator metadata(that will generate source using sundog) on forward migration. In backward migration, it will reset the value of the source as string. --- Release.toml | 1 + sources/Cargo.lock | 7 +++++ sources/Cargo.toml | 1 + .../Cargo.toml | 15 ++++++++++ .../src/main.rs | 30 +++++++++++++++++++ 5 files changed, 54 insertions(+) create mode 100644 sources/settings-migrations/v1.29.0/update-settings-generator-control/Cargo.toml create mode 100644 sources/settings-migrations/v1.29.0/update-settings-generator-control/src/main.rs diff --git a/Release.toml b/Release.toml index 0d39eae7481..37c0907a18c 100644 --- a/Release.toml +++ b/Release.toml @@ -381,6 +381,7 @@ version = "1.28.0" ] "(1.28.0, 1.29.0)" = [ "migrate_v1.29.0_update-settings-generator-admin.lz4", + "migrate_v1.29.0_update-settings-generator-control.lz4", "migrate_v1.29.0_change-public-admin-container-to-set-gen.lz4", "migrate_v1.29.0_change-public-control-container-to-set-gen.lz4", ] diff --git a/sources/Cargo.lock b/sources/Cargo.lock index a5790ed53ed..dfdb4b4cf11 100644 --- a/sources/Cargo.lock +++ b/sources/Cargo.lock @@ -3601,6 +3601,13 @@ dependencies = [ "migration-helpers", ] +[[package]] +name = "update-settings-generator-control" +version = "0.1.0" +dependencies = [ + "migration-helpers", +] + [[package]] name = "url" version = "2.5.0" diff --git a/sources/Cargo.toml b/sources/Cargo.toml index 7bbeea64eb2..c147bf192b8 100644 --- a/sources/Cargo.toml +++ b/sources/Cargo.toml @@ -72,6 +72,7 @@ members = [ "settings-migrations/v1.28.0/aws-control-container-v0-7-18", "settings-migrations/v1.28.0/public-control-container-v0-7-18", "settings-migrations/v1.29.0/update-settings-generator-admin", + "settings-migrations/v1.29.0/update-settings-generator-control", "settings-migrations/v1.29.0/change-public-admin-container-to-set-gen", "settings-migrations/v1.29.0/change-public-control-container-to-set-gen", diff --git a/sources/settings-migrations/v1.29.0/update-settings-generator-control/Cargo.toml b/sources/settings-migrations/v1.29.0/update-settings-generator-control/Cargo.toml new file mode 100644 index 00000000000..490b44b9a6c --- /dev/null +++ b/sources/settings-migrations/v1.29.0/update-settings-generator-control/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "update-settings-generator-control" +version = "0.1.0" +authors = ["Shikha Vyaghra "] +license = "Apache-2.0 OR MIT" +edition = "2021" +publish = false +# Don't rebuild crate just because of changes to README. +exclude = ["README.md"] + + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +migration-helpers.workspace = true diff --git a/sources/settings-migrations/v1.29.0/update-settings-generator-control/src/main.rs b/sources/settings-migrations/v1.29.0/update-settings-generator-control/src/main.rs new file mode 100644 index 00000000000..e9932990ce4 --- /dev/null +++ b/sources/settings-migrations/v1.29.0/update-settings-generator-control/src/main.rs @@ -0,0 +1,30 @@ +use migration_helpers::common_migrations::MetadataStringToStructMigration; +use migration_helpers::{migrate, Result}; +use std::process; + +const OLD_CONTROL_CTR_CMDLINE: &str = + "schnauzer-v2 render --requires 'aws@v1(helpers=[ecr-prefix])' --template '{{ ecr-prefix settings.aws.region }}/bottlerocket-control:v0.7.18'"; +const NEW_CONTROL_CTR_CMDLINE: &str = + "schnauzer-v2 render --requires 'aws@v1(helpers=[ecr-prefix])' --template '{{ ecr-prefix settings.aws.region }}/bottlerocket-control:v0.7.18'"; + +/// We bumped the version of the default control container +fn run() -> Result<()> { + migrate(MetadataStringToStructMigration { + setting: "settings.host-containers.control.source", + old_cmdline: OLD_CONTROL_CTR_CMDLINE, + new_cmdline: NEW_CONTROL_CTR_CMDLINE, + metadata_type: "setting-generator", + binary_for_generator: "schnauzer-v2", + skip_if_populated: true, + }) +} + +// 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); + } +}