Skip to content

Commit 20a3ef0

Browse files
committed
error handling and include/exclude operators in/from upgrading
1 parent 55e80a5 commit 20a3ef0

File tree

3 files changed

+43
-26
lines changed

3 files changed

+43
-26
lines changed

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

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ pub enum Error {
3535
#[snafu(display("failed to deploy manifests using the kube client"))]
3636
DeployManifest { source: k8s::Error },
3737

38+
#[snafu(display("failed to construct a valid request"))]
39+
ConstructRequest { source: reqwest::Error },
40+
3841
#[snafu(display("failed to access the CRDs from source"))]
3942
AccessCRDs { source: reqwest::Error },
4043

@@ -129,7 +132,7 @@ impl ReleaseSpec {
129132
namespace: &str,
130133
k8s_client: &Client,
131134
) -> Result<()> {
132-
debug!("Upgrading CRDs for release");
135+
info!("Upgrading CRDs for release");
133136

134137
include_products.iter().for_each(|product| {
135138
Span::current().record("product.included", product);
@@ -139,36 +142,31 @@ impl ReleaseSpec {
139142
});
140143

141144
let client = reqwest::Client::new();
142-
143145
let operators = self.filter_products(include_products, exclude_products);
144146

145-
Span::current().pb_set_style(
146-
&ProgressStyle::with_template("Upgrading CRDs {wide_bar} {pos}/{len}").unwrap(),
147-
);
148-
Span::current().pb_set_length(operators.len() as u64);
149-
150147
for (product_name, product) in operators {
151-
Span::current().record("product_name", &product_name);
152-
debug!("Upgrading CRDs for {product_name}-operator");
148+
info!("Upgrading CRDs for {product_name}-operator");
153149

154-
let release = match product.version.pre.as_str() {
150+
let release_branch = match product.version.pre.as_str() {
155151
"dev" => "main".to_string(),
156152
_ => {
157153
format!("{}", product.version)
158154
}
159155
};
160156

161157
let request_url = format!(
162-
"https://raw.githubusercontent.com/stackabletech/{product_name}-operator/{release}/deploy/helm/{product_name}-operator/crds/crds.yaml"
158+
"https://raw.githubusercontent.com/stackabletech/{product_name}-operator/{release_branch}/deploy/helm/{product_name}-operator/crds/crds.yaml"
163159
);
164160

165-
// Get CRD manifests
166-
// TODO bei nicht 200 Status, Fehler werfen
161+
// Get CRD manifests from request_url
167162
let response = client
168163
.get(request_url)
169164
.send()
170165
.await
166+
.context(ConstructRequestSnafu)?
167+
.error_for_status()
171168
.context(AccessCRDsSnafu)?;
169+
172170
let crd_manifests = response.text().await.context(ReadManifestsSnafu)?;
173171

174172
// Upgrade CRDs
@@ -177,18 +175,29 @@ impl ReleaseSpec {
177175
.await
178176
.context(DeployManifestSnafu)?;
179177

180-
debug!("Upgraded {product_name}-operator CRDs");
181-
Span::current().pb_inc(1);
178+
info!("Upgraded {product_name}-operator CRDs");
182179
}
183180

184181
Ok(())
185182
}
186183

187184
#[instrument(skip_all)]
188-
pub fn uninstall(&self, namespace: &str) -> Result<()> {
185+
pub fn uninstall(&self,
186+
include_products: &[String],
187+
exclude_products: &[String],
188+
namespace: &str) -> Result<()> {
189189
info!("Uninstalling release");
190190

191-
for (product_name, product_spec) in &self.products {
191+
include_products.iter().for_each(|product| {
192+
Span::current().record("product.included", product);
193+
});
194+
exclude_products.iter().for_each(|product| {
195+
Span::current().record("product.excluded", product);
196+
});
197+
198+
let operators = self.filter_products(include_products, exclude_products);
199+
200+
for (product_name, product_spec) in operators {
192201
info!("Uninstalling {product_name}-operator");
193202

194203
// Create operator spec

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ pub enum Error {
3737
#[snafu(display("failed to patch/create Kubernetes object"))]
3838
KubeClientPatch { source: kube::error::Error },
3939

40+
#[snafu(display("failed to replace Kubernetes object"))]
41+
KubeClientReplace { source: kube::error::Error },
42+
4043
#[snafu(display("failed to deserialize YAML data"))]
4144
DeserializeYaml { source: serde_yaml::Error },
4245

@@ -65,9 +68,6 @@ pub enum Error {
6568
#[snafu(display("failed to retrieve cluster information"))]
6669
ClusterInformation { source: cluster::Error },
6770

68-
#[snafu(display("failed to retrieve previous resource version information"))]
69-
ResourceVersion { source: kube::error::Error },
70-
7171
#[snafu(display("invalid or empty secret data in '{secret_name}'"))]
7272
InvalidSecretData { secret_name: String },
7373

@@ -151,6 +151,9 @@ impl Client {
151151
Ok(())
152152
}
153153

154+
/// Replaces CRDs defined the in raw `crds` YAML string. This
155+
/// method will fail if it is unable to parse the CRDs, unable to
156+
/// resolve GVKs or unable to replace/create the dynamic objects.
154157
pub async fn replace_crds(&self, crds: &str) -> Result<()> {
155158
for crd in serde_yaml::Deserializer::from_str(crds) {
156159
let mut object = DynamicObject::deserialize(crd).context(DeserializeYamlSnafu)?;
@@ -179,12 +182,12 @@ impl Client {
179182
object.metadata.resource_version = resource.resource_version();
180183
api.replace(&object.name_any(), &PostParams::default(), &object)
181184
.await
182-
.context(KubeClientPatchSnafu)?;
185+
.context(KubeClientReplaceSnafu)?;
183186
} else {
184187
// Create CRD if a previous version wasn't found
185188
api.create(&PostParams::default(), &object)
186189
.await
187-
.context(KubeClientCreateSnafu)?;
190+
.context(KubeClientPatchSnafu)?;
188191
}
189192
}
190193

rust/stackablectl/src/cmds/release.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,7 @@ async fn upgrade_cmd(
346346
cli: &Cli,
347347
release_list: release::ReleaseList,
348348
) -> Result<String, CmdError> {
349-
debug!(release = %args.release, "Upgrading release");
350-
Span::current().pb_set_style(&ProgressStyle::with_template("").unwrap());
349+
info!(release = %args.release, "Upgrading release");
351350

352351
match release_list.get(&args.release) {
353352
Some(release) => {
@@ -356,7 +355,10 @@ async fn upgrade_cmd(
356355

357356
// Uninstall the old operator release first
358357
release
359-
.uninstall(&args.operator_namespace)
358+
.uninstall(
359+
&args.included_products,
360+
&args.excluded_products,
361+
&args.operator_namespace)
360362
.context(ReleaseUninstallSnafu)?;
361363

362364
// Upgrade the CRDs for all the operators to be upgraded
@@ -403,7 +405,10 @@ async fn uninstall_cmd(
403405
match release_list.get(&args.release) {
404406
Some(release) => {
405407
release
406-
.uninstall(&args.operator_namespace)
408+
.uninstall(
409+
&Vec::new(),
410+
&Vec::new(),
411+
&args.operator_namespace)
407412
.context(ReleaseUninstallSnafu)?;
408413

409414
let mut result = cli.result();

0 commit comments

Comments
 (0)