Skip to content

Commit 8dd56cd

Browse files
committed
only upgrade installed operators and specifically included ones
1 parent 45ab412 commit 8dd56cd

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

rust/stackablectl/src/cmds/release.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ use snafu::{ResultExt, Snafu};
77
use stackable_cockpit::{
88
common::list,
99
constants::DEFAULT_OPERATOR_NAMESPACE,
10-
platform::{namespace, operator::ChartSourceType, release},
10+
helm::{self, Release},
11+
platform::{
12+
namespace,
13+
operator::{self, ChartSourceType},
14+
release,
15+
},
1116
utils::{
17+
self,
1218
k8s::{self, Client},
1319
path::PathOrUrlParseError,
1420
},
@@ -118,6 +124,9 @@ pub struct ReleaseUninstallArgs {
118124

119125
#[derive(Debug, Snafu)]
120126
pub enum CmdError {
127+
#[snafu(display("Helm error"))]
128+
HelmError { source: helm::Error },
129+
121130
#[snafu(display("failed to serialize YAML output"))]
122131
SerializeYamlOutput { source: serde_yaml::Error },
123132

@@ -353,19 +362,40 @@ async fn upgrade_cmd(
353362
let mut output = cli.result();
354363
let client = Client::new().await.context(KubeClientCreateSnafu)?;
355364

365+
// Get all currently installed operators to only upgrade those
366+
let installed_charts: Vec<Release> =
367+
helm::list_releases(&args.operator_namespace).context(HelmSnafu)?;
368+
369+
let mut operators: Vec<String> = operator::VALID_OPERATORS
370+
.iter()
371+
.filter(|operator| {
372+
installed_charts
373+
.iter()
374+
.any(|release| release.name == utils::operator_chart_name(operator))
375+
})
376+
.map(|operator| operator.to_string())
377+
.collect();
378+
356379
// Uninstall the old operator release first
357380
release
358381
.uninstall(
359-
&args.included_products,
382+
&operators,
360383
&args.excluded_products,
361384
&args.operator_namespace,
362385
)
363386
.context(ReleaseUninstallSnafu)?;
364387

388+
// If operators were added to args.included_products, install them as well
389+
for product in &args.included_products {
390+
if !operators.contains(product) {
391+
operators.push(product.clone());
392+
}
393+
}
394+
365395
// Upgrade the CRDs for all the operators to be upgraded
366396
release
367397
.upgrade_crds(
368-
&args.included_products,
398+
&operators,
369399
&args.excluded_products,
370400
&args.operator_namespace,
371401
&client,
@@ -376,7 +406,7 @@ async fn upgrade_cmd(
376406
// Install the new operator release
377407
release
378408
.install(
379-
&args.included_products,
409+
&operators,
380410
&args.excluded_products,
381411
&args.operator_namespace,
382412
&ChartSourceType::from(cli.chart_type()),

0 commit comments

Comments
 (0)