Skip to content

Commit ba37ff7

Browse files
committed
add progress indication for installing manifests
1 parent 3a37410 commit ba37ff7

File tree

1 file changed

+78
-66
lines changed

1 file changed

+78
-66
lines changed

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

Lines changed: 78 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::collections::HashMap;
33
use indicatif::ProgressStyle;
44
use snafu::{ResultExt, Snafu};
55
use stackable_operator::kvp::Labels;
6-
use tracing::{Span, debug, info, instrument};
6+
use tracing::{debug, info, info_span, instrument, Instrument as _, Span};
77
use tracing_indicatif::span_ext::IndicatifSpanExt as _;
88

99
use crate::{
@@ -87,74 +87,86 @@ pub trait InstallManifestsExt {
8787
parameters.insert("NAMESPACE".to_owned(), namespace.to_owned());
8888

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

156168
Span::current().pb_inc(1);
157-
}
169+
};
158170

159171
Ok(())
160172
}

0 commit comments

Comments
 (0)