Skip to content

Commit 7a9e870

Browse files
committed
refactor progress messages setup
1 parent f85cf1e commit 7a9e870

File tree

13 files changed

+124
-201
lines changed

13 files changed

+124
-201
lines changed

rust/stackable-cockpit/src/helm.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use std::fmt::Display;
33
use serde::{Deserialize, Serialize};
44
use snafu::{ResultExt, Snafu};
55
use tokio::task::block_in_place;
6-
use tracing::{debug, error, info, instrument};
6+
use tracing::{debug, error, info, instrument, Span};
7+
use tracing_indicatif::span_ext::IndicatifSpanExt as _;
78
use url::Url;
89

910
use crate::{
@@ -183,7 +184,7 @@ pub struct ChartVersion<'a> {
183184
///
184185
/// This function expects the fully qualified Helm release name. In case of our
185186
/// operators this is: `<PRODUCT_NAME>-operator`.
186-
#[instrument(skip(values_yaml), fields(with_values = values_yaml.is_some()))]
187+
#[instrument(skip(values_yaml), fields(with_values = values_yaml.is_some(), indicatif.pb_show = true))]
187188
pub fn install_release_from_repo_or_registry(
188189
release_name: &str,
189190
ChartVersion {
@@ -199,6 +200,10 @@ pub fn install_release_from_repo_or_registry(
199200
// but that requires a larger refactoring
200201
block_in_place(|| {
201202
debug!("Install Helm release from repo");
203+
Span::current().pb_set_message(
204+
format!("Installing {name} Helm chart", name = chart_name)
205+
.as_str(),
206+
);
202207

203208
if check_release_exists(release_name, namespace)? {
204209
let release = get_release(release_name, namespace)?.ok_or(Error::InstallRelease {
@@ -297,13 +302,14 @@ fn install_release(
297302
///
298303
/// This function expects the fully qualified Helm release name. In case of our
299304
/// operators this is: `<PRODUCT_NAME>-operator`.
300-
#[instrument]
305+
#[instrument(fields(indicatif.pb_show = true))]
301306
pub fn uninstall_release(
302307
release_name: &str,
303308
namespace: &str,
304309
suppress_output: bool,
305310
) -> Result<UninstallReleaseStatus, Error> {
306311
debug!("Uninstall Helm release");
312+
Span::current().pb_set_message(format!("Uninstalling {name}-operator", name = release_name).as_str());
307313

308314
if check_release_exists(release_name, namespace)? {
309315
let result = helm_sys::uninstall_helm_release(release_name, namespace, suppress_output);

rust/stackable-cockpit/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ pub mod xfer;
1313

1414
pub static PROGRESS_BAR_STYLE: LazyLock<ProgressStyle> = LazyLock::new(|| {
1515
ProgressStyle::with_template(
16-
"{span_child_prefix_indent}Progress: {wide_bar:.magenta/cyan} {pos}/{len}",
16+
"{span_child_prefix}Progress: {wide_bar:.magenta/cyan} {pos}/{len}",
1717
)
1818
.expect("valid progress template")
1919
});
2020

2121
pub static PROGRESS_SPINNER_STYLE: LazyLock<ProgressStyle> = LazyLock::new(|| {
22-
ProgressStyle::with_template("{span_child_prefix_indent}{spinner} {msg}")
22+
ProgressStyle::with_template("{span_child_prefix}{spinner} {msg}")
2323
.expect("valid progress template")
2424
});

rust/stackable-cockpit/src/platform/demo/spec.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use indicatif::ProgressStyle;
21
use serde::{Deserialize, Serialize};
32
use snafu::{OptionExt, ResultExt, Snafu};
43
use tracing::{Span, debug, info, instrument, warn};
@@ -183,6 +182,7 @@ impl DemoSpec {
183182
stack_name = %self.stack,
184183
operator_namespace = %install_params.operator_namespace,
185184
demo_namespace = %install_params.demo_namespace,
185+
indicatif.pb_show = true
186186
))]
187187
async fn prepare_manifests(
188188
&self,
@@ -191,10 +191,7 @@ impl DemoSpec {
191191
transfer_client: &xfer::Client,
192192
) -> Result<(), Error> {
193193
info!("Installing demo manifests");
194-
Span::current().pb_set_style(
195-
&ProgressStyle::with_template("{spinner} Installing manifests")
196-
.expect("valid progress template"),
197-
);
194+
Span::current().pb_set_message("Installing manifests");
198195

199196
let params = install_params
200197
.parameters

rust/stackable-cockpit/src/platform/manifests.rs

Lines changed: 64 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use std::collections::HashMap;
22

3-
use indicatif::ProgressStyle;
43
use snafu::{ResultExt, Snafu};
54
use stackable_operator::kvp::Labels;
6-
use tracing::{Instrument as _, Span, debug, info, info_span, instrument};
5+
use tracing::{Span, debug, info, instrument};
76
use tracing_indicatif::span_ext::IndicatifSpanExt as _;
87

98
use crate::{
@@ -65,7 +64,7 @@ pub enum Error {
6564

6665
pub trait InstallManifestsExt {
6766
// TODO (Techassi): This step shouldn't care about templating the manifests nor fetching them from remote
68-
#[instrument(skip_all, fields(%namespace))]
67+
#[instrument(skip_all, fields(%namespace, indicatif.pb_show = true))]
6968
#[allow(async_fn_in_trait)]
7069
async fn install_manifests(
7170
manifests: &[ManifestSpec],
@@ -86,94 +85,75 @@ pub trait InstallManifestsExt {
8685
parameters.insert("NAMESPACE".to_owned(), namespace.to_owned());
8786

8887
for manifest in manifests {
89-
let span = info_span!("install_manifests_iter");
90-
9188
let parameters = parameters.clone();
9289
let labels = labels.clone();
93-
async move {
94-
match manifest {
95-
ManifestSpec::HelmChart(helm_file) => {
96-
debug!(helm_file, "Installing manifest from Helm chart");
97-
98-
// Read Helm chart YAML and apply templating
99-
let helm_file =
100-
helm_file.into_path_or_url().context(ParsePathOrUrlSnafu {
101-
path_or_url: helm_file.clone(),
102-
})?;
10390

104-
let helm_chart: helm::Chart = transfer_client
105-
.get(&helm_file, &Template::new(&parameters).then(Yaml::new()))
106-
.await
107-
.context(FileTransferSnafu)?;
108-
109-
info!(helm_chart.name, helm_chart.version, "Installing Helm chart",);
110-
Span::current().pb_set_message(
111-
format!("Installing {name} Helm chart", name = helm_chart.name)
112-
.as_str(),
113-
);
114-
Span::current().pb_set_style(
115-
&ProgressStyle::with_template("{spinner} {msg}")
116-
.expect("valid progress template"),
117-
);
118-
119-
// Assumption: that all manifest helm charts refer to repos not registries
120-
helm::add_repo(&helm_chart.repo.name, &helm_chart.repo.url).context(
121-
AddHelmRepositorySnafu {
122-
repo_name: helm_chart.repo.name.clone(),
123-
},
124-
)?;
125-
126-
// Serialize chart options to string
127-
let values_yaml = serde_yaml::to_string(&helm_chart.options)
128-
.context(SerializeOptionsSnafu)?;
129-
130-
// Install the Helm chart using the Helm wrapper
131-
helm::install_release_from_repo_or_registry(
132-
&helm_chart.release_name,
133-
helm::ChartVersion {
134-
chart_source: &helm_chart.repo.name,
135-
chart_name: &helm_chart.name,
136-
chart_version: Some(&helm_chart.version),
137-
},
138-
Some(&values_yaml),
139-
namespace,
140-
true,
141-
)
142-
.context(InstallHelmReleaseSnafu {
143-
release_name: helm_chart.release_name,
91+
match manifest {
92+
ManifestSpec::HelmChart(helm_file) => {
93+
debug!(helm_file, "Installing manifest from Helm chart");
94+
95+
// Read Helm chart YAML and apply templating
96+
let helm_file =
97+
helm_file.into_path_or_url().context(ParsePathOrUrlSnafu {
98+
path_or_url: helm_file.clone(),
14499
})?;
145-
}
146-
ManifestSpec::PlainYaml(manifest_file) => {
147-
debug!(manifest_file, "Installing YAML manifest");
148-
Span::current().pb_set_style(
149-
&ProgressStyle::with_template("{spinner} Installing YAML manifest")
150-
.expect("valid progress template"),
151-
);
152-
153-
// Read YAML manifest and apply templating
154-
let path_or_url =
155-
manifest_file
156-
.into_path_or_url()
157-
.context(ParsePathOrUrlSnafu {
158-
path_or_url: manifest_file.clone(),
159-
})?;
160-
161-
let manifests = transfer_client
162-
.get(&path_or_url, &Template::new(&parameters))
163-
.await
164-
.context(FileTransferSnafu)?;
165-
166-
client
167-
.deploy_manifests(&manifests, namespace, labels.clone())
168-
.await
169-
.context(DeployManifestSnafu)?;
170-
}
100+
101+
let helm_chart: helm::Chart = transfer_client
102+
.get(&helm_file, &Template::new(&parameters).then(Yaml::new()))
103+
.await
104+
.context(FileTransferSnafu)?;
105+
106+
info!(helm_chart.name, helm_chart.version, "Installing Helm chart",);
107+
108+
// Assumption: that all manifest helm charts refer to repos not registries
109+
helm::add_repo(&helm_chart.repo.name, &helm_chart.repo.url).context(
110+
AddHelmRepositorySnafu {
111+
repo_name: helm_chart.repo.name.clone(),
112+
},
113+
)?;
114+
115+
// Serialize chart options to string
116+
let values_yaml = serde_yaml::to_string(&helm_chart.options)
117+
.context(SerializeOptionsSnafu)?;
118+
119+
// Install the Helm chart using the Helm wrapper
120+
helm::install_release_from_repo_or_registry(
121+
&helm_chart.release_name,
122+
helm::ChartVersion {
123+
chart_source: &helm_chart.repo.name,
124+
chart_name: &helm_chart.name,
125+
chart_version: Some(&helm_chart.version),
126+
},
127+
Some(&values_yaml),
128+
namespace,
129+
true,
130+
)
131+
.context(InstallHelmReleaseSnafu {
132+
release_name: helm_chart.release_name,
133+
})?;
171134
}
135+
ManifestSpec::PlainYaml(manifest_file) => {
136+
debug!(manifest_file, "Installing YAML manifest");
137+
138+
// Read YAML manifest and apply templating
139+
let path_or_url =
140+
manifest_file
141+
.into_path_or_url()
142+
.context(ParsePathOrUrlSnafu {
143+
path_or_url: manifest_file.clone(),
144+
})?;
145+
146+
let manifests = transfer_client
147+
.get(&path_or_url, &Template::new(&parameters))
148+
.await
149+
.context(FileTransferSnafu)?;
172150

173-
Ok::<(), Error>(())
151+
client
152+
.deploy_manifests(&manifests, namespace, labels.clone())
153+
.await
154+
.context(DeployManifestSnafu)?;
155+
}
174156
}
175-
.instrument(span)
176-
.await?;
177157

178158
Span::current().pb_inc(1);
179159
}

rust/stackable-cockpit/src/platform/operator/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::{fmt::Display, str::FromStr};
22

3-
use indicatif::ProgressStyle;
43
use semver::Version;
54
use serde::Serialize;
65
use snafu::{ResultExt, Snafu, ensure};
@@ -186,6 +185,7 @@ impl OperatorSpec {
186185
// display for the inner type if it exists. Otherwise we gte the Debug
187186
// impl for the whole Option.
188187
version = self.version.as_ref().map(tracing::field::display),
188+
indicatif.pb_show = true
189189
))]
190190
pub fn install(
191191
&self,
@@ -195,9 +195,6 @@ impl OperatorSpec {
195195
info!(operator = %self, "Installing operator");
196196
Span::current()
197197
.pb_set_message(format!("Installing {name}-operator", name = self.name).as_str());
198-
Span::current().pb_set_style(
199-
&ProgressStyle::with_template("{spinner} {msg}").expect("valid progress template"),
200-
);
201198

202199
let version = self.version.as_ref().map(|v| v.to_string());
203200
let helm_name = self.helm_name();

rust/stackable-cockpit/src/platform/release/spec.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ impl ReleaseSpec {
5454
%namespace,
5555
product.included = tracing::field::Empty,
5656
product.excluded = tracing::field::Empty,
57+
indicatif.pb_show = true
5758
))]
5859
pub async fn install(
5960
&self,
@@ -117,7 +118,7 @@ impl ReleaseSpec {
117118
.await
118119
}
119120

120-
#[instrument(skip_all)]
121+
#[instrument(skip_all, fields(indicatif.pb_show = true))]
121122
pub fn uninstall(&self, namespace: &str) -> Result<()> {
122123
info!("Uninstalling release");
123124

rust/stackable-cockpit/src/platform/stack/spec.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use indicatif::ProgressStyle;
21
use serde::{Deserialize, Serialize};
32
use snafu::{OptionExt, ResultExt, Snafu};
43
use tracing::{Span, debug, info, instrument, log::warn};
@@ -196,7 +195,7 @@ impl StackSpec {
196195
.await
197196
}
198197

199-
#[instrument(skip_all, fields(release = %self.release, %operator_namespace))]
198+
#[instrument(skip_all, fields(release = %self.release, %operator_namespace, indicatif.pb_show = true))]
200199
pub async fn install_release(
201200
&self,
202201
release_list: release::ReleaseList,
@@ -205,10 +204,7 @@ impl StackSpec {
205204
chart_source: &ChartSourceType,
206205
) -> Result<(), Error> {
207206
info!(self.release, "Trying to install release");
208-
Span::current().pb_set_style(
209-
&ProgressStyle::with_template("{spinner} Installing operators")
210-
.expect("valid progress template"),
211-
);
207+
Span::current().pb_set_message("Installing operators");
212208

213209
// Get the release by name
214210
let release = release_list
@@ -224,18 +220,15 @@ impl StackSpec {
224220
.context(InstallReleaseSnafu)
225221
}
226222

227-
#[instrument(skip_all)]
223+
#[instrument(skip_all, fields(indicatif.pb_show = true))]
228224
pub async fn prepare_manifests(
229225
&self,
230226
install_params: StackInstallParameters,
231227
client: &Client,
232228
transfer_client: &xfer::Client,
233229
) -> Result<(), Error> {
234230
info!("Installing stack manifests");
235-
Span::current().pb_set_style(
236-
&ProgressStyle::with_template("{spinner} Installing manifests")
237-
.expect("valid progress template"),
238-
);
231+
Span::current().pb_set_message("Installing manifests");
239232

240233
let parameters = install_params
241234
.parameters

rust/stackable-cockpit/src/utils/k8s/client.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use serde::Deserialize;
1414
use snafu::{OptionExt, ResultExt, Snafu};
1515
use stackable_operator::{commons::listener::Listener, kvp::Labels};
1616
use tokio::sync::RwLock;
17-
use tracing::info;
17+
use tracing::{info, instrument, Span};
18+
use tracing_indicatif::span_ext::IndicatifSpanExt as _;
1819

1920
#[cfg(doc)]
2021
use crate::utils::k8s::ListParamsExt;
@@ -98,12 +99,15 @@ impl Client {
9899
/// Deploys manifests defined the in raw `manifests` YAML string. This
99100
/// method will fail if it is unable to parse the manifests, unable to
100101
/// resolve GVKs or unable to patch the dynamic objects.
102+
#[instrument(skip_all, fields(indicatif.pb_show = true))]
101103
pub async fn deploy_manifests(
102104
&self,
103105
manifests: &str,
104106
namespace: &str,
105107
labels: Labels,
106108
) -> Result<()> {
109+
Span::current().pb_set_message("Installing YAML manifest");
110+
107111
// TODO (Techassi): Impl IntoIterator for Labels
108112
let labels: BTreeMap<String, String> = labels.into();
109113

0 commit comments

Comments
 (0)