From 790b1b7375a680f8dfb572fc9c58a1ac8c848fc4 Mon Sep 17 00:00:00 2001 From: Niladri Halder Date: Mon, 16 Oct 2023 14:53:06 +0000 Subject: [PATCH] feat(upgrade): fail when upgrading from a higher to a lower version Signed-off-by: Niladri Halder --- k8s/upgrade/src/plugin/preflight_validations.rs | 10 +++++++++- k8s/upgrade/src/plugin/user_prompt.rs | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/k8s/upgrade/src/plugin/preflight_validations.rs b/k8s/upgrade/src/plugin/preflight_validations.rs index 80206fe39..374063bce 100644 --- a/k8s/upgrade/src/plugin/preflight_validations.rs +++ b/k8s/upgrade/src/plugin/preflight_validations.rs @@ -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; } @@ -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(()) } diff --git a/k8s/upgrade/src/plugin/user_prompt.rs b/k8s/upgrade/src/plugin/user_prompt.rs index 8c3dbe8fa..dd4c70c37 100644 --- a/k8s/upgrade/src/plugin/user_prompt.rs +++ b/k8s/upgrade/src/plugin/user_prompt.rs @@ -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'";