Skip to content

Commit

Permalink
Add progress indicator to fluvio cluster --k8 command (#1627)
Browse files Browse the repository at this point in the history
Fixes #1635
Fixes #1636
  • Loading branch information
morenol committed Sep 21, 2021
1 parent 858c26f commit 33276e9
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Release Notes

## Platform Version 0.9.8 - UNRELEASED
* Add progress indicator to `fluvio cluster start` ([1627](https://github.com/infinyon/fluvio/pull/1627))

## Platform Version 0.9.7 - 2021-09-16
* Improve progress message in `fluvio cluster start --local` ([1586](https://github.com/infinyon/fluvio/pull/1586))
Expand Down
2 changes: 0 additions & 2 deletions crates/fluvio-cluster/src/cli/start/k8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ pub async fn start_k8(installer: &ClusterInstaller) -> Result<(), K8InstallError
if checks.is_none() {
println!("Skipped pre-start checks");
}
println!("Successfully installed Fluvio!");
}
// Aborted startup because pre-checks failed
Err(K8InstallError::FailedPrecheck(check_statuses)) => {
Expand All @@ -100,7 +99,6 @@ pub async fn start_k8(installer: &ClusterInstaller) -> Result<(), K8InstallError
}

pub async fn setup_k8(installer: &ClusterInstaller) -> Result<(), ClusterCliError> {
println!("Performing pre-startup checks...");
let check_results = installer.setup().await;
render_check_results(&check_results);
render_results_next_steps(&check_results);
Expand Down
73 changes: 52 additions & 21 deletions crates/fluvio-cluster/src/start/k8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ use std::env;

use derive_builder::Builder;
use fluvio::FluvioAdmin;
use indicatif::ProgressBar;
use k8_client::SharedK8Client;
use k8_client::load_and_share;
use tracing::{info, warn, debug, instrument};
use tracing::{warn, debug, instrument};
use once_cell::sync::Lazy;
use tempfile::NamedTempFile;
use semver::Version;
Expand All @@ -30,14 +31,17 @@ use fluvio_command::CommandExt;
use crate::helm::{HelmClient};
use crate::check::{CheckFailed, CheckResults, AlreadyInstalled, SysChartCheck};
use crate::error::K8InstallError;
use crate::render::ProgressRenderedText;
use crate::start::common::check_crd;
use crate::{ClusterError, StartStatus, DEFAULT_NAMESPACE, CheckStatus, ClusterChecker, CheckStatuses};
use crate::charts::{ChartConfig, ChartInstaller};
use crate::check::render::render_check_progress;
use crate::check::render::render_check_progress_with_indicator;
use crate::UserChartLocation;

use super::constants::*;
use super::common::try_connect_to_sc;
use super::progress::InstallProgressMessage;
use super::progress::create_progress_indicator;

const DEFAULT_REGISTRY: &str = "infinyon";
const DEFAULT_GROUP_NAME: &str = "main";
Expand Down Expand Up @@ -569,6 +573,7 @@ pub struct ClusterInstaller {
kube_client: SharedK8Client,
/// Helm client for performing installs
helm_client: HelmClient,
pb: ProgressBar,
}

impl ClusterInstaller {
Expand All @@ -588,6 +593,7 @@ impl ClusterInstaller {
config,
kube_client: load_and_share().map_err(K8InstallError::K8ClientError)?,
helm_client: HelmClient::new().map_err(K8InstallError::HelmError)?,
pb: create_progress_indicator(),
})
}

Expand Down Expand Up @@ -623,8 +629,11 @@ impl ClusterInstaller {
}

if self.config.render_checks {
self.pb
.println(InstallProgressMessage::PreFlightCheck.msg());

let mut progress = checker.run_and_fix_with_progress();
render_check_progress(&mut progress).await
render_check_progress_with_indicator(&mut progress, &self.pb).await
} else {
checker.run_wait_and_fix().await
}
Expand All @@ -638,8 +647,6 @@ impl ClusterInstaller {
fields(namespace = &*self.config.namespace),
)]
pub async fn install_fluvio(&self) -> Result<StartStatus, K8InstallError> {
println!("starting installing");

let mut installed = false;
let checks = match self.config.skip_checks {
true => None,
Expand All @@ -656,7 +663,6 @@ impl ClusterInstaller {
let mut any_failed = false;
for status in &statuses {
match status {
// If Fluvio is already installed, return the SC's address
CheckStatus::Fail(CheckFailed::AlreadyInstalled) => {
debug!("Fluvio is already installed");
installed = true;
Expand All @@ -676,6 +682,9 @@ impl ClusterInstaller {

if !installed {
self.install_app().await?;
} else {
self.pb
.println(InstallProgressMessage::AlreadyInstalled.msg())
}

let namespace = &self.config.namespace;
Expand All @@ -689,21 +698,29 @@ impl ClusterInstaller {

let address = format!("{}:{}", host_name, port);

println!("found SC service addr: {}", address);
self.pb
.println(InstallProgressMessage::FoundSC(address.clone()).msg());
let cluster_config =
FluvioConfig::new(address.clone()).with_tls(self.config.client_tls_policy.clone());

self.pb
.set_message(InstallProgressMessage::ConnectingSC.msg());

let fluvio = match try_connect_to_sc(&cluster_config, &self.config.platform_version).await {
Some(fluvio) => fluvio,
None => return Err(K8InstallError::SCServiceTimeout),
};
self.pb.set_message("");

if self.config.save_profile {
self.update_profile(address.clone())?;
self.pb.println(InstallProgressMessage::ProfileSet.msg());
}

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

Ok(StartStatus {
address,
Expand All @@ -720,6 +737,9 @@ impl ClusterInstaller {
&self.config
);

self.pb
.println(InstallProgressMessage::InstallingFluvio.msg());

// If configured with TLS, copy certs to server
if let TlsPolicy::Verified(tls) = &self.config.server_tls_policy {
self.upload_tls_secrets(tls)?;
Expand Down Expand Up @@ -816,9 +836,11 @@ impl ClusterInstaller {
debug!("Using helm install settings: {:#?}", &install_settings);

if self.config.upgrade {
println!("Upgrading fluvio chart");
self.pb
.set_message(InstallProgressMessage::UpgradingChart.msg());
} else {
println!("installing fluvio chart");
self.pb
.set_message(InstallProgressMessage::InstallingChart.msg());
}

let mut config = ChartConfig::app_builder()
Expand All @@ -836,7 +858,10 @@ impl ClusterInstaller {
let installer = ChartInstaller::from_config(config)?;
installer.process(self.config.upgrade)?;

info!("Fluvio app chart has been installed");
self.pb
.println(InstallProgressMessage::ChartInstalled.msg());
self.pb.set_message("");

Ok(())
}

Expand Down Expand Up @@ -991,7 +1016,8 @@ impl ClusterInstaller {
.count();

if self.config.spu_replicas as usize == ready_spu {
println!("All SPUs({}) are ready", ready_spu);
self.pb.println(InstallProgressMessage::SpusConfirmed.msg());

return Ok(true);
} else {
debug!(
Expand All @@ -1000,9 +1026,8 @@ impl ClusterInstaller {
attempt = i,
"Not all SPUs are ready. Waiting",
);
println!(
"{} of {} spu are ready, sleeping 10 seconds...",
ready_spu, self.config.spu_replicas,
self.pb.set_message(
InstallProgressMessage::WaitingForSPU(ready_spu, expected_spu).msg(),
);
sleep(Duration::from_secs(10)).await;
}
Expand Down Expand Up @@ -1059,7 +1084,8 @@ impl ClusterInstaller {

/// Updates the Fluvio configuration with the newly installed cluster info.
fn update_profile(&self, external_addr: String) -> Result<(), K8InstallError> {
println!("updating profile for: {}", external_addr);
self.pb
.set_message(format!("updating profile for: {}", external_addr));
let mut config_file = ConfigFile::load_default_or_new()?;
let config = config_file.mut_config();

Expand Down Expand Up @@ -1089,6 +1115,7 @@ impl ClusterInstaller {

config.set_current_profile(&profile_name);
config_file.save()?;
self.pb.set_message("");
Ok(())
}

Expand Down Expand Up @@ -1117,12 +1144,12 @@ impl ClusterInstaller {
async fn create_managed_spu_group(&self, fluvio: &Fluvio) -> Result<(), K8InstallError> {
let name = self.config.group_name.clone();
let admin = fluvio.admin().await;

println!("checking if spu groups exists");
let lists = admin.list::<SpuGroupSpec, _>(vec![]).await?;

if lists.is_empty() {
println!("Trying to create managed {} spus", self.config.spu_replicas);
self.pb.set_message(format!(
"Trying to create managed {} spus",
self.config.spu_replicas
));

let spu_spec = SpuGroupSpec {
replicas: self.config.spu_replicas,
Expand All @@ -1132,15 +1159,19 @@ impl ClusterInstaller {

admin.create(name, false, spu_spec).await?;

println!("Created {} spus", self.config.spu_replicas);
self.pb.println(
InstallProgressMessage::SpuGroupLaunched(self.config.spu_replicas as u16).msg(),
);
} else {
println!("spu group: {} exists, skipping", lists[0].name);
self.pb
.println(InstallProgressMessage::SpuGroupExists.msg());
}

// Wait for the SPU cluster to spin up
if !self.config.skip_spu_liveness_check {
self.wait_for_spu(&admin).await?;
}
self.pb.set_message("");

Ok(())
}
Expand Down
44 changes: 38 additions & 6 deletions crates/fluvio-cluster/src/start/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@ pub(crate) enum InstallProgressMessage {
PreFlightCheck,
LaunchingSC,
ScLaunched,
ConnectingSC,
LaunchingSPUGroup(u16),
StartSPU(u16, u16),
WaitingForSPU(usize, usize),
SpuGroupLaunched(u16),
SpuGroupExists,
AlreadyInstalled,
InstallingFluvio,
InstallingChart,
UpgradingChart,
ChartInstalled,
FoundSC(String),
ConfirmingSpus,
SpusConfirmed,
ProfileSet,
Expand All @@ -24,32 +33,55 @@ impl ProgressRenderedText for InstallProgressMessage {
InstallProgressMessage::PreFlightCheck => {
format!("{}", "📝 Running pre-flight checks".bold())
}
InstallProgressMessage::AlreadyInstalled => {
format!("✨ {}", "Fluvio already installed".bold())
}
InstallProgressMessage::ChartInstalled => {
format!("{:>6} {}", "✅", "Fluvio app chart has been installed")
}
InstallProgressMessage::InstallingFluvio => {
format!("🛠️ {}", "Installing Fluvio".bold())
}
InstallProgressMessage::LaunchingSC => {
format!("🖥️ {}", "Starting SC server".bold())
}

InstallProgressMessage::SpuGroupExists => {
format!("{}", "🤖 SPU group exists, skipping".bold())
}
InstallProgressMessage::FoundSC(address) => {
format!("🔎 {} {}", "Found SC service addr:".bold(), address.bold())
}
InstallProgressMessage::ScLaunched => {
format!("🖥️ {}", "SC Launched".bold())
}
InstallProgressMessage::InstallingChart => {
format!("{:>6} {}", "📊", "Installing Fluvio chart")
}
InstallProgressMessage::UpgradingChart => {
format!("{:>6} {}", "📊", "Upgrading Fluvio chart")
}
InstallProgressMessage::ConnectingSC => {
format!("🔗 {}", "Trying to connect to SC".bold())
}

InstallProgressMessage::WaitingForSPU(spu_num, total) => {
format!("{:>6} ({}/{})", "🤖 Waiting for SPU:", spu_num, total)
}
InstallProgressMessage::LaunchingSPUGroup(spu_num) => {
format!("{} {}", "🤖 Launching SPU Group with:".bold(), spu_num)
}

InstallProgressMessage::StartSPU(spu_num, total) => {
format!("{} ({}/{})", "🤖 Starting SPU:", spu_num, total)
}

InstallProgressMessage::SpuGroupLaunched(spu_num) => {
format!("🤖 {} ({})", "SPU group launched".bold(), spu_num)
}
InstallProgressMessage::ConfirmingSpus => {
format!("💙 {}", "Confirming SPUs".bold())
}

InstallProgressMessage::SpusConfirmed => {
format!("{:>6} {}", "✅".bold().green(), "All SPUs confirmed")
format!("{:>6} {}", "✅", "All SPUs confirmed")
}

InstallProgressMessage::ProfileSet => {
format!("👤 {}", "Profile set".bold())
}
Expand Down

0 comments on commit 33276e9

Please sign in to comment.