Skip to content

Commit 9f6f8e6

Browse files
committed
use client with cache to fetch CRDs
1 parent 2e6b8a5 commit 9f6f8e6

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

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

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ use crate::{
1414
operator::{self, ChartSourceType, OperatorSpec},
1515
product,
1616
},
17-
utils::k8s::{self, Client},
17+
utils::{
18+
k8s::{self, Client},
19+
path::{IntoPathOrUrl as _, PathOrUrlParseError},
20+
},
21+
xfer::{self, processor::Text},
1822
};
1923

2024
type Result<T, E = Error> = std::result::Result<T, E>;
@@ -24,6 +28,17 @@ pub enum Error {
2428
#[snafu(display("failed to parse operator spec"))]
2529
OperatorSpecParse { source: operator::SpecParseError },
2630

31+
/// This error indicates that parsing a string into a path or URL failed.
32+
#[snafu(display("failed to parse '{path_or_url}' as path/url"))]
33+
ParsePathOrUrl {
34+
source: PathOrUrlParseError,
35+
path_or_url: String,
36+
},
37+
38+
/// This error indicates that receiving remote content failed.
39+
#[snafu(display("failed to receive remote content"))]
40+
FileTransfer { source: xfer::Error },
41+
2742
#[snafu(display("failed to install release using Helm"))]
2843
HelmInstall { source: helm::Error },
2944

@@ -35,15 +50,6 @@ pub enum Error {
3550

3651
#[snafu(display("failed to deploy manifests using the kube client"))]
3752
DeployManifest { source: k8s::Error },
38-
39-
#[snafu(display("failed to construct a valid request"))]
40-
ConstructRequest { source: reqwest::Error },
41-
42-
#[snafu(display("failed to access the CRDs from source"))]
43-
AccessCRDs { source: reqwest::Error },
44-
45-
#[snafu(display("failed to read CRD manifests"))]
46-
ReadManifests { source: reqwest::Error },
4753
}
4854

4955
#[derive(Clone, Debug, Deserialize, Serialize)]
@@ -142,6 +148,7 @@ impl ReleaseSpec {
142148
exclude_products: &[String],
143149
namespace: &str,
144150
k8s_client: &Client,
151+
transfer_client: &xfer::Client,
145152
) -> Result<()> {
146153
info!("Upgrading CRDs for release");
147154
Span::current().pb_set_style(&PROGRESS_BAR_STYLE);
@@ -153,7 +160,6 @@ impl ReleaseSpec {
153160
Span::current().record("product.excluded", product);
154161
});
155162

156-
let client = reqwest::Client::new();
157163
let operators = self.filter_products(include_products, exclude_products);
158164

159165
Span::current().pb_set_length(operators.len() as u64);
@@ -162,7 +168,6 @@ impl ReleaseSpec {
162168
info!("Upgrading CRDs for {product_name}-operator");
163169
let iter_span = tracing::info_span!("upgrade_crds_iter", indicatif.pb_show = true);
164170

165-
let client = client.clone();
166171
async move {
167172
Span::current().pb_set_message(format!("Ugrading CRDs for {product_name}-operator").as_str());
168173

@@ -173,20 +178,18 @@ impl ReleaseSpec {
173178
}
174179
};
175180

176-
let request_url = format!(
181+
let request_url = &format!(
177182
"https://raw.githubusercontent.com/stackabletech/{product_name}-operator/{release_branch}/deploy/helm/{product_name}-operator/crds/crds.yaml"
178183
);
184+
let request_url = request_url.into_path_or_url().context(ParsePathOrUrlSnafu {
185+
path_or_url: request_url.clone(),
186+
})?;
179187

180188
// Get CRD manifests from request_url
181-
let response = client
182-
.get(request_url)
183-
.send()
189+
let crd_manifests: String = transfer_client
190+
.get(&request_url, &Text)
184191
.await
185-
.context(ConstructRequestSnafu)?
186-
.error_for_status()
187-
.context(AccessCRDsSnafu)?;
188-
189-
let crd_manifests = response.text().await.context(ReadManifestsSnafu)?;
192+
.context(FileTransferSnafu)?;
190193

191194
// Upgrade CRDs
192195
k8s_client

rust/stackable-cockpit/src/xfer/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ impl Client {
120120
.client
121121
.execute(req)
122122
.await
123+
.context(FetchRemoteContentSnafu)?
124+
.error_for_status()
123125
.context(FetchRemoteContentSnafu)?;
124126

125127
result.text().await.context(FetchRemoteContentSnafu)

rust/stackablectl/src/cmds/release.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ impl ReleaseArgs {
181181
ReleaseCommands::Describe(args) => describe_cmd(args, cli, release_list).await,
182182
ReleaseCommands::Install(args) => install_cmd(args, cli, release_list).await,
183183
ReleaseCommands::Uninstall(args) => uninstall_cmd(args, cli, release_list).await,
184-
ReleaseCommands::Upgrade(args) => upgrade_cmd(args, cli, release_list).await,
184+
ReleaseCommands::Upgrade(args) => {
185+
upgrade_cmd(args, cli, release_list, &transfer_client).await
186+
}
185187
}
186188
}
187189
}
@@ -354,11 +356,12 @@ async fn install_cmd(
354356
}
355357
}
356358

357-
#[instrument(skip(cli, release_list), fields(indicatif.pb_show = true))]
359+
#[instrument(skip(cli, release_list, transfer_client), fields(indicatif.pb_show = true))]
358360
async fn upgrade_cmd(
359361
args: &ReleaseUpgradeArgs,
360362
cli: &Cli,
361363
release_list: release::ReleaseList,
364+
transfer_client: &xfer::Client,
362365
) -> Result<String, CmdError> {
363366
info!(release = %args.release, "Upgrading release");
364367
Span::current().pb_set_message("Upgrading release");
@@ -405,6 +408,7 @@ async fn upgrade_cmd(
405408
&args.excluded_products,
406409
&args.operator_namespace,
407410
&client,
411+
transfer_client,
408412
)
409413
.await
410414
.context(CrdUpgradeSnafu)?;

0 commit comments

Comments
 (0)