Skip to content

Commit

Permalink
Merge pull request #2752 from etungsten/cherry-pick
Browse files Browse the repository at this point in the history
Cherry pick #2749 into `1.12.x`
  • Loading branch information
etungsten authored Jan 25, 2023
2 parents 7f47ef4 + e23e19d commit 6ef1139
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
22 changes: 22 additions & 0 deletions sources/api/migration/migration-helpers/src/common_migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MigrationData> {
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<MigrationData> {
println!("NoOpMigration has no work to do on downgrade.",);
Ok(input)
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -10,8 +10,10 @@ fn run() -> Result<()> {
migrate(AddMetadataMigration(&[SettingMetadata {
metadata: &["affected-services"],
setting: "settings.autoscaling",
}]));
};
}]))?;
} else {
migrate(NoOpMigration)?;
}

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -12,8 +12,10 @@ fn run() -> Result<()> {
"settings.autoscaling",
"services.autoscaling-warm-pool",
"configuration-files.warm-pool-wait-toml",
]));
};
]))?;
} else {
migrate(NoOpMigration)?;
}

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -12,7 +12,9 @@ fn run() -> Result<()> {
metadata: &["affected-services"],
setting: "settings.oci-defaults",
}]))?
};
} else {
migrate(NoOpMigration)?;
}

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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(())
Expand Down

0 comments on commit 6ef1139

Please sign in to comment.