diff --git a/sources/api/migration/migration-helpers/src/common_migrations.rs b/sources/api/migration/migration-helpers/src/common_migrations.rs index ec1d86d261a..ce06e895e07 100644 --- a/sources/api/migration/migration-helpers/src/common_migrations.rs +++ b/sources/api/migration/migration-helpers/src/common_migrations.rs @@ -1369,3 +1369,25 @@ mod test_replace_metadata { ); } } + +// =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= + +/// When we add conditional migrations that can only run for specific variants, we need to run this +/// migration helper for cases where the migration does NOT apply so migrator will still create a valid +/// intermediary datastore that the host can transition to. +#[derive(Debug)] +pub struct NoOpMigration; + +impl Migration for NoOpMigration { + /// No work to do on forward migrations, copy the same datastore + fn forward(&mut self, input: MigrationData) -> Result { + println!("NoOpMigration has no work to do on upgrade.",); + Ok(input) + } + + /// No work to do on backward migrations, copy the same datastore + fn backward(&mut self, input: MigrationData) -> Result { + println!("NoOpMigration has no work to do on downgrade.",); + Ok(input) + } +} diff --git a/sources/api/migration/migrations/v1.12.0/add-k8s-autoscaling-warm-pool-setting-metadata/src/main.rs b/sources/api/migration/migrations/v1.12.0/add-k8s-autoscaling-warm-pool-setting-metadata/src/main.rs index ae1239f30e7..8a4e76d6ad7 100644 --- a/sources/api/migration/migrations/v1.12.0/add-k8s-autoscaling-warm-pool-setting-metadata/src/main.rs +++ b/sources/api/migration/migrations/v1.12.0/add-k8s-autoscaling-warm-pool-setting-metadata/src/main.rs @@ -1,6 +1,6 @@ #![deny(rust_2018_idioms)] -use migration_helpers::common_migrations::{AddMetadataMigration, SettingMetadata}; +use migration_helpers::common_migrations::{AddMetadataMigration, NoOpMigration, SettingMetadata}; use migration_helpers::{migrate, Result}; use std::process; @@ -10,8 +10,10 @@ fn run() -> Result<()> { migrate(AddMetadataMigration(&[SettingMetadata { metadata: &["affected-services"], setting: "settings.autoscaling", - }])); - }; + }]))?; + } else { + migrate(NoOpMigration)?; + } Ok(()) } diff --git a/sources/api/migration/migrations/v1.12.0/add-k8s-autoscaling-warm-pool-setting/src/main.rs b/sources/api/migration/migrations/v1.12.0/add-k8s-autoscaling-warm-pool-setting/src/main.rs index f81bd14d99e..ad14000b688 100644 --- a/sources/api/migration/migrations/v1.12.0/add-k8s-autoscaling-warm-pool-setting/src/main.rs +++ b/sources/api/migration/migrations/v1.12.0/add-k8s-autoscaling-warm-pool-setting/src/main.rs @@ -1,6 +1,6 @@ #![deny(rust_2018_idioms)] -use migration_helpers::common_migrations::AddPrefixesMigration; +use migration_helpers::common_migrations::{AddPrefixesMigration, NoOpMigration}; use migration_helpers::{migrate, Result}; use std::process; @@ -12,8 +12,10 @@ fn run() -> Result<()> { "settings.autoscaling", "services.autoscaling-warm-pool", "configuration-files.warm-pool-wait-toml", - ])); - }; + ]))?; + } else { + migrate(NoOpMigration)?; + } Ok(()) } 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 index 76e827e73ca..f8610cc70ce 100644 --- 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 @@ -1,5 +1,5 @@ #![deny(rust_2018_idioms)] -use migration_helpers::common_migrations::{AddMetadataMigration, SettingMetadata}; +use migration_helpers::common_migrations::{AddMetadataMigration, NoOpMigration, SettingMetadata}; use migration_helpers::{migrate, Result}; use std::process; @@ -12,7 +12,9 @@ fn run() -> Result<()> { metadata: &["affected-services"], setting: "settings.oci-defaults", }]))? - }; + } else { + migrate(NoOpMigration)?; + } Ok(()) } 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 index 00f7af72bdd..84438b42287 100644 --- 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 @@ -1,6 +1,6 @@ #![deny(rust_2018_idioms)] -use migration_helpers::common_migrations; +use migration_helpers::common_migrations::{AddPrefixesMigration, NoOpMigration}; use migration_helpers::{migrate, Result}; use std::process; @@ -10,11 +10,13 @@ use std::process; /// `settings.oci-defaults.resource-limits` fn run() -> Result<()> { if cfg!(variant_runtime = "k8s") { - migrate(common_migrations::AddPrefixesMigration(vec![ + migrate(AddPrefixesMigration(vec![ "settings.oci-defaults", "services.oci-defaults", "configuration-files.oci-defaults", ]))? + } else { + migrate(NoOpMigration)?; } Ok(())