From 4a99b978217133cf270555578dc31c9ab2ec35bb Mon Sep 17 00:00:00 2001 From: sinhaashish Date: Thu, 20 Jul 2023 11:16:55 +0000 Subject: [PATCH] chore(upgrade): modify check for rebuilding Signed-off-by: sinhaashish --- k8s/upgrade/src/bin/upgrade-job/upgrade/utils.rs | 3 ++- k8s/upgrade/src/common/mod.rs | 1 + k8s/upgrade/src/common/utils.rs | 10 ++++++++++ k8s/upgrade/src/lib.rs | 2 ++ k8s/upgrade/src/plugin/preflight_validations.rs | 15 +++++++++------ 5 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 k8s/upgrade/src/common/mod.rs create mode 100644 k8s/upgrade/src/common/utils.rs diff --git a/k8s/upgrade/src/bin/upgrade-job/upgrade/utils.rs b/k8s/upgrade/src/bin/upgrade-job/upgrade/utils.rs index 341c9da04..2f72155a8 100644 --- a/k8s/upgrade/src/bin/upgrade-job/upgrade/utils.rs +++ b/k8s/upgrade/src/bin/upgrade-job/upgrade/utils.rs @@ -10,6 +10,7 @@ use kube::{api::ObjectList, ResourceExt}; use semver::{Version, VersionReq}; use snafu::ResultExt; use tracing::{info, warn}; +use upgrade::common::utils::is_child_degraded_or_faulted; /// Function to check for any volume rebuild in progress across the cluster pub(crate) async fn is_rebuilding(rest_client: &RestClientSet) -> Result { @@ -32,7 +33,7 @@ pub(crate) async fn is_rebuilding(rest_client: &RestClientSet) -> Result { if target .children .iter() - .any(|child| child.rebuild_progress.is_some()) + .any(|child| is_child_degraded_or_faulted(child)) { return Ok(true); } diff --git a/k8s/upgrade/src/common/mod.rs b/k8s/upgrade/src/common/mod.rs new file mode 100644 index 000000000..b5614dd82 --- /dev/null +++ b/k8s/upgrade/src/common/mod.rs @@ -0,0 +1 @@ +pub mod utils; diff --git a/k8s/upgrade/src/common/utils.rs b/k8s/upgrade/src/common/utils.rs new file mode 100644 index 000000000..ae7ab867f --- /dev/null +++ b/k8s/upgrade/src/common/utils.rs @@ -0,0 +1,10 @@ +use openapi::models::{Child, ChildState}; + +/// Returns true if child is faulted or degrade. +pub fn is_child_degraded_or_faulted(child: &Child) -> bool { + match child.state { + ChildState::Degraded => true, + ChildState::Faulted => true, + _ => false, + } +} diff --git a/k8s/upgrade/src/lib.rs b/k8s/upgrade/src/lib.rs index 8e1789b41..9f47f71ab 100644 --- a/k8s/upgrade/src/lib.rs +++ b/k8s/upgrade/src/lib.rs @@ -11,3 +11,5 @@ pub use plugin::constants; /// Module for upgrade client errors. pub use plugin::error; + +pub mod common; diff --git a/k8s/upgrade/src/plugin/preflight_validations.rs b/k8s/upgrade/src/plugin/preflight_validations.rs index 8fba8a9c2..f7f1341ca 100644 --- a/k8s/upgrade/src/plugin/preflight_validations.rs +++ b/k8s/upgrade/src/plugin/preflight_validations.rs @@ -1,8 +1,11 @@ -use crate::plugin::{ - constants::{get_image_version_tag, SINGLE_REPLICA_VOLUME, UPGRADE_TO_DEVELOP_BRANCH}, - error, - upgrade::{get_pvc_from_uuid, get_source_version}, - user_prompt, +use crate::{ + common::utils::is_child_degraded_or_faulted, + plugin::{ + constants::{get_image_version_tag, SINGLE_REPLICA_VOLUME, UPGRADE_TO_DEVELOP_BRANCH}, + error, + upgrade::{get_pvc_from_uuid, get_source_version}, + user_prompt, + }, }; use openapi::{ clients::tower::{self, Configuration}, @@ -154,7 +157,7 @@ pub(crate) async fn is_rebuild_in_progress(client: &RestClient) -> error::Result if target .children .iter() - .any(|child| child.rebuild_progress.is_some()) + .any(|child| is_child_degraded_or_faulted(child)) { return Ok(true); }