Skip to content

Commit

Permalink
Add progress indicator to fluvio cluster --k8 --setup command
Browse files Browse the repository at this point in the history
  • Loading branch information
morenol committed Sep 21, 2021
1 parent 752f104 commit 7f5a65d
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 1 deletion.
99 changes: 99 additions & 0 deletions crates/fluvio-cluster/src/progress.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
use crate::{CheckResult, ClusterError, StartStatus, render::ProgressRenderedText};

#[derive(Debug)]
pub enum SetupProgressMessage {
PreFlightCheck(u64),
Check(CheckResult),
}

#[derive(Debug)]
pub enum InstallProgressMessage {
PreFlightCheck(u64),
Check(CheckResult),
ClientLoaded,
CrdChecked,
ClusterError(ClusterError),
Installing,
ScLaunched,
SpuGroupLaunched(u16),
ConfirmSpu,
ProfileSet,
StartStatus(StartStatus),
}

impl ProgressRenderedText for InstallProgressMessage {
fn text(&self) -> String {
use colored::*;

match self {
InstallProgressMessage::PreFlightCheck(_n) => {
format!("{}", "Running pre-flight checks".bold())
}
InstallProgressMessage::Check(check) => check.text(),

InstallProgressMessage::ClientLoaded => {
format!("{:>13} {}", "Ok: ✅".bold().green(), "Client Loaded")
}

InstallProgressMessage::Installing => {
format!("{}", "Installing fluvio".bold())
}
InstallProgressMessage::CrdChecked => {
format!("{:>13} {}", "Ok: ✅".bold().green(), "CRD is ok")
}
InstallProgressMessage::ClusterError(err) => err.to_string(),
InstallProgressMessage::ScLaunched => {
format!("{:>13} {}", "Ok: ✅".bold().green(), "SC Launched")
}
InstallProgressMessage::SpuGroupLaunched(spu_num) => {
format!(
"{:>13} {} ({})",
"Ok: ✅".bold().green(),
"SPU group launched",
spu_num
)
}
InstallProgressMessage::ConfirmSpu => {
format!("{:>13} {}", "Ok: ✅".bold().green(), "SPU confirmed")
}

InstallProgressMessage::ProfileSet => {
format!("{:>13} {}", "Ok: ✅".bold().green(), "Profile set")
}

InstallProgressMessage::StartStatus(status) => {
format!(
"{} {}",
"Fluvio installed with address:".bold(),
status.address,
)
}
}
}
fn next_step_text(&self) -> Option<String> {
match self {
InstallProgressMessage::PreFlightCheck(_n) => Some("Running checks".to_string()),
InstallProgressMessage::Check(_check) => None,
InstallProgressMessage::ClientLoaded => Some("Checking CRD".to_string()),
InstallProgressMessage::Installing => Some("Loading client...".to_string()),
InstallProgressMessage::CrdChecked => Some("Launching SC".to_string()),
InstallProgressMessage::ClusterError(_err) => None,
InstallProgressMessage::ScLaunched => Some("Launching SPU Group".to_string()),
InstallProgressMessage::SpuGroupLaunched(_spu_num) => Some("Confirming SPUs".into()),
InstallProgressMessage::ConfirmSpu => Some("Setting profile".to_string()),
InstallProgressMessage::ProfileSet => None,
InstallProgressMessage::StartStatus(_status) => None,
}
}
}

impl From<SetupProgressMessage> for InstallProgressMessage {
fn from(progress: SetupProgressMessage) -> Self {
match progress {
SetupProgressMessage::PreFlightCheck(n) => InstallProgressMessage::PreFlightCheck(n),
SetupProgressMessage::Check(check_result) => {
InstallProgressMessage::Check(check_result)
}
}
}
}
2 changes: 1 addition & 1 deletion crates/fluvio-cluster/src/start/k8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ impl ClusterInstaller {

// Create a managed SPU cluster
self.create_managed_spu_group(&fluvio).await?;
self.pb.println(InstallProgressMessage::Success.msg());f
self.pb.println(InstallProgressMessage::Success.msg());
self.pb.finish_and_clear();

Ok(StartStatus {
Expand Down

0 comments on commit 7f5a65d

Please sign in to comment.