Skip to content

Commit cc6bd56

Browse files
committed
add progress reporting to stackablectl
1 parent 480443d commit cc6bd56

File tree

28 files changed

+387
-120
lines changed

28 files changed

+387
-120
lines changed

Cargo.lock

Lines changed: 83 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ directories = "5.0"
3131
dotenvy = "0.15"
3232
futures = "0.3"
3333
indexmap = { version = "2.2", features = ["serde"] }
34+
indicatif = "0.17.11"
3435
k8s-openapi = { version = "0.24", default-features = false, features = ["v1_32"] }
3536
kube = { version = "0.99", default-features = false, features = ["client", "rustls-tls", "ws", "socks5", "http-proxy"] }
3637
lazy_static = "1.5"
@@ -54,6 +55,7 @@ termion = "4.0"
5455
tokio = { version = "1.38", features = ["rt-multi-thread", "macros", "fs", "process", "io-std"] }
5556
tower-http = { version = "0.5", features = ["validate-request"] }
5657
tracing = "0.1"
58+
tracing-indicatif = "0.3.9"
5759
tracing-subscriber = "0.3"
5860
url = "2.5"
5961
urlencoding = "2.1.3"

rust/stackable-cockpit/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ stackable-operator.workspace = true
3131
tera.workspace = true
3232
tokio.workspace = true
3333
tracing.workspace = true
34+
tracing-indicatif.workspace = true
3435
url.workspace = true
3536
urlencoding.workspace = true
3637
utoipa = { workspace = true, optional = true }
3738
which.workspace = true
3839
futures.workspace = true
40+
indicatif.workspace = true
3941

4042
[dev-dependencies]
4143
rstest.workspace = true

rust/stackable-cockpit/src/engine/docker/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use std::process::Stdio;
22

3+
use indicatif::ProgressStyle;
34
use snafu::{ResultExt, Snafu};
45
use tokio::process::Command;
5-
use tracing::{debug, instrument};
6+
use tracing::{Span, debug, instrument};
7+
use tracing_indicatif::span_ext::IndicatifSpanExt;
68

79
type Result<T, E = Error> = std::result::Result<T, E>;
810

@@ -22,6 +24,7 @@ pub enum Error {
2224
#[instrument(skip_all)]
2325
pub async fn check_if_docker_is_running() -> Result<()> {
2426
debug!("Checking if Docker is running");
27+
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
2528

2629
if Command::new("docker")
2730
.arg("info")

rust/stackable-cockpit/src/engine/kind/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use std::process::Stdio;
22

3+
use indicatif::ProgressStyle;
34
use snafu::{OptionExt, ResultExt, Snafu, ensure};
45
use tokio::{io::AsyncWriteExt, process::Command};
5-
use tracing::{debug, info, instrument};
6+
use tracing::{Span, debug, info, instrument};
7+
use tracing_indicatif::span_ext::IndicatifSpanExt;
68

79
use crate::{
810
engine::{
@@ -67,6 +69,7 @@ impl Cluster {
6769
#[instrument(skip_all)]
6870
pub async fn create(&self) -> Result<()> {
6971
info!("Creating local cluster using kind");
72+
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
7073

7174
// Check if required binaries are present
7275
if let Some(binary) = binaries_present_with_name(&["docker", "kind"]) {
@@ -112,6 +115,7 @@ impl Cluster {
112115
#[instrument(skip_all)]
113116
pub async fn create_if_not_exists(&self) -> Result<()> {
114117
info!("Creating cluster if it doesn't exist using kind");
118+
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
115119

116120
if Self::check_if_cluster_exists(&self.name).await? {
117121
return Ok(());
@@ -134,16 +138,20 @@ impl Cluster {
134138
#[instrument(skip_all)]
135139
async fn check_if_cluster_exists(cluster_name: &str) -> Result<bool> {
136140
debug!("Checking if kind cluster exists");
141+
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
137142

138143
let output = Command::new("kind")
139144
.args(["get", "clusters"])
140145
.output()
141146
.await
142147
.context(CommandFailedToRunSnafu)?;
143148

144-
ensure!(output.status.success(), CommandErroredOutSnafu {
145-
error: String::from_utf8_lossy(&output.stderr)
146-
});
149+
ensure!(
150+
output.status.success(),
151+
CommandErroredOutSnafu {
152+
error: String::from_utf8_lossy(&output.stderr)
153+
}
154+
);
147155

148156
let output = String::from_utf8_lossy(&output.stdout);
149157
Ok(output.lines().any(|name| name == cluster_name))

rust/stackable-cockpit/src/engine/minikube/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
use indicatif::ProgressStyle;
12
use snafu::{ResultExt, Snafu};
23
use tokio::process::Command;
3-
use tracing::{debug, info, instrument};
4+
use tracing::{Span, debug, info, instrument};
5+
use tracing_indicatif::span_ext::IndicatifSpanExt;
46

57
use crate::{
68
engine::docker::{self, check_if_docker_is_running},
@@ -44,6 +46,7 @@ impl Cluster {
4446
#[instrument(skip_all)]
4547
pub async fn create(&self) -> Result<(), Error> {
4648
info!("Creating local cluster using Minikube");
49+
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
4750

4851
// Check if required binaries are present
4952
if let Some(binary) = binaries_present_with_name(&["docker", "minikube"]) {
@@ -73,6 +76,7 @@ impl Cluster {
7376
#[instrument(skip_all)]
7477
pub async fn create_if_not_exists(&self) -> Result<(), Error> {
7578
info!("Creating cluster if it doesn't exist using Minikube");
79+
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
7680

7781
if Self::check_if_cluster_exists(&self.name).await? {
7882
return Ok(());
@@ -95,6 +99,7 @@ impl Cluster {
9599
#[instrument(skip_all)]
96100
async fn check_if_cluster_exists(cluster_name: &str) -> Result<bool, Error> {
97101
debug!("Checking if Minikube cluster exists");
102+
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
98103

99104
let output = Command::new("minikube")
100105
.arg("status")

0 commit comments

Comments
 (0)