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

Generate broker container names more sensibly #16289

Merged
merged 1 commit into from
Mar 10, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,25 @@ private String generateUniqueName(String suffix) {
*/
@VisibleForTesting
protected String generateContainerNameFromImageRef(String image) {
return image.toLowerCase().replaceAll("[^/]*/", "").replaceAll("[^\\d\\w-]", "-");
String containerName;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this is certainly improving the situation, it is still not taking care of the possible clashes. What do you think can be done there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A container name can be up to 30 chars, if you want to use an image with a really long tag there's not much we can do that's intelligent. Apart from that we could choose a completely different tack for naming these containers, but that's potentially more risky and I would prefer that be a separate issue + PR to minimize risk in 7.9.x.

Are there any big cases I've missed in the PR? I admit I wrote it hastily.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One solution would be to just name the containers "metadata-broker" and "artifacts-broker", though that obscures the version being used in the default use case (where it's currently something like che-plugin-metadata-broker-v3-1-0.

if (image.contains("@")) {
// Image is tagged with digest; we trim digest to 10 chars and remove "sha256"
String[] parts = image.split("@");
String imagePart = parts[0];
String digest = parts[1];
if (digest.contains(":")) {
digest = digest.split(":")[1];
}
if (digest.length() > 10) {
digest = digest.substring(0, 10);
}
image = String.format("%s-%s", imagePart, digest);
}
containerName = image.toLowerCase().replaceAll("[^/]*/", "").replaceAll("[^\\d\\w-]", "-");
if (containerName.length() > 63) {
containerName = containerName.substring(0, 63);
}
return containerName;
}

public static class BrokersConfigs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public void testImageToContainerNameConversion(Object image, Object expected) {
assertEquals(
actual,
expected,
String.format("Should remove registry and organization from image '%s'.", image));
String.format("Should generate name '%s' from image '%s'.", expected, image));
}

@DataProvider(name = "imageRefs")
Expand All @@ -325,7 +325,17 @@ public Object[][] imageRefs() {
{"very-long-registry-hostname-url.service/eclipse/image:tag", "image-tag"},
{"eclipse/che-unified-plugin-broker:v0.20", "che-unified-plugin-broker-v0-20"},
{"very-long-organization.name-eclipse-che/image:tag", "image-tag"},
{"very-long-registry-hostname-url.service/very-long-organization/image:tag", "image-tag"}
{"very-long-registry-hostname-url.service/very-long-organization/image:tag", "image-tag"},
{
"image-with-digest@sha256:7b868470f7b63d9da10a788d26abf4c076f90dc4c7de24d1298a8160c9a3dcc9",
"image-with-digest-7b868470f7"
},
{"image-with-short-digest@sha256:abcd", "image-with-short-digest-abcd"},
{"no-exception-when-no-colon@sha256abcd", "no-exception-when-no-colon-sha256abcd"},
{
"image-and-tag-longer-than-63-chars:really-long-tag-for-some-reason",
"image-and-tag-longer-than-63-chars-really-long-tag-for-some-rea"
}
};
}
}