Skip to content

Commit 4717dd0

Browse files
committed
refactor: remove raw nifi cluster from upgrade
1 parent b264e5c commit 4717dd0

2 files changed

Lines changed: 11 additions & 26 deletions

File tree

rust/operator-binary/src/controller/upgrade.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,16 @@ use snafu::{ResultExt, Snafu};
55
use stackable_operator::{
66
client::Client,
77
k8s_openapi::{api::apps::v1::StatefulSet, apimachinery::pkg::apis::meta::v1::LabelSelector},
8-
kvp::Labels,
9-
v2::types::kubernetes::NamespaceName,
108
};
119

12-
use crate::crd::{APP_NAME, NifiRole, v1alpha1};
10+
use super::ValidatedCluster;
1311

1412
#[derive(Snafu, Debug)]
1513
pub enum Error {
1614
#[snafu(display("failed to fetch deployed StatefulSets"))]
1715
FetchStatefulsets {
1816
source: stackable_operator::client::Error,
1917
},
20-
21-
#[snafu(display("failed to build labels"))]
22-
LabelBuild {
23-
source: stackable_operator::kvp::LabelError,
24-
},
2518
}
2619

2720
type Result<T, E = Error> = std::result::Result<T, E>;
@@ -37,29 +30,26 @@ pub enum ClusterVersionUpdateState {
3730
}
3831

3932
pub async fn cluster_version_update_state(
40-
nifi: &v1alpha1::NifiCluster,
33+
cluster: &ValidatedCluster,
4134
client: &Client,
42-
namespace: &NamespaceName,
43-
resolved_version: &String,
4435
deployed_version: Option<&String>,
4536
) -> Result<ClusterVersionUpdateState> {
37+
// The version we want to converge to, i.e. the resolved product image version.
38+
let resolved_version = &cluster.image.product_version;
39+
4640
// Handle full restarts for a version change
4741
match deployed_version {
4842
Some(deployed_version) => {
4943
if deployed_version != resolved_version {
5044
// Check if statefulsets are already scaled to zero, if not - requeue
5145
let selector = LabelSelector {
5246
match_expressions: None,
53-
match_labels: Some(
54-
Labels::role_selector(nifi, APP_NAME, &NifiRole::Node.to_string())
55-
.context(LabelBuildSnafu)?
56-
.into(),
57-
),
47+
match_labels: Some(cluster.role_selector().into()),
5848
};
5949

6050
// Retrieve the deployed statefulsets to check on the current status of the restart
6151
let deployed_statefulsets = client
62-
.list_with_label_selector::<StatefulSet>(namespace.as_ref(), &selector)
52+
.list_with_label_selector::<StatefulSet>(cluster.namespace.as_ref(), &selector)
6353
.await
6454
.context(FetchStatefulsetsSnafu)?;
6555

rust/operator-binary/src/nifi_controller.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,10 @@ pub async fn reconcile_nifi(
224224
&& deployed_version.is_some_and(|v| v.starts_with("2."));
225225

226226
if !rolling_upgrade_supported {
227-
cluster_version_update_state = upgrade::cluster_version_update_state(
228-
nifi,
229-
client,
230-
&validated_cluster.namespace,
231-
&resolved_product_image.product_version,
232-
deployed_version,
233-
)
234-
.await
235-
.context(ClusterVersionUpdateStateSnafu)?;
227+
cluster_version_update_state =
228+
upgrade::cluster_version_update_state(&validated_cluster, client, deployed_version)
229+
.await
230+
.context(ClusterVersionUpdateStateSnafu)?;
236231

237232
if cluster_version_update_state == ClusterVersionUpdateState::UpdateInProgress {
238233
return Ok(Action::await_change());

0 commit comments

Comments
 (0)