Skip to content

Commit d0cbc4b

Browse files
committed
migrations: migrator for image-verifier-plugins on k8s
Add migration for these new settings for k8s variants. no-op on ecs variants as these settings have previously existed Signed-off-by: Gavin Inglis <giinglis@amazon.com>
1 parent e73a63d commit d0cbc4b

4 files changed

Lines changed: 76 additions & 0 deletions

File tree

sources/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sources/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ members = [
6363
"settings-migrations/v1.56.0/image-verifier-plugins-extensible",
6464
"settings-migrations/v1.60.0/kubernetes-topology-manager-policy-options",
6565
"settings-migrations/v1.60.0/container-runtime-max-concurrent-unpacks",
66+
"settings-migrations/v1.61.0/image-verifier-plugins-settings",
6667

6768
"settings-plugins/aws-dev",
6869
"settings-plugins/aws-ecs-2",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "image-verifier-plugins-settings"
3+
version = "0.1.0"
4+
license = "Apache-2.0 OR MIT"
5+
edition = "2021"
6+
publish = false
7+
exclude = ["README.md"]
8+
9+
[dependencies]
10+
migration-helpers.workspace = true
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
use migration_helpers::common_migrations::{AddPrefixesMigration, NoOpMigration};
2+
use migration_helpers::{migrate, MigrationData, Result};
3+
use std::process;
4+
5+
/// Added new image-verifier-plugins settings.
6+
/// For k8s variants: remove the settings on downgrade since they didn't exist before.
7+
/// For ecs-3 variants: no migration needed since these settings already exist.
8+
fn run() -> Result<()> {
9+
// Create a custom migration that checks variant at runtime
10+
migrate(VariantSpecificMigration)
11+
}
12+
13+
struct VariantSpecificMigration;
14+
15+
impl migration_helpers::Migration for VariantSpecificMigration {
16+
fn forward(&mut self, input: MigrationData) -> Result<MigrationData> {
17+
// No work needed on upgrade for any variant
18+
println!("VariantSpecificMigration has no work to do on upgrade.");
19+
Ok(input)
20+
}
21+
22+
fn backward(&mut self, input: MigrationData) -> Result<MigrationData> {
23+
// Check variant from runtime data
24+
if let Some(variant_value) = input.data.get("os.variant_id") {
25+
if let Some(variant_str) = variant_value.as_str() {
26+
if variant_str.starts_with("aws-k8s-") || variant_str.starts_with("vmware-k8s-") {
27+
// For k8s variants, remove the settings on downgrade
28+
println!("k8s variant detected ({}), removing image-verifier-plugins settings on downgrade", variant_str);
29+
return AddPrefixesMigration(vec!["settings.image-verifier-plugins"])
30+
.backward(input);
31+
} else if variant_str.starts_with("aws-ecs-") {
32+
// For ECS variants, no migration needed
33+
println!(
34+
"ECS variant detected ({}), no migration needed",
35+
variant_str
36+
);
37+
return NoOpMigration.backward(input);
38+
}
39+
}
40+
}
41+
42+
// Default behavior for unknown variants
43+
println!(
44+
"Unknown or missing variant, using default behavior (remove settings on downgrade)"
45+
);
46+
AddPrefixesMigration(vec!["settings.image-verifier-plugins"]).backward(input)
47+
}
48+
}
49+
50+
// Returning a Result from main makes it print a Debug representation of the error, but with Snafu
51+
// we have nice Display representations of the error, so we wrap "main" (run) and print any error.
52+
// https://github.com/shepmaster/snafu/issues/110
53+
fn main() {
54+
if let Err(e) = run() {
55+
eprintln!("{e}");
56+
process::exit(1);
57+
}
58+
}

0 commit comments

Comments
 (0)