Skip to content

fix: Support PR versions in automatic stackableVersion #629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

## [0.45.1] - 2023-08-01

### Fixed

- Support PR versions in automatic stackableVersion - ([#619]) falsely assumed the binaries in `-pr` versions
have the version `0.0.0-dev` ([#629]).

[#629]: https://github.com/stackabletech/operator-rs/pull/629

## [0.45.0] - 2023-08-01

### Changed
Expand Down
61 changes: 53 additions & 8 deletions src/commons/product_image_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub struct ProductImageStackableVersion {
product_version: String,
/// Stackable version of the product, e.g. `23.4`, `23.4.1` or `0.0.0-dev`.
/// If not specified, the operator will use its own version, e.g. `23.4.1`.
/// When using a nightly operator it will use the nightly `0.0.0-dev` image.
/// When using a nightly operator or a pr version, it will use the nightly `0.0.0-dev` image.
stackable_version: Option<String>,
/// Name of the docker repo, e.g. `docker.stackable.tech/stackable`
repo: Option<String>,
Expand Down Expand Up @@ -84,7 +84,7 @@ pub enum PullPolicy {
impl ProductImage {
/// `image_base_name` should be base of the image name in the container image registry, e.g. `trino`.
/// `operator_version` needs to be the full operator version and a valid semver string.
/// Accepted values are `23.7.0` or `0.0.0-dev`. Versions with a trailing `-pr` or something else are not supported.
/// Accepted values are `23.7.0`, `0.0.0-dev` or `0.0.0-pr123`. Other variants are not supported.
pub fn resolve(&self, image_base_name: &str, operator_version: &str) -> ResolvedProductImage {
let image_pull_policy = self.pull_policy.as_ref().to_string();
let pull_secrets = self.pull_secrets.clone();
Expand All @@ -110,10 +110,16 @@ impl ProductImage {
.repo
.as_deref()
.unwrap_or(STACKABLE_DOCKER_REPO);
let stackable_version = image_selection
.stackable_version
.as_deref()
.unwrap_or(operator_version);
let stackable_version = match &image_selection.stackable_version {
Some(stackable_version) => stackable_version,
None => {
if operator_version.starts_with("0.0.0-") {
"0.0.0-dev"
} else {
operator_version
}
}
};
let image = format!(
"{repo}/{image_base_name}:{product_version}-stackable{stackable_version}",
product_version = image_selection.product_version,
Expand Down Expand Up @@ -141,8 +147,9 @@ mod tests {
use rstest::rstest;

#[rstest]
#[case::stackable_version_without_stackable_version(
#[case::stackable_version_without_stackable_version_stable_version(
"superset",
"23.7.42",
r#"
productVersion: 1.4.1
"#,
Expand All @@ -154,8 +161,37 @@ mod tests {
pull_secrets: None,
}
)]
#[case::stackable_version_without_stackable_version_nightly(
"superset",
"0.0.0-dev",
r#"
productVersion: 1.4.1
"#,
ResolvedProductImage {
image: "docker.stackable.tech/stackable/superset:1.4.1-stackable0.0.0-dev".to_string(),
app_version_label: "1.4.1-stackable0.0.0-dev".to_string(),
product_version: "1.4.1".to_string(),
image_pull_policy: "Always".to_string(),
pull_secrets: None,
}
)]
#[case::stackable_version_without_stackable_version_pr_version(
"superset",
"0.0.0-pr123",
r#"
productVersion: 1.4.1
"#,
ResolvedProductImage {
image: "docker.stackable.tech/stackable/superset:1.4.1-stackable0.0.0-dev".to_string(),
app_version_label: "1.4.1-stackable0.0.0-dev".to_string(),
product_version: "1.4.1".to_string(),
image_pull_policy: "Always".to_string(),
pull_secrets: None,
}
)]
#[case::stackable_version_without_repo(
"superset",
"23.7.42",
r#"
productVersion: 1.4.1
stackableVersion: 2.1.0
Expand All @@ -170,6 +206,7 @@ mod tests {
)]
#[case::stackable_version_with_repo(
"trino",
"23.7.42",
r#"
productVersion: 1.4.1
stackableVersion: 2.1.0
Expand All @@ -185,6 +222,7 @@ mod tests {
)]
#[case::custom_without_tag(
"superset",
"23.7.42",
r#"
custom: my.corp/myteam/stackable/superset
productVersion: 1.4.1
Expand All @@ -199,6 +237,7 @@ mod tests {
)]
#[case::custom_with_tag(
"superset",
"23.7.42",
r#"
custom: my.corp/myteam/stackable/superset:latest-and-greatest
productVersion: 1.4.1
Expand All @@ -213,6 +252,7 @@ mod tests {
)]
#[case::custom_takes_precedence(
"superset",
"23.7.42",
r#"
custom: my.corp/myteam/stackable/superset:latest-and-greatest
productVersion: 1.4.1
Expand All @@ -228,6 +268,7 @@ mod tests {
)]
#[case::pull_policy_if_not_present(
"superset",
"23.7.42",
r#"
custom: my.corp/myteam/stackable/superset:latest-and-greatest
productVersion: 1.4.1
Expand All @@ -243,6 +284,7 @@ mod tests {
)]
#[case::pull_policy_always(
"superset",
"23.7.42",
r#"
custom: my.corp/myteam/stackable/superset:latest-and-greatest
productVersion: 1.4.1
Expand All @@ -258,6 +300,7 @@ mod tests {
)]
#[case::pull_policy_never(
"superset",
"23.7.42",
r#"
custom: my.corp/myteam/stackable/superset:latest-and-greatest
productVersion: 1.4.1
Expand All @@ -273,6 +316,7 @@ mod tests {
)]
#[case::pull_secrets(
"superset",
"23.7.42",
r#"
custom: my.corp/myteam/stackable/superset:latest-and-greatest
productVersion: 1.4.1
Expand All @@ -291,11 +335,12 @@ mod tests {
)]
fn test_correct_resolved_image(
#[case] image_base_name: String,
#[case] operator_version: String,
#[case] input: String,
#[case] expected: ResolvedProductImage,
) {
let product_image: ProductImage = serde_yaml::from_str(&input).expect("Illegal test input");
let resolved_product_image = product_image.resolve(&image_base_name, "23.7.42");
let resolved_product_image = product_image.resolve(&image_base_name, &operator_version);

assert_eq!(resolved_product_image, expected);
}
Expand Down