Skip to content

Commit

Permalink
feat(upgrade): fail when upgrading from a higher to a lower version
Browse files Browse the repository at this point in the history
Signed-off-by: Niladri Halder <[email protected]>
  • Loading branch information
niladrih committed Oct 16, 2023
1 parent b696520 commit 790b1b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion k8s/upgrade/src/plugin/preflight_validations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ pub(crate) async fn upgrade_path_validation(
// Stable to unstable check.
if !allow_unstable {
let mut self_is_stable: bool = false;
if let Some(version) = self_version {
if let Some(ref version) = self_version {
if !version.pre.is_empty() {
self_is_stable = true;
}
Expand All @@ -244,6 +244,14 @@ pub(crate) async fn upgrade_path_validation(
}
}

// Upgrade not allowed to lower semver versions check.
if let Some(ref version) = self_version {
if version.lt(&source) {
console_logger::error("", user_prompt::HIGHER_TO_LOWER_SEMVER_UPGRADE);
return error::InvalidUpgradePath.fail();
}
}

Ok(())
}

Expand Down
5 changes: 5 additions & 0 deletions k8s/upgrade/src/plugin/user_prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,8 @@ pub const HELM_UPGRADE_VALIDATION_ERROR: &str =
pub const STABLE_TO_UNSTABLE_UPGRADE: &str =
"Cannot upgrade from a stable version to an unstable version. \
If this is intentional, try again with '--allow-unstable'";

/// Failure notice for when upgrading from a higher version to a lower one.
pub const HIGHER_TO_LOWER_SEMVER_UPGRADE: &str =
"Cannot upgrade from a higher version to a lower version. \
If this is intentional, try again with '--skip-upgrade-path-validation-for-unsupported-version'";

0 comments on commit 790b1b7

Please sign in to comment.