Skip to content
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

feat: Let operators pick stackable version automatically #619

Merged
merged 12 commits into from
Aug 1, 2023
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]).
maltesander marked this conversation as resolved.
Show resolved Hide resolved

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

## [0.44.0] - 2023-07-13

### Added
Expand Down
56 changes: 34 additions & 22 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. `23.4`, `23.4.1` or `0.0.0-dev`.
/// 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,42 +79,45 @@ 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();

match &self.image_selection {
ProductImageSelection::Custom(custom) => {
let custom_image_tag = custom
ProductImageSelection::Custom(image_selection) => {
let image_tag = image_selection
.custom
.split_once(':')
.map_or("latest", |splits| splits.1);
let app_version_label = format!("{}-{}", custom.product_version, custom_image_tag);
let app_version_label =
format!("{}-{}", image_selection.product_version, image_tag);
ResolvedProductImage {
product_version: custom.product_version.to_string(),
product_version: image_selection.product_version.to_string(),
app_version_label,
image: custom.custom.to_string(),
image: image_selection.custom.clone(),
image_pull_policy,
pull_secrets,
}
}
ProductImageSelection::StackableVersion(stackable_version) => {
let repo = stackable_version
ProductImageSelection::StackableVersion(image_selection) => {
let repo = image_selection
.repo
.as_deref()
.unwrap_or(STACKABLE_DOCKER_REPO);
let stackable_version = image_selection
.stackable_version
.as_deref()
.unwrap_or(operator_version);
let image = format!(
"{repo}/{image_base_name}:{product_version}-stackable{stackable_version}",
product_version = stackable_version.product_version,
stackable_version = stackable_version.stackable_version,
product_version = image_selection.product_version,
);
let app_version_label = format!(
"{product_version}-stackable{stackable_version}",
product_version = stackable_version.product_version,
stackable_version = stackable_version.stackable_version,
product_version = image_selection.product_version,
);
ResolvedProductImage {
product_version: stackable_version.product_version.to_string(),
product_version: image_selection.product_version.to_string(),
app_version_label,
image,
image_pull_policy,
Expand All @@ -131,6 +135,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 +288,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 +302,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