Skip to content

Commit

Permalink
Add basic progress output
Browse files Browse the repository at this point in the history
  • Loading branch information
Techassi committed Oct 20, 2023
1 parent fddf2f5 commit 082bfaa
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 15 deletions.
2 changes: 2 additions & 0 deletions rust/stackable-cockpit/src/engine/kind/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ impl KindCluster {
.args(["create", "cluster"])
.args(["--name", self.name.as_str()])
.args(["--config", "-"])
.stdout(Stdio::null())
.stderr(Stdio::null())
.stdin(Stdio::piped())
.spawn()
.context(IoSnafu)?;
Expand Down
2 changes: 1 addition & 1 deletion rust/stackable-cockpit/src/platform/stack/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl StackSpecV2 {
},
Some(&values_yaml),
product_namespace,
false,
true,
)
.context(HelmInstallReleaseSnafu {
release_name: helm_chart.release_name,
Expand Down
15 changes: 11 additions & 4 deletions rust/stackablectl/src/cmds/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ async fn install_cmd(
) -> Result<String, CmdError> {
info!("Installing demo {}", args.demo_name);

// Init result output and progress output
let mut output = cli.result();
output.enable_progress(format!("Installing demo '{}'", args.demo_name));

let demo_spec = list.get(&args.demo_name).ok_or(CmdError::NoSuchDemo {
name: args.demo_name.clone(),
})?;
Expand All @@ -289,6 +293,7 @@ async fn install_cmd(
.context(ListSnafu)?;

// Install local cluster if needed
output.set_progress_message("Creating local cluster");
args.local_cluster
.install_if_needed(None)
.await
Expand All @@ -307,19 +312,22 @@ async fn install_cmd(
.unwrap_or(DEFAULT_PRODUCT_NAMESPACE.into());

if !args.skip_release {
output.set_progress_message("Creating operator namespace");
namespace::create_if_needed(operator_namespace.clone())
.await
.context(NamespaceSnafu {
namespace: operator_namespace.clone(),
})?;
}

output.set_progress_message("Creating product namespace");
namespace::create_if_needed(product_namespace.clone())
.await
.context(NamespaceSnafu {
namespace: product_namespace.clone(),
})?;

output.set_progress_message("Installing demo manifests");
demo_spec
.install(
stack_list,
Expand All @@ -334,8 +342,6 @@ async fn install_cmd(
.await
.context(DemoSnafu)?;

let mut result = cli.result();

let operator_cmd = format!(
"stackablectl operator installed{}",
if args.namespaces.operator_namespace.is_some() {
Expand All @@ -354,11 +360,12 @@ async fn install_cmd(
}
);

result
output
.with_command_hint(operator_cmd, "display the installed operators")
.with_command_hint(stacklet_cmd, "display the installed stacklets")
.with_output(format!("Installed demo '{}'", args.demo_name));

output.finish_progress("Done");
// TODO (Techassi): Remove unwrap
Ok(result.render().unwrap())
Ok(output.render().unwrap())
}
13 changes: 9 additions & 4 deletions rust/stackablectl/src/cmds/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,19 +271,25 @@ async fn install_cmd(

match release_list.get(&args.release) {
Some(release) => {
let mut output = cli.result();
output.enable_progress(format!("Installing release '{}'", args.release));

// Install local cluster if needed
output.set_progress_message("Installing local cluster");
args.local_cluster
.install_if_needed(None)
.await
.context(CommonClusterArgsSnafu)?;

// Create operator namespace if needed
output.set_progress_message("Creating operator namespace");
namespace::create_if_needed(args.operator_namespace.clone())
.await
.context(NamespaceSnafu {
namespace: args.operator_namespace.clone(),
})?;

output.set_progress_message("Installing release manifests");
release
.install(
&args.included_products,
Expand All @@ -292,17 +298,16 @@ async fn install_cmd(
)
.context(ReleaseInstallSnafu)?;

let mut result = cli.result();

result
output
.with_command_hint(
"stackablectl operator installed",
"list installed operators",
)
.with_output(format!("Installed release '{}'", args.release));

output.finish_progress("Done");
// TODO (Techassi): Remove unwrap
Ok(result.render().unwrap())
Ok(output.render().unwrap())
}
None => Ok("No such release".into()),
}
Expand Down
15 changes: 11 additions & 4 deletions rust/stackablectl/src/cmds/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ async fn install_cmd(

match stack_list.get(&args.stack_name) {
Some(stack_spec) => {
let mut output = cli.result();
output.enable_progress(format!("Installing stack '{}'", args.stack_name));

// Install local cluster if needed
output.set_progress_message("Creating local cluster");
args.local_cluster
.install_if_needed(None)
.await
Expand All @@ -297,12 +301,14 @@ async fn install_cmd(

// Install release if not opted out
if !args.skip_release {
output.set_progress_message("Creating operator namespace");
namespace::create_if_needed(operator_namespace.clone())
.await
.context(NamespaceSnafu {
namespace: operator_namespace.clone(),
})?;

output.set_progress_message("Installing release manifests");
stack_spec
.install_release(release_list, &operator_namespace, &product_namespace)
.await
Expand All @@ -312,13 +318,15 @@ async fn install_cmd(
}

// Create product namespace if needed
output.set_progress_message("Creating product namespace");
namespace::create_if_needed(product_namespace.clone())
.await
.context(NamespaceSnafu {
namespace: product_namespace.clone(),
})?;

// Install stack
output.set_progress_message("Installing stack manifests");
stack_spec
.install_stack_manifests(
&args.stack_parameters,
Expand All @@ -328,8 +336,6 @@ async fn install_cmd(
.await
.context(StackSnafu)?;

let mut result = cli.result();

let operator_cmd = format!(
"stackablectl operator installed{}",
if args.namespaces.operator_namespace.is_some() {
Expand All @@ -348,13 +354,14 @@ async fn install_cmd(
}
);

result
output
.with_command_hint(operator_cmd, "display the installed operators")
.with_command_hint(stacklet_cmd, "display the installed stacklets")
.with_output(format!("Installed stack '{}'", args.stack_name));

output.finish_progress("Done");
// TODO (Techassi): Remove unwrap
Ok(result.render().unwrap())
Ok(output.render().unwrap())
}
None => Ok("No such stack".into()),
}
Expand Down
10 changes: 8 additions & 2 deletions rust/stackablectl/src/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,15 @@ where
.get_or_insert(Spinner::new(spinners::Dots, initial_message, Color::Green));
}

pub fn set_progress_message(&mut self, message: String) {
pub fn set_progress_message(&mut self, message: impl Into<String>) {
if let Some(progress) = self.progress.as_mut() {
progress.update_text(message)
progress.update_text(message.into())
}
}

pub fn finish_progress(&mut self, message: impl AsRef<str>) {
if let Some(progress) = self.progress.as_mut() {
progress.success(message.as_ref())
}
}

Expand Down

0 comments on commit 082bfaa

Please sign in to comment.