From eb369629b1334cbc84e6cc5d80f0fb26dae11687 Mon Sep 17 00:00:00 2001 From: morenol Date: Tue, 3 May 2022 15:52:26 +0000 Subject: [PATCH] Improve cluster check message (#2343) Fixes #2308 ![image](https://user-images.githubusercontent.com/22335041/166480869-a6295cf8-8dad-41f0-b0ef-24dc3e2eb784.png) ![image](https://user-images.githubusercontent.com/22335041/166483944-f71d21b5-0bcf-451b-b982-6ffc9812dc35.png) ![image](https://user-images.githubusercontent.com/22335041/166481293-1aadd398-71f0-4687-9283-93a31c6918ba.png) --- CHANGELOG.md | 1 + crates/fluvio-cluster/src/check/mod.rs | 24 ++++++++++++++++++++++-- crates/fluvio-cluster/src/cli/check.rs | 17 +++++++++++++---- crates/fluvio-cluster/src/cli/mod.rs | 7 ++++++- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed8fa3f388..92fb8fdabb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Platform Version 0.9.25 - UNRELEASED * Set timestamp in Records while producing. ([#2288](https://github.com/infinyon/fluvio/issues/2288)) * Support `ReadCommitted` isolation in SPU for Produce requests [#2336](https://github.com/infinyon/fluvio/pull/2336) +* Improve error messages and add `--fix` option to `fluvio cluster check` to autofix recoverable errors ([#2308](https://github.com/infinyon/fluvio/issues/2308)) ## Platform Version 0.9.24 - 2022-04-21 * CLI: Migrate all fluvio crates to `comfy-table` from `prettytable-rs` ([#2285](https://github.com/infinyon/fluvio/issues/2263)) diff --git a/crates/fluvio-cluster/src/check/mod.rs b/crates/fluvio-cluster/src/check/mod.rs index 88fa5a6bbb..dc84f732ef 100644 --- a/crates/fluvio-cluster/src/check/mod.rs +++ b/crates/fluvio-cluster/src/check/mod.rs @@ -233,6 +233,9 @@ pub enum UnrecoverableCheckStatus { #[error("Local Fluvio component still exists")] ExistingLocalCluster, + #[error("Helm client error")] + HelmClientError, + /// Other misc #[error("Other failure: {0}")] Other(String), @@ -476,9 +479,18 @@ impl ClusterCheck for SysChartCheck { let helm = HelmClient::new()?; // check installed system chart version - let sys_charts = helm + let sys_charts = match helm .get_installed_chart_by_name(SYS_CHART_NAME, None) - .map_err(ClusterCheckError::HelmError)?; + .map_err(ClusterCheckError::HelmError) + { + Ok(charts) => charts, + Err(helm_error) => { + debug!(?helm_error, "helm client error"); + return Ok(CheckStatus::Unrecoverable( + UnrecoverableCheckStatus::HelmClientError, + )); + } + }; debug!(charts = sys_charts.len(), "sys charts count"); if sys_charts.is_empty() { Ok(CheckStatus::AutoFixableError { @@ -862,6 +874,12 @@ impl ClusterChecker { } } } else { + pb.println(pad_format!(format!( + "{} {} check failed and is auto-fixable but fixer is disabled. Use `--fix` to enable it.", + "❌".bold(), + check.label().italic(), + ))); + failed = true; } } @@ -871,12 +889,14 @@ impl ClusterChecker { } CheckStatus::Unrecoverable(err) => { debug!("failed: {}", err); + pb.println(pad_format!(format!( "{} Check {} failed {}", "❌", check.label().italic(), err.to_string().red() ))); + failed = true; } } diff --git a/crates/fluvio-cluster/src/cli/check.rs b/crates/fluvio-cluster/src/cli/check.rs index e5c8764a6c..e9ac8c39ed 100644 --- a/crates/fluvio-cluster/src/cli/check.rs +++ b/crates/fluvio-cluster/src/cli/check.rs @@ -2,26 +2,35 @@ use semver::Version; use clap::Parser; use crate::progress::ProgressBarFactory; -use crate::{ClusterChecker}; +use crate::ClusterChecker; use crate::check::{SysChartCheck, ClusterCheckError}; use crate::charts::ChartConfig; #[derive(Debug, Parser)] -pub struct CheckOpt {} +pub struct CheckOpt { + /// Attempt to fix recoverable errors + #[clap(long)] + fix: bool, +} impl CheckOpt { pub async fn process(self, platform_version: Version) -> Result<(), ClusterCheckError> { use colored::*; println!("{}", "Running pre-startup checks...".bold()); + println!( + "{}", + "Note: This may require admin access to current Kubernetes context" + .bold() + .yellow() + ); let sys_config: ChartConfig = ChartConfig::sys_builder() .build() .map_err(|err| ClusterCheckError::Other(format!("chart config error: {:#?}", err)))?; - let pb = ProgressBarFactory::new(false); ClusterChecker::empty() .with_preflight_checks() .with_check(SysChartCheck::new(sys_config, platform_version)) - .run(&pb, false) + .run(&pb, self.fix) .await?; Ok(()) diff --git a/crates/fluvio-cluster/src/cli/mod.rs b/crates/fluvio-cluster/src/cli/mod.rs index 0984c79b17..1fdddc3dd7 100644 --- a/crates/fluvio-cluster/src/cli/mod.rs +++ b/crates/fluvio-cluster/src/cli/mod.rs @@ -46,7 +46,12 @@ pub enum ClusterCmd { #[clap(name = "delete")] Delete(DeleteOpt), - /// Check that all requirements for cluster startup are met + /// Check that all requirements for cluster startup are met. + /// + /// This command is useful to check if user has all the required dependencies and permissions to run + /// fluvio on the current Kubernetes context. + /// + /// It is not intended to be used in scenarios where user does not have access to Kubernetes resources (eg. Cloud) #[clap(name = "check")] Check(CheckOpt),