Skip to content

Commit

Permalink
migrations: add migrations for 'settings.oci-defaults'
Browse files Browse the repository at this point in the history
Co-authored-by: Mahdi Chaker <mmchaker@amazon.com>
Co-authored-by: Matthew James Briggs <brigmatt@amazon.com>
  • Loading branch information
mchaker and webern committed Jan 17, 2023
1 parent 2e561ba commit 352a0a1
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Release.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
16 changes: 16 additions & 0 deletions sources/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions sources/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "oci-defaults-setting-metadata"
version = "0.1.0"
edition = "2018"
authors = ["Mahdi Chaker <mmchaker@amazon.com>"]
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" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use bottlerocket_variant::Variant;

fn main() {
let variant = Variant::from_env().unwrap();
variant.emit_cfgs();
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "oci-defaults-setting"
version = "0.1.0"
edition = "2018"
authors = ["Mahdi Chaker <mmchaker@amazon.com>"]
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" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use bottlerocket_variant::Variant;

fn main() {
let variant = Variant::from_env().unwrap();
variant.emit_cfgs();
}
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 352a0a1

Please sign in to comment.