Skip to content

Commit

Permalink
feat: default stackableVersion to operator version
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernauer committed Jul 6, 2023
1 parent 5d2ca16 commit 87fa9d0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Changed

- [BREAKING] ProductImageSelection now defaults `stackableVersion` to operator version ([#619]).

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

## [0.43.0] - 2023-07-06

### Added
Expand Down
39 changes: 25 additions & 14 deletions src/commons/product_image_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ pub struct ProductImageCustom {
pub struct ProductImageStackableVersion {
/// Version of the product, e.g. `1.4.1`.
product_version: String,
/// Stackable version of the product, e.g. 2.1.0
stackable_version: String,
/// Stackable version of the product, e.g. 2.1.0.
/// If not specified, the operator will use the same version as he has (e.g. `23.4.1` or `0.0.0-dev`)
stackable_version: Option<String>,
/// Name of the docker repo, e.g. `docker.stackable.tech/stackable`
repo: Option<String>,
}
Expand Down Expand Up @@ -78,7 +79,7 @@ pub enum PullPolicy {
}

impl ProductImage {
pub fn resolve(&self, image_base_name: &str) -> ResolvedProductImage {
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 @@ -102,15 +103,17 @@ impl ProductImage {
.repo
.as_deref()
.unwrap_or(STACKABLE_DOCKER_REPO);
let stackable_version_version = stackable_version
.stackable_version
.as_deref()
.unwrap_or(operator_version);
let image = format!(
"{repo}/{image_base_name}:{product_version}-stackable{stackable_version}",
"{repo}/{image_base_name}:{product_version}-stackable{stackable_version_version}",
product_version = stackable_version.product_version,
stackable_version = stackable_version.stackable_version,
);
let app_version_label = format!(
"{product_version}-stackable{stackable_version}",
"{product_version}-stackable{stackable_version_version}",
product_version = stackable_version.product_version,
stackable_version = stackable_version.stackable_version,
);
ResolvedProductImage {
product_version: stackable_version.product_version.to_string(),
Expand All @@ -131,6 +134,19 @@ mod tests {
use rstest::rstest;

#[rstest]
#[case::stackable_version_without_stackable_version(
"superset",
r#"
productVersion: 1.4.1
"#,
ResolvedProductImage {
image: "docker.stackable.tech/stackable/superset:1.4.1-stackableoperator-version".to_string(),
app_version_label: "1.4.1-stackableoperator-version".to_string(),
product_version: "1.4.1".to_string(),
image_pull_policy: "IfNotPresent".to_string(),
pull_secrets: None,
}
)]
#[case::stackable_version_without_repo(
"superset",
r#"
Expand Down Expand Up @@ -271,8 +287,9 @@ mod tests {
#[case] input: String,
#[case] expected: ResolvedProductImage,
) {
let operator_version = "operator-version";
let product_image: ProductImage = serde_yaml::from_str(&input).expect("Illegal test input");
let resolved_product_image = product_image.resolve(&image_base_name);
let resolved_product_image = product_image.resolve(&image_base_name, operator_version);

assert_eq!(resolved_product_image, expected);
}
Expand All @@ -284,12 +301,6 @@ mod tests {
"#,
"data did not match any variant of untagged enum ProductImageSelection at line 2 column 9"
)]
#[case::product_version(
r#"
productVersion: 1.4.1
"#,
"data did not match any variant of untagged enum ProductImageSelection at line 2 column 9"
)]
#[case::stackable_version(
r#"
stackableVersion: 2.1.0
Expand Down

0 comments on commit 87fa9d0

Please sign in to comment.