Skip to content

Commit 131d45b

Browse files
committed
fix bug where invalid labels were created due to forbidden label charachter ":" in hash
1 parent 958f62f commit 131d45b

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ impl ProductImage {
111111
ProductImageSelection::Custom(image_selection) => {
112112
let image = ImageRef::parse(&image_selection.custom);
113113
let image_tag_or_hash = image.tag.or(image.hash).unwrap_or("latest".to_string());
114-
let mut app_version_label = format!("{}-{}", product_version, image_tag_or_hash);
115-
// TODO Use new label mechanism once added
116-
app_version_label.truncate(63);
114+
let app_version_label =
115+
Self::build_app_version_label(&product_version, &image_tag_or_hash);
117116

118117
ResolvedProductImage {
119118
product_version,
@@ -174,6 +173,26 @@ impl ProductImage {
174173
}) => pv,
175174
}
176175
}
176+
177+
/// Format the `image_tag_or_hash` for special characters not allowed in labels and build the
178+
/// full app_version_label with a max length of 63 characters.
179+
///
180+
/// A docker image with hash usually looks like:
181+
///
182+
/// Without product or stackable version:
183+
/// oci.stackable.tech/sdp/spark-k8s@sha256:c8b77ba72de6f8ddb99cb484b5ee79c43623cc2514d1448243f7d65d0ef66212
184+
///
185+
/// With product and stackable version:
186+
/// oci.stackable.tech/sdp/spark-k8s:3.5.6-stackable25.7.0@sha256:c8b77ba72de6f8ddb99cb484b5ee79c43623cc2514d1448243f7d65d0ef66212
187+
///
188+
/// Using the hash we have to avoid adding characters like ":" to the image with is against Kubernetes policy.
189+
fn build_app_version_label(product_version: &str, image_tag_or_hash: &str) -> String {
190+
let formatted_image_tag_or_hash = image_tag_or_hash.replace(":", "-");
191+
let mut app_version_label = format!("{}-{}", product_version, formatted_image_tag_or_hash);
192+
// TODO Use new label mechanism once added
193+
app_version_label.truncate(63);
194+
app_version_label
195+
}
177196
}
178197

179198
#[cfg(test)]

0 commit comments

Comments
 (0)