Skip to content

Commit c0c9031

Browse files
committed
refactor(operator): Streamline floating version handling
1 parent eee5f95 commit c0c9031

2 files changed

Lines changed: 45 additions & 9 deletions

File tree

crates/stackable-operator/src/commons/product_image_selection.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,30 +239,31 @@ impl ProductImage {
239239
// Trim the end to ensure no double slashes are produced below
240240
.trim_end_matches('/');
241241

242+
// First, figure out which version should be used. If the user explicitly specified
243+
// a version, use that directly. If no explicit version is set, we need to fall back
244+
// to the operator version. 0.0.0-pr* as the operator version results in the product
245+
// version to use 0.0.0-dev. In all other cases, the operator version is used as is.
242246
let stackable_version = match stackable_version {
243247
Some(version) => version,
244248
None => {
245-
if operator_version.major == 0
246-
&& operator_version.minor == 0
247-
&& operator_version.patch == 0
248-
&& operator_version.pre.starts_with("pr")
249-
{
249+
if operator_version.is_0_0_0_pr() {
250250
tracing::warn!(
251251
%operator_version,
252252
"operator is built by pull request, using {version} build of product image",
253253
version = *ZERO_ZERO_ZERO_DEV
254254
);
255255

256-
is_floating_tag = true;
257256
&*ZERO_ZERO_ZERO_DEV
258257
} else {
259258
operator_version
260259
}
261260
}
262261
};
263262

263+
// Determine if the selected stackable version is considered floating once.
264+
is_floating_tag = stackable_version.is_floating() || *use_floating_tag;
265+
264266
let stackable_version = if *use_floating_tag {
265-
is_floating_tag = true;
266267
stackable_version.floating()
267268
} else {
268269
stackable_version.to_string()
@@ -383,7 +384,7 @@ mod tests {
383384
image: "oci.stackable.tech/sdp/superset:1.4.1-stackable0.0.0-dev".to_string(),
384385
app_version_label_value: "1.4.1-stackable0.0.0-dev".parse().expect("static app version label is always valid"),
385386
product_version: "1.4.1".to_string(),
386-
image_pull_policy: "IfNotPresent".to_string(),
387+
image_pull_policy: "Always".to_string(),
387388
pull_secrets: None,
388389
}
389390
)]

crates/stackable-shared/src/semver.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,45 @@ pub static ZERO_ZERO_ZERO_DEV: LazyLock<semver::Version> = LazyLock::new(|| semv
1212
pub trait VersionExt {
1313
/// Returns the floating version as a [`String`], eg. `26.7.0` -> `26.7`
1414
fn floating(&self) -> String;
15+
16+
/// Returns whether the version is `0.0.0`, independent of pre-release information and build
17+
/// metadata.
18+
fn is_0_0_0(&self) -> bool;
19+
20+
/// Returns whether the version is `0.0.0-dev`, independent of build metadata.
21+
fn is_0_0_0_dev(&self) -> bool;
22+
23+
/// Returns whether the version is `0.0.0-pr*`, independent of build metadata.
24+
fn is_0_0_0_pr(&self) -> bool;
25+
26+
/// Returns whether the version is considered floating.
27+
///
28+
/// Currently, `0.0.0-dev` and `0.0.0-pr*` versions are considered floating.
29+
fn is_floating(&self) -> bool;
1530
}
1631

1732
impl VersionExt for ::semver::Version {
1833
fn floating(&self) -> String {
19-
format!("{major}.{minor}", major = self.major, minor = self.minor)
34+
if self.is_floating() {
35+
self.to_string()
36+
} else {
37+
format!("{major}.{minor}", major = self.major, minor = self.minor)
38+
}
39+
}
40+
41+
fn is_0_0_0(&self) -> bool {
42+
self.major == 0 && self.minor == 0 && self.patch == 0
43+
}
44+
45+
fn is_0_0_0_dev(&self) -> bool {
46+
self.is_0_0_0() && self.pre.as_str() == "dev"
47+
}
48+
49+
fn is_0_0_0_pr(&self) -> bool {
50+
self.is_0_0_0() && self.pre.starts_with("pr")
51+
}
52+
53+
fn is_floating(&self) -> bool {
54+
self.is_0_0_0_dev() || self.is_0_0_0_pr()
2055
}
2156
}

0 commit comments

Comments
 (0)