From 352a0a1477ff9084703c3be9ba8a0e1075ca1ce3 Mon Sep 17 00:00:00 2001 From: Mahdi Chaker Date: Thu, 5 Jan 2023 16:05:28 -0800 Subject: [PATCH] migrations: add migrations for 'settings.oci-defaults' Co-authored-by: Mahdi Chaker Co-authored-by: Matthew James Briggs --- Release.toml | 2 ++ sources/Cargo.lock | 16 ++++++++++ sources/Cargo.toml | 2 ++ .../oci-defaults-setting-metadata/Cargo.toml | 15 +++++++++ .../oci-defaults-setting-metadata/build.rs | 6 ++++ .../oci-defaults-setting-metadata/src/main.rs | 28 +++++++++++++++++ .../v1.12.0/oci-defaults-setting/Cargo.toml | 15 +++++++++ .../v1.12.0/oci-defaults-setting/build.rs | 6 ++++ .../v1.12.0/oci-defaults-setting/src/main.rs | 31 +++++++++++++++++++ 9 files changed, 121 insertions(+) create mode 100644 sources/api/migration/migrations/v1.12.0/oci-defaults-setting-metadata/Cargo.toml create mode 100644 sources/api/migration/migrations/v1.12.0/oci-defaults-setting-metadata/build.rs create mode 100644 sources/api/migration/migrations/v1.12.0/oci-defaults-setting-metadata/src/main.rs create mode 100644 sources/api/migration/migrations/v1.12.0/oci-defaults-setting/Cargo.toml create mode 100644 sources/api/migration/migrations/v1.12.0/oci-defaults-setting/build.rs create mode 100644 sources/api/migration/migrations/v1.12.0/oci-defaults-setting/src/main.rs diff --git a/Release.toml b/Release.toml index 142c8b4d31a..4c60177e90a 100644 --- a/Release.toml +++ b/Release.toml @@ -175,4 +175,6 @@ version = "1.12.0" "migrate_v1.12.0_k8s-private-pki-path.lz4", "migrate_v1.12.0_add-k8s-autoscaling-warm-pool-setting.lz4", "migrate_v1.12.0_add-k8s-autoscaling-warm-pool-setting-metadata.lz4", + "migrate_v1.12.0_oci-defaults-setting.lz4", + "migrate_v1.12.0_oci-defaults-setting-metadata.lz4", ] diff --git a/sources/Cargo.lock b/sources/Cargo.lock index dd6c4b9646d..b6107765be5 100644 --- a/sources/Cargo.lock +++ b/sources/Cargo.lock @@ -2518,6 +2518,22 @@ dependencies = [ "memchr", ] +[[package]] +name = "oci-defaults-setting" +version = "0.1.0" +dependencies = [ + "bottlerocket-variant", + "migration-helpers", +] + +[[package]] +name = "oci-defaults-setting-metadata" +version = "0.1.0" +dependencies = [ + "bottlerocket-variant", + "migration-helpers", +] + [[package]] name = "oid-registry" version = "0.6.1" diff --git a/sources/Cargo.toml b/sources/Cargo.toml index 27e243b093b..e7b74ae6524 100644 --- a/sources/Cargo.toml +++ b/sources/Cargo.toml @@ -29,6 +29,8 @@ members = [ "api/migration/migrations/v1.12.0/k8s-private-pki-path", "api/migration/migrations/v1.12.0/add-k8s-autoscaling-warm-pool-setting", "api/migration/migrations/v1.12.0/add-k8s-autoscaling-warm-pool-setting-metadata", + "api/migration/migrations/v1.12.0/oci-defaults-setting", + "api/migration/migrations/v1.12.0/oci-defaults-setting-metadata", "bottlerocket-release", diff --git a/sources/api/migration/migrations/v1.12.0/oci-defaults-setting-metadata/Cargo.toml b/sources/api/migration/migrations/v1.12.0/oci-defaults-setting-metadata/Cargo.toml new file mode 100644 index 00000000000..d13b9eb149b --- /dev/null +++ b/sources/api/migration/migrations/v1.12.0/oci-defaults-setting-metadata/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "oci-defaults-setting-metadata" +version = "0.1.0" +edition = "2018" +authors = ["Mahdi Chaker "] +license = "Apache-2.0 OR MIT" +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"} + +[build-dependencies] +bottlerocket-variant = { version = "0.1", path = "../../../../../bottlerocket-variant" } diff --git a/sources/api/migration/migrations/v1.12.0/oci-defaults-setting-metadata/build.rs b/sources/api/migration/migrations/v1.12.0/oci-defaults-setting-metadata/build.rs new file mode 100644 index 00000000000..51d16cf1b4c --- /dev/null +++ b/sources/api/migration/migrations/v1.12.0/oci-defaults-setting-metadata/build.rs @@ -0,0 +1,6 @@ +use bottlerocket_variant::Variant; + +fn main() { + let variant = Variant::from_env().unwrap(); + variant.emit_cfgs(); +} diff --git a/sources/api/migration/migrations/v1.12.0/oci-defaults-setting-metadata/src/main.rs b/sources/api/migration/migrations/v1.12.0/oci-defaults-setting-metadata/src/main.rs new file mode 100644 index 00000000000..76e827e73ca --- /dev/null +++ b/sources/api/migration/migrations/v1.12.0/oci-defaults-setting-metadata/src/main.rs @@ -0,0 +1,28 @@ +#![deny(rust_2018_idioms)] +use migration_helpers::common_migrations::{AddMetadataMigration, SettingMetadata}; +use migration_helpers::{migrate, Result}; +use std::process; + +/// We updated the 'affected-services' list metadata for 'settings.oci-defaults' +/// to include itself and containerd on upgrade, and to remove those values on +/// downgrade, depending on the running variant. +fn run() -> Result<()> { + if cfg!(variant_runtime = "k8s") { + migrate(AddMetadataMigration(&[SettingMetadata { + metadata: &["affected-services"], + setting: "settings.oci-defaults", + }]))? + }; + + Ok(()) +} + +// 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); + } +} diff --git a/sources/api/migration/migrations/v1.12.0/oci-defaults-setting/Cargo.toml b/sources/api/migration/migrations/v1.12.0/oci-defaults-setting/Cargo.toml new file mode 100644 index 00000000000..c6c3480768e --- /dev/null +++ b/sources/api/migration/migrations/v1.12.0/oci-defaults-setting/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "oci-defaults-setting" +version = "0.1.0" +edition = "2018" +authors = ["Mahdi Chaker "] +license = "Apache-2.0 OR MIT" +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"} + +[build-dependencies] +bottlerocket-variant = { version = "0.1", path = "../../../../../bottlerocket-variant" } diff --git a/sources/api/migration/migrations/v1.12.0/oci-defaults-setting/build.rs b/sources/api/migration/migrations/v1.12.0/oci-defaults-setting/build.rs new file mode 100644 index 00000000000..51d16cf1b4c --- /dev/null +++ b/sources/api/migration/migrations/v1.12.0/oci-defaults-setting/build.rs @@ -0,0 +1,6 @@ +use bottlerocket_variant::Variant; + +fn main() { + let variant = Variant::from_env().unwrap(); + variant.emit_cfgs(); +} diff --git a/sources/api/migration/migrations/v1.12.0/oci-defaults-setting/src/main.rs b/sources/api/migration/migrations/v1.12.0/oci-defaults-setting/src/main.rs new file mode 100644 index 00000000000..00f7af72bdd --- /dev/null +++ b/sources/api/migration/migrations/v1.12.0/oci-defaults-setting/src/main.rs @@ -0,0 +1,31 @@ +#![deny(rust_2018_idioms)] + +use migration_helpers::common_migrations; +use migration_helpers::{migrate, Result}; +use std::process; + +/// We added new settings for configuring the default OCI runtime spec, +/// `settings.oci-defaults`, which will initially contain +/// `settings.oci-defaults.capabilities` and +/// `settings.oci-defaults.resource-limits` +fn run() -> Result<()> { + if cfg!(variant_runtime = "k8s") { + migrate(common_migrations::AddPrefixesMigration(vec![ + "settings.oci-defaults", + "services.oci-defaults", + "configuration-files.oci-defaults", + ]))? + } + + Ok(()) +} + +// 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); + } +}