Skip to content

Commit 2e15cce

Browse files
committed
refactor: use ProductVersion in status
1 parent 84e6209 commit 2e15cce

4 files changed

Lines changed: 21 additions & 8 deletions

File tree

extra/crds.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,7 +2280,10 @@ spec:
22802280
type: object
22812281
type: array
22822282
deployed_version:
2283+
maxLength: 63
2284+
minLength: 1
22832285
nullable: true
2286+
pattern: ^[a-z0-9A-Z]([a-z0-9A-Z-_.]*[a-z0-9A-Z]+)?$
22842287
type: string
22852288
type: object
22862289
required:

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ 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+
v2::types::operator::ProductVersion,
89
};
910

1011
use super::ValidatedCluster;
@@ -32,15 +33,15 @@ pub enum ClusterVersionUpdateState {
3233
pub async fn cluster_version_update_state(
3334
cluster: &ValidatedCluster,
3435
client: &Client,
35-
deployed_version: Option<&String>,
36+
deployed_version: Option<&ProductVersion>,
3637
) -> Result<ClusterVersionUpdateState> {
3738
// The version we want to converge to, i.e. the resolved product image version.
3839
let resolved_version = &cluster.image.product_version;
3940

4041
// Handle full restarts for a version change
4142
match deployed_version {
4243
Some(deployed_version) => {
43-
if deployed_version != resolved_version {
44+
if deployed_version.as_ref() != resolved_version.as_str() {
4445
// Check if statefulsets are already scaled to zero, if not - requeue
4546
let selector = LabelSelector {
4647
match_expressions: None,

rust/operator-binary/src/crd/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ use stackable_operator::{
3939
v2::{
4040
config_overrides::KeyValueConfigOverrides,
4141
role_utils::JavaCommonConfig,
42-
types::kubernetes::{ConfigMapName, ListenerClassName, SecretClassName},
42+
types::{
43+
kubernetes::{ConfigMapName, ListenerClassName, SecretClassName},
44+
operator::ProductVersion,
45+
},
4346
},
4447
versioned::versioned,
4548
};
@@ -292,7 +295,7 @@ pub enum NifiRole {
292295

293296
#[derive(Clone, Debug, Default, Deserialize, JsonSchema, Serialize)]
294297
pub struct NifiStatus {
295-
pub deployed_version: Option<String>,
298+
pub deployed_version: Option<ProductVersion>,
296299
#[serde(default)]
297300
pub conditions: Vec<ClusterCondition>,
298301
}

rust/operator-binary/src/nifi_controller.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Ensures that `Pod`s are configured and running for each [`v1alpha1::NifiCluster`].
22
3-
use std::sync::Arc;
3+
use std::{str::FromStr, sync::Arc};
44

55
use const_format::concatcp;
66
use snafu::{OptionExt, ResultExt, Snafu};
@@ -21,7 +21,10 @@ use stackable_operator::{
2121
compute_conditions, operations::ClusterOperationsConditionBuilder,
2222
statefulset::StatefulSetConditionBuilder,
2323
},
24-
v2::{cluster_resources::cluster_resources_new, types::operator::RoleGroupName},
24+
v2::{
25+
cluster_resources::cluster_resources_new,
26+
types::operator::{ProductVersion, RoleGroupName},
27+
},
2528
};
2629
use strum::{EnumDiscriminants, IntoStaticStr};
2730
use tracing::Instrument;
@@ -221,7 +224,7 @@ pub async fn reconcile_nifi(
221224
.as_ref()
222225
.and_then(|status| status.deployed_version.as_ref());
223226
let rolling_upgrade_supported = resolved_product_image.product_version.starts_with("2.")
224-
&& deployed_version.is_some_and(|v| v.starts_with("2."));
227+
&& deployed_version.is_some_and(|v| v.as_ref().starts_with("2."));
225228

226229
if !rolling_upgrade_supported {
227230
cluster_version_update_state =
@@ -429,7 +432,10 @@ pub async fn reconcile_nifi(
429432
// we are still in the process of updating
430433
let status = if cluster_version_update_state != ClusterVersionUpdateState::UpdateRequested {
431434
NifiStatus {
432-
deployed_version: Some(resolved_product_image.product_version.clone()),
435+
deployed_version: Some(
436+
ProductVersion::from_str(&resolved_product_image.product_version)
437+
.expect("the resolved product version is a valid product version label value"),
438+
),
433439
conditions,
434440
}
435441
} else {

0 commit comments

Comments
 (0)