From 97b8ed4cd86d369f67b54fb41237949532dad0ab Mon Sep 17 00:00:00 2001 From: "Sean P. Kelly" Date: Thu, 3 Aug 2023 07:05:47 +0000 Subject: [PATCH] Add schnauzer-v2 settings generator migrations --- Release.toml | 4 +- sources/Cargo.lock | 7 +++ sources/Cargo.toml | 1 + .../schnauzer-v2-generators/Cargo.toml | 12 ++++++ .../schnauzer-v2-generators/src/main.rs | 43 +++++++++++++++++++ 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 sources/api/migration/migrations/v1.15.0/schnauzer-v2-generators/Cargo.toml create mode 100644 sources/api/migration/migrations/v1.15.0/schnauzer-v2-generators/src/main.rs diff --git a/Release.toml b/Release.toml index 0ff123f00ab..a13fef7ade8 100644 --- a/Release.toml +++ b/Release.toml @@ -216,4 +216,6 @@ version = "1.15.0" "migrate_v1.14.2_ecs-images-cleanup.lz4", ] "(1.14.2, 1.14.3)" = [] -"(1.14.3, 1.15.0)" = [] +"(1.14.3, 1.15.0)" = [ + "migrate_v1.15.0_schnauzer-v2-generators.lz4", +] diff --git a/sources/Cargo.lock b/sources/Cargo.lock index 699aff14b0c..61a3aa73547 100644 --- a/sources/Cargo.lock +++ b/sources/Cargo.lock @@ -3388,6 +3388,13 @@ dependencies = [ "url", ] +[[package]] +name = "schnauzer-v2-generators" +version = "0.1.0" +dependencies = [ + "migration-helpers", +] + [[package]] name = "scopeguard" version = "1.1.0" diff --git a/sources/Cargo.toml b/sources/Cargo.toml index 52aff72bffe..97bafde270f 100644 --- a/sources/Cargo.toml +++ b/sources/Cargo.toml @@ -53,6 +53,7 @@ members = [ "api/migration/migrations/v1.14.0/aws-control-container-v0-7-2", "api/migration/migrations/v1.14.0/public-control-container-v0-7-2", "api/migration/migrations/v1.14.2/ecs-images-cleanup", + "api/migration/migrations/v1.15.0/schnauzer-v2-generators", "bloodhound", diff --git a/sources/api/migration/migrations/v1.15.0/schnauzer-v2-generators/Cargo.toml b/sources/api/migration/migrations/v1.15.0/schnauzer-v2-generators/Cargo.toml new file mode 100644 index 00000000000..ff9edc96d16 --- /dev/null +++ b/sources/api/migration/migrations/v1.15.0/schnauzer-v2-generators/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "schnauzer-v2-generators" +version = "0.1.0" +authors = ["Sean P. Kelly "] +license = "Apache-2.0 OR MIT" +edition = "2021" +publish = false +# Don't rebuild crate just because of changes to README. +exclude = ["README.md"] + +[dependencies] +migration-helpers = { path = "../../../migration-helpers", version = "0.1.0" } diff --git a/sources/api/migration/migrations/v1.15.0/schnauzer-v2-generators/src/main.rs b/sources/api/migration/migrations/v1.15.0/schnauzer-v2-generators/src/main.rs new file mode 100644 index 00000000000..d7ef6be1c25 --- /dev/null +++ b/sources/api/migration/migrations/v1.15.0/schnauzer-v2-generators/src/main.rs @@ -0,0 +1,43 @@ +use migration_helpers::common_migrations::{MetadataReplacement, ReplaceMetadataMigration}; +use migration_helpers::{migrate, Result}; +use std::process; + +// +fn run() -> Result<()> { + migrate(ReplaceMetadataMigration(vec![ + MetadataReplacement { + setting: "settings.host-containers.admin.source", + metadata: "setting-generator", + old_val: "schnauzer settings.host-containers.admin.source", + new_val: "schnauzer-v2 render --requires 'aws@v1(ecr-prefix)' --template '{{ ecr-prefix settings.aws.region }}/bottlerocket-admin:v0.10.1'", + }, + MetadataReplacement { + setting: "settings.host-containers.control.source", + metadata: "setting-generator", + old_val: "schnauzer settings.host-containers.control.source", + new_val: "schnauzer-v2 render --requires 'aws@v1(ecr-prefix)' --template '{{ ecr-prefix settings.aws.region }}/bottlerocket-control:v0.7.2'", + }, + MetadataReplacement { + setting: "settings.updates.targets-base-url", + metadata: "setting-generator", + old_val: "schnauzer settings.updates.targets-base-url", + new_val: "schnauzer-v2 render --requires 'aws@v1' --requires 'updates@v1(tuf-prefix)' --template '{{ tuf-prefix settings.aws.region }}/targets/'", + }, + MetadataReplacement { + setting: "settings.updates.metadata-base-url", + metadata: "setting-generator", + old_val: "schnauzer settings.updates.metadata-base-url", + new_val: "schnauzer-v2 render --requires 'aws@v1' --requires 'updates@v1(metadata-prefix, tuf-prefix)' --template '{{ tuf-prefix settings.aws.region }}{{ metadata-prefix settings.aws.region }}/2020-07-07/{{ os.variant_id }}/{{ os.arch }}/'", + }, + ])) +} + +// 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); + } +}