Skip to content

Commit d57492c

Browse files
authored
fix: Uninstall operators when removing release (#174)
* fix: Uninstall operators when removing release * Update linked PR in changelog * Add review suggestions
1 parent 85da206 commit d57492c

File tree

7 files changed

+47
-22
lines changed

7 files changed

+47
-22
lines changed

rust/stackable-cockpit/src/helm.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,12 @@ pub struct ChartVersion<'a> {
186186
pub chart_version: Option<&'a str>,
187187
}
188188

189-
/// Installs a Helm release
189+
/// Installs a Helm release from a repo.
190+
///
191+
/// This function expects the fully qualified Helm release name. In case of our
192+
/// operators this is: `<PRODUCT_NAME>-operator`.
190193
#[instrument]
191194
pub fn install_release_from_repo(
192-
operator_name: &str,
193195
release_name: &str,
194196
ChartVersion {
195197
repo_name,
@@ -258,6 +260,10 @@ pub fn install_release_from_repo(
258260
Ok(InstallReleaseStatus::Installed(release_name.to_string()))
259261
}
260262

263+
/// Installs a Helm release.
264+
///
265+
/// This function expects the fully qualified Helm release name. In case of our
266+
/// operators this is: `<PRODUCT_NAME>-operator`.
261267
fn install_release(
262268
release_name: &str,
263269
chart_name: &str,
@@ -289,7 +295,10 @@ fn install_release(
289295
Ok(())
290296
}
291297

292-
/// Uninstall a Helm release
298+
/// Uninstall a Helm release.
299+
///
300+
/// This function expects the fully qualified Helm release name. In case of our
301+
/// operators this is: `<PRODUCT_NAME>-operator`.
293302
#[instrument]
294303
pub fn uninstall_release(
295304
release_name: &str,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ impl OperatorSpec {
185185

186186
// Install using Helm
187187
helm::install_release_from_repo(
188-
&self.name,
189188
&helm_name,
190189
helm::ChartVersion {
191190
chart_version: version.as_deref(),

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ use utoipa::ToSchema;
88

99
use crate::{
1010
helm,
11-
platform::{operator, product},
11+
platform::{
12+
operator::{self, OperatorSpec},
13+
product,
14+
},
1215
};
1316

1417
type Result<T, E = Error> = std::result::Result<T, E>;
@@ -52,10 +55,10 @@ impl ReleaseSpec {
5255
info!("Installing release");
5356

5457
for (product_name, product) in self.filter_products(include_products, exclude_products) {
55-
info!("Installing product {}", product_name);
58+
info!("Installing {product_name}-operator");
5659

5760
// Create operator spec
58-
let operator = operator::OperatorSpec::new(product_name, Some(product.version.clone()))
61+
let operator = OperatorSpec::new(product_name, Some(product.version.clone()))
5962
.context(OperatorSpecParseSnafu)?;
6063

6164
// Install operator
@@ -65,9 +68,20 @@ impl ReleaseSpec {
6568
Ok(())
6669
}
6770

71+
#[instrument(skip_all)]
6872
pub fn uninstall(&self, namespace: &str) -> Result<()> {
69-
for (product_name, _) in &self.products {
70-
helm::uninstall_release(product_name, namespace, true).context(HelmUninstallSnafu)?;
73+
info!("Uninstalling release");
74+
75+
for (product_name, product_spec) in &self.products {
76+
info!("Uninstalling {product_name}-operator");
77+
78+
// Create operator spec
79+
let operator = OperatorSpec::new(product_name, Some(product_spec.version.clone()))
80+
.context(OperatorSpecParseSnafu)?;
81+
82+
// Uninstall operator
83+
helm::uninstall_release(&operator.helm_name(), namespace, true)
84+
.context(HelmUninstallSnafu)?;
7185
}
7286

7387
Ok(())

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ pub async fn get_endpoint_urls_for_loadbalancer(
192192
.as_ref()
193193
.and_then(|s| s.load_balancer.as_ref())
194194
.and_then(|l| l.ingress.as_ref())
195-
.and_then(|l| l.get(0));
195+
.and_then(|l| l.first());
196196

197197
if let Some(lb_host) = lb_host {
198198
let lb_host = lb_host.hostname.as_ref().or(lb_host.ip.as_ref());

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ impl StackSpec {
286286

287287
// Install the Helm chart using the Helm wrapper
288288
helm::install_release_from_repo(
289-
&helm_chart.release_name,
290289
&helm_chart.release_name,
291290
helm::ChartVersion {
292291
repo_name: &helm_chart.repo.name,

rust/stackablectl/CHANGELOG.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Fixed
8+
9+
- Fix `stackablectl release uninstall` command. It now deletes the operators included in the selected release correctly
10+
([#174]).
11+
12+
[#174]: https://github.com/stackabletech/stackable-cockpit/pull/174
13+
714
## [23.11.2] - 2024-01-02
815

916
### Changed
1017

11-
- Bumped Rust version from `1.74.0` to `1.75.0` ([#172]).
12-
- Bumped Rust and Go dependencies ([#135], [#162], [#167], [#168], [#170]).
13-
- Renamed old output style `plain` to `table`. The new output option `plain` will output a reduced view (which removes
18+
- Bump Rust version from `1.74.0` to `1.75.0` ([#172]).
19+
- Bump Rust and Go dependencies ([#135], [#162], [#167], [#168], [#170]).
20+
- Rename old output style `plain` to `table`. The new output option `plain` will output a reduced view (which removes
1421
borders from tables for example) ([#142], [#163]).
1522

1623
[#135]: https://github.com/stackabletech/stackable-cockpit/pull/135
@@ -36,6 +43,6 @@ First official release of the `stackablectl` rewrite.
3643

3744
### Changed
3845

39-
- Bumped Rust version from `1.73.0` to `1.74.0` ([#151]).
46+
- Bump Rust version from `1.73.0` to `1.74.0` ([#151]).
4047

4148
[#151]: https://github.com/stackabletech/stackable-cockpit/pull/151

rust/stackablectl/src/cmds/release.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl ReleaseArgs {
145145
}
146146
}
147147

148-
#[instrument]
148+
#[instrument(skip(cli, release_list))]
149149
async fn list_cmd(
150150
args: &ReleaseListArgs,
151151
cli: &Cli,
@@ -199,7 +199,7 @@ async fn list_cmd(
199199
}
200200
}
201201

202-
#[instrument]
202+
#[instrument(skip(cli, release_list))]
203203
async fn describe_cmd(
204204
args: &ReleaseDescribeArgs,
205205
cli: &Cli,
@@ -260,14 +260,12 @@ async fn describe_cmd(
260260
}
261261
}
262262

263-
#[instrument]
263+
#[instrument(skip(cli, release_list))]
264264
async fn install_cmd(
265265
args: &ReleaseInstallArgs,
266266
cli: &Cli,
267267
release_list: release::List,
268268
) -> Result<String, CmdError> {
269-
info!("Installing release");
270-
271269
match release_list.get(&args.release) {
272270
Some(release) => {
273271
let mut output = cli.result();
@@ -306,13 +304,12 @@ async fn install_cmd(
306304
}
307305
}
308306

307+
#[instrument(skip(cli, release_list))]
309308
async fn uninstall_cmd(
310309
args: &ReleaseUninstallArgs,
311310
cli: &Cli,
312311
release_list: release::List,
313312
) -> Result<String, CmdError> {
314-
info!("Installing release");
315-
316313
match release_list.get(&args.release) {
317314
Some(release) => {
318315
release

0 commit comments

Comments
 (0)