Skip to content

Fix bug where invalid labels were created due to forbidden label characters #1075

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

Closed
wants to merge 1 commit into from
Closed
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
25 changes: 22 additions & 3 deletions crates/stackable-operator/src/commons/product_image_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,8 @@ impl ProductImage {
ProductImageSelection::Custom(image_selection) => {
let image = ImageRef::parse(&image_selection.custom);
let image_tag_or_hash = image.tag.or(image.hash).unwrap_or("latest".to_string());
let mut app_version_label = format!("{}-{}", product_version, image_tag_or_hash);
// TODO Use new label mechanism once added
app_version_label.truncate(63);
let app_version_label =
Self::build_app_version_label(&product_version, &image_tag_or_hash);

ResolvedProductImage {
product_version,
Expand Down Expand Up @@ -174,6 +173,26 @@ impl ProductImage {
}) => pv,
}
}

/// Format the `image_tag_or_hash` for special characters not allowed in labels and build the
/// full app_version_label with a max length of 63 characters.
///
/// A docker image with hash usually looks like:
///
/// Without product or stackable version:
/// oci.stackable.tech/sdp/spark-k8s@sha256:c8b77ba72de6f8ddb99cb484b5ee79c43623cc2514d1448243f7d65d0ef66212
///
/// With product and stackable version:
/// oci.stackable.tech/sdp/spark-k8s:3.5.6-stackable25.7.0@sha256:c8b77ba72de6f8ddb99cb484b5ee79c43623cc2514d1448243f7d65d0ef66212
///
/// Using the hash we have to avoid adding characters like ":" to the image with is against Kubernetes policy.
fn build_app_version_label(product_version: &str, image_tag_or_hash: &str) -> String {
let formatted_image_tag_or_hash = image_tag_or_hash.replace(":", "-");
let mut app_version_label = format!("{}-{}", product_version, formatted_image_tag_or_hash);
// TODO Use new label mechanism once added
app_version_label.truncate(63);
app_version_label
}
}

#[cfg(test)]
Expand Down
Loading