Skip to content

Commit f329487

Browse files
committed
WIP
1 parent 591d393 commit f329487

File tree

14 files changed

+249
-126
lines changed

14 files changed

+249
-126
lines changed

rust/stackable-cockpit/src/helm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub struct ChartVersion<'a> {
183183
///
184184
/// This function expects the fully qualified Helm release name. In case of our
185185
/// operators this is: `<PRODUCT_NAME>-operator`.
186-
#[instrument(skip(values_yaml), fields(with_values = values_yaml.is_some()))]
186+
#[instrument(skip(values_yaml), fields(with_values = values_yaml.is_some(), indicatif.pb_show = true))]
187187
pub fn install_release_from_repo_or_registry(
188188
release_name: &str,
189189
ChartVersion {
@@ -371,7 +371,7 @@ pub fn get_release(release_name: &str, namespace: &str) -> Result<Option<Release
371371
}
372372

373373
/// Adds a Helm repo with `repo_name` and `repo_url`.
374-
#[instrument]
374+
#[instrument(fields(indicatif.pb_show = true))]
375375
pub fn add_repo(repository_name: &str, repository_url: &str) -> Result<(), Error> {
376376
debug!("Add Helm repo");
377377

rust/stackable-cockpit/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
use std::sync::LazyLock;
2+
3+
use indicatif::ProgressStyle;
4+
15
pub mod common;
26
pub mod constants;
37
pub mod engine;
@@ -6,3 +10,10 @@ pub mod oci;
610
pub mod platform;
711
pub mod utils;
812
pub mod xfer;
13+
14+
pub(crate) static PROGRESS_BAR_STYLE: LazyLock<ProgressStyle> = LazyLock::new(|| {
15+
ProgressStyle::with_template(
16+
"{span_child_prefix:.bold.dim} Progress {msg}: {wide_bar:.magenta/cyan} {pos}/{len}",
17+
)
18+
.expect("valid progress template")
19+
});

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ impl DemoSpec {
183183
stack_name = %self.stack,
184184
operator_namespace = %install_params.operator_namespace,
185185
demo_namespace = %install_params.demo_namespace,
186+
indicatif.pb_show = true
186187
))]
187188
async fn prepare_manifests(
188189
&self,
@@ -191,7 +192,12 @@ impl DemoSpec {
191192
transfer_client: &xfer::Client,
192193
) -> Result<(), Error> {
193194
info!("Installing demo manifests");
194-
Span::current().pb_set_style(&ProgressStyle::with_template("{spinner} Installing manifests").expect("valid progress template"));
195+
// Span::current().pb_set_style(
196+
// &ProgressStyle::with_template(
197+
// "{span_child_prefix:.bold.dim} {spinner} {span_name} Installing manifests",
198+
// )
199+
// .expect("valid progress template"),
200+
// );
195201

196202
let params = install_params
197203
.parameters

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

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
use std::collections::HashMap;
1+
use std::{collections::HashMap, time::Duration};
22

33
use indicatif::ProgressStyle;
44
use snafu::{ResultExt, Snafu};
55
use stackable_operator::kvp::Labels;
6-
use tracing::{debug, info, info_span, instrument, Instrument as _, Span};
6+
use tracing::{Instrument as _, Span, debug, info, info_span, instrument};
77
use tracing_indicatif::span_ext::IndicatifSpanExt as _;
88

99
use crate::{
10+
PROGRESS_BAR_STYLE,
1011
common::manifest::ManifestSpec,
1112
helm,
1213
utils::{
@@ -64,7 +65,7 @@ pub enum Error {
6465

6566
pub trait InstallManifestsExt {
6667
// TODO (Techassi): This step shouldn't care about templating the manifests nor fetching them from remote
67-
#[instrument(skip_all, fields(%namespace))]
68+
#[instrument(skip_all, fields(%namespace, indicatif.pb_show = true))]
6869
#[allow(async_fn_in_trait)]
6970
async fn install_manifests(
7071
manifests: &[ManifestSpec],
@@ -76,18 +77,21 @@ pub trait InstallManifestsExt {
7677
) -> Result<(), Error> {
7778
debug!("Installing manifests");
7879

79-
Span::current().pb_set_style(
80-
&ProgressStyle::with_template("Progress: {wide_bar} {pos}/{len}").expect("valid progress template")
81-
);
80+
Span::current().pb_set_style(&PROGRESS_BAR_STYLE);
8281
Span::current().pb_set_length(manifests.len() as u64);
8382

83+
tokio::time::sleep(Duration::from_secs(2)).await;
84+
8485
let mut parameters = parameters.clone();
8586
// We add the NAMESPACE parameter, so that stacks/demos can use that to render e.g. the
8687
// fqdn service names [which contain the namespace].
8788
parameters.insert("NAMESPACE".to_owned(), namespace.to_owned());
8889

8990
for manifest in manifests {
90-
let span = info_span!("install_manifests_iter");
91+
let span = tracing::warn_span!("install_manifests_iter", indicatif.pb_show = true);
92+
span.pb_set_style(
93+
&ProgressStyle::with_template("{span_child_prefix} boo {span_name}").unwrap(),
94+
);
9195

9296
let parameters = parameters.clone();
9397
let labels = labels.clone();
@@ -97,18 +101,27 @@ pub trait InstallManifestsExt {
97101
debug!(helm_file, "Installing manifest from Helm chart");
98102

99103
// 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-
})?;
104+
let helm_file =
105+
helm_file.into_path_or_url().context(ParsePathOrUrlSnafu {
106+
path_or_url: helm_file.clone(),
107+
})?;
103108

104109
let helm_chart: helm::Chart = transfer_client
105110
.get(&helm_file, &Template::new(&parameters).then(Yaml::new()))
106111
.await
107112
.context(FileTransferSnafu)?;
108113

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"));
114+
info!(helm_chart.name, helm_chart.version, "Installing Helm chart");
115+
Span::current().pb_set_message(
116+
format!("Installing {name} Helm chart", name = helm_chart.name)
117+
.as_str(),
118+
);
119+
// Span::current().pb_set_style(
120+
// &ProgressStyle::with_template(
121+
// "{span_child_prefix:.bold.dim} {spinner} {span_name}",
122+
// )
123+
// .expect("valid progress template"),
124+
// );
112125

113126
// Assumption: that all manifest helm charts refer to repos not registries
114127
helm::add_repo(&helm_chart.repo.name, &helm_chart.repo.url).context(
@@ -139,7 +152,13 @@ pub trait InstallManifestsExt {
139152
}
140153
ManifestSpec::PlainYaml(manifest_file) => {
141154
debug!(manifest_file, "Installing YAML manifest");
142-
Span::current().pb_set_style(&ProgressStyle::with_template("{spinner} Installing YAML manifest").expect("valid progress template"));
155+
// TODO (@NickLarsenNZ): This span already has a style.
156+
// Span::current().pb_set_style(
157+
// &ProgressStyle::with_template(
158+
// "{span_child_prefix:.bold.dim} {spinner} {span_name} Installing YAML manifest",
159+
// )
160+
// .expect("valid progress template"),
161+
// );
143162

144163
// Read YAML manifest and apply templating
145164
let path_or_url =
@@ -162,8 +181,9 @@ pub trait InstallManifestsExt {
162181
}
163182

164183
Ok::<(), Error>(())
165-
166-
}.instrument(span).await?;
184+
}
185+
.instrument(span)
186+
.await?;
167187

168188
Span::current().pb_inc(1);
169189
}

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use indicatif::ProgressStyle;
44
use semver::Version;
55
use serde::Serialize;
66
use snafu::{ResultExt, Snafu, ensure};
7-
use tracing::{info, instrument, Span};
7+
use tracing::{Span, info, instrument};
88
use tracing_indicatif::{indicatif_println, span_ext::IndicatifSpanExt};
99

1010
use crate::{
@@ -93,10 +93,9 @@ impl FromStr for OperatorSpec {
9393
ensure!(len <= 2, InvalidEqualSignCountSnafu);
9494

9595
// Check if the provided operator name is in the list of valid operators
96-
ensure!(
97-
VALID_OPERATORS.contains(&parts[0]),
98-
InvalidNameSnafu { name: parts[0] }
99-
);
96+
ensure!(VALID_OPERATORS.contains(&parts[0]), InvalidNameSnafu {
97+
name: parts[0]
98+
});
10099

101100
// If there is only one part, the input didn't include
102101
// the optional version identifier
@@ -187,15 +186,20 @@ impl OperatorSpec {
187186
// display for the inner type if it exists. Otherwise we gte the Debug
188187
// impl for the whole Option.
189188
version = self.version.as_ref().map(tracing::field::display),
189+
indicatif.pb_show = true,
190190
))]
191191
pub fn install(
192192
&self,
193193
namespace: &str,
194194
chart_source: &ChartSourceType,
195195
) -> Result<(), helm::Error> {
196196
info!(operator = %self, "Installing operator");
197-
Span::current().pb_set_message(format!("Installing {name}-operator", name = self.name).as_str());
198-
Span::current().pb_set_style(&ProgressStyle::with_template("{spinner} {msg}").expect("valid progress template"));
197+
Span::current()
198+
.pb_set_message(format!("Installing {name}-operator", name = self.name).as_str());
199+
// Span::current().pb_set_style(
200+
// &ProgressStyle::with_template("{span_child_prefix:.bold.dim} {spinner} {span_name}")
201+
// .expect("valid progress template"),
202+
// );
199203

200204
let version = self.version.as_ref().map(|v| v.to_string());
201205
let helm_name = self.helm_name();

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
use futures::{StreamExt as _, TryStreamExt};
22
use indexmap::IndexMap;
3-
use indicatif::ProgressStyle;
43
use serde::{Deserialize, Serialize};
54
use snafu::{ResultExt, Snafu};
65
use tokio::task::JoinError;
7-
use tracing::{info, instrument, Instrument, Span};
8-
use tracing_indicatif::{span_ext::IndicatifSpanExt as _};
6+
use tracing::{Instrument, Span, info, instrument};
7+
use tracing_indicatif::span_ext::IndicatifSpanExt as _;
98
#[cfg(feature = "openapi")]
109
use utoipa::ToSchema;
1110

1211
use crate::{
13-
helm,
12+
PROGRESS_BAR_STYLE, helm,
1413
platform::{
1514
operator::{self, ChartSourceType, OperatorSpec},
1615
product,
@@ -55,6 +54,7 @@ impl ReleaseSpec {
5554
%namespace,
5655
product.included = tracing::field::Empty,
5756
product.excluded = tracing::field::Empty,
57+
indicatif.pb_show = true,
5858
))]
5959
pub async fn install(
6060
&self,
@@ -64,9 +64,8 @@ impl ReleaseSpec {
6464
chart_source: &ChartSourceType,
6565
) -> Result<()> {
6666
info!("Installing release");
67-
Span::current().pb_set_style(
68-
&ProgressStyle::with_template("Progress: {wide_bar} {pos}/{len}").expect("valid progress template")
69-
);
67+
Span::current().pb_set_message("Progress");
68+
Span::current().pb_set_style(&PROGRESS_BAR_STYLE);
7069

7170
include_products.iter().for_each(|product| {
7271
Span::current().record("product.included", product);
@@ -120,13 +119,11 @@ impl ReleaseSpec {
120119
.await
121120
}
122121

123-
#[instrument(skip_all)]
122+
#[instrument(skip_all, fields(indicatif.pb_show = true))]
124123
pub fn uninstall(&self, namespace: &str) -> Result<()> {
125124
info!("Uninstalling release");
126125

127-
Span::current().pb_set_style(
128-
&ProgressStyle::with_template("Progress: {wide_bar} {pos}/{len}").expect("valid progress template")
129-
);
126+
Span::current().pb_set_style(&PROGRESS_BAR_STYLE);
130127
Span::current().pb_set_length(self.products.len() as u64);
131128

132129
for (product_name, product_spec) in &self.products {

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl StackSpec {
196196
.await
197197
}
198198

199-
#[instrument(skip_all, fields(release = %self.release, %operator_namespace))]
199+
#[instrument(skip_all, fields(release = %self.release, %operator_namespace, indicatif.pb_show = true))]
200200
pub async fn install_release(
201201
&self,
202202
release_list: release::ReleaseList,
@@ -205,7 +205,12 @@ impl StackSpec {
205205
chart_source: &ChartSourceType,
206206
) -> Result<(), Error> {
207207
info!(self.release, "Trying to install release");
208-
Span::current().pb_set_style(&ProgressStyle::with_template("{spinner} Installing operators").expect("valid progress template"));
208+
Span::current().pb_set_style(
209+
&ProgressStyle::with_template(
210+
"{span_child_prefix:.bold.dim} {spinner} {span_name} Installing operators",
211+
)
212+
.expect("valid progress template"),
213+
);
209214

210215
// Get the release by name
211216
let release = release_list
@@ -221,15 +226,18 @@ impl StackSpec {
221226
.context(InstallReleaseSnafu)
222227
}
223228

224-
#[instrument(skip_all)]
229+
#[instrument(skip_all, fields(indicatif.pb_show = true))]
225230
pub async fn prepare_manifests(
226231
&self,
227232
install_params: StackInstallParameters,
228233
client: &Client,
229234
transfer_client: &xfer::Client,
230235
) -> Result<(), Error> {
231236
info!("Installing stack manifests");
232-
Span::current().pb_set_style(&ProgressStyle::with_template("{spinner} Installing manifests").expect("valid progress template"));
237+
// Span::current().pb_set_style(
238+
// &ProgressStyle::with_template("{spinner} {span_name} Installing manifests")
239+
// .expect("valid progress template"),
240+
// );
233241

234242
let parameters = install_params
235243
.parameters

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ 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::{Instrument, info, info_span, instrument};
1818

1919
#[cfg(doc)]
2020
use crate::utils::k8s::ListParamsExt;
@@ -98,6 +98,7 @@ impl Client {
9898
/// Deploys manifests defined the in raw `manifests` YAML string. This
9999
/// method will fail if it is unable to parse the manifests, unable to
100100
/// resolve GVKs or unable to patch the dynamic objects.
101+
#[instrument(skip_all, fields(indicatif.pb_show = true))]
101102
pub async fn deploy_manifests(
102103
&self,
103104
manifests: &str,
@@ -108,6 +109,8 @@ impl Client {
108109
let labels: BTreeMap<String, String> = labels.into();
109110

110111
for manifest in serde_yaml::Deserializer::from_str(manifests) {
112+
let span = info_span!("install_a_manifest", indicatif.pb_show = true);
113+
111114
let mut object = DynamicObject::deserialize(manifest).context(DeserializeYamlSnafu)?;
112115

113116
// Add our own labels to the object
@@ -141,6 +144,7 @@ impl Client {
141144
&PatchParams::apply("stackablectl"),
142145
&Patch::Apply(object),
143146
)
147+
.instrument(span)
144148
.await
145149
.context(KubeClientPatchSnafu)?;
146150
}
@@ -354,16 +358,13 @@ impl Client {
354358
pub async fn create_namespace(&self, name: String) -> Result<()> {
355359
let namespace_api: Api<Namespace> = Api::all(self.client.clone());
356360
namespace_api
357-
.create(
358-
&PostParams::default(),
359-
&Namespace {
360-
metadata: ObjectMeta {
361-
name: Some(name),
362-
..Default::default()
363-
},
361+
.create(&PostParams::default(), &Namespace {
362+
metadata: ObjectMeta {
363+
name: Some(name),
364364
..Default::default()
365365
},
366-
)
366+
..Default::default()
367+
})
367368
.await
368369
.context(KubeClientPatchSnafu)?;
369370

0 commit comments

Comments
 (0)