Skip to content
Snippets Groups Projects
Commit b7ceb222 authored by Angel Misevski's avatar Angel Misevski Committed by Ilya Buziuk
Browse files

Fix bug where broker container name can exceed 63 characters


The container name for the plugin broker is derived from its docker
image reference. When this reference contains a registry, it's possible
for this name to exceed the 63-character limit imposed by Kubernetes,
e.g.

  my-internal-registry/my-organization/che-unified-plugin-broker:v0.20

results in a broker container named

  my-internal-registry-my-organization-che-unified-plugin-broker-v0-20

This commit removes the registry hostname from the container name and
keeps the conversion the same.

Signed-off-by: default avatarAngel Misevski <amisevsk@redhat.com>
parent cdca0558
No related branches found
No related tags found
No related merge requests found
......@@ -124,8 +124,8 @@ public class Names {
if (containerName != null && containerName.length() > MAX_CONTAINER_NAME_LENGTH) {
throw new IllegalArgumentException(
format(
"The container name exceeds the allowed limit of %s characters.",
MAX_CONTAINER_NAME_LENGTH));
"The container name '%s' exceeds the allowed limit of %s characters.",
containerName, MAX_CONTAINER_NAME_LENGTH));
}
if (annotations != null
......
......@@ -34,6 +34,8 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
......@@ -71,6 +73,8 @@ public abstract class BrokerEnvironmentFactory<E extends KubernetesEnvironment>
private static final String CONF_FOLDER = "/broker-config";
private static final String PLUGINS_VOLUME_NAME = "plugins";
private static final String BROKERS_POD_NAME = "che-plugin-broker";
private static final Pattern IMAGE_PATTERN =
Pattern.compile("(?<registry>[^/]+/)?(?<org>[^/]+)/(?<image>[^/]+)");
private final ObjectMapper objectMapper = new ObjectMapper();
private final String cheWebsocketEndpoint;
......@@ -158,9 +162,19 @@ public abstract class BrokerEnvironmentFactory<E extends KubernetesEnvironment>
List<EnvVar> envVars,
String image,
@Nullable String brokerVolumeName) {
// There's a chance the full image reference may be over the name limit of 63 chars
// so we need to remove registry hostname
Matcher matcher = IMAGE_PATTERN.matcher(image);
String containerName;
if (matcher.matches()) {
containerName = String.format("%s/%s", matcher.group("org"), matcher.group("image"));
} else {
containerName = image;
}
containerName = containerName.toLowerCase().replaceAll("[^\\d\\w-]", "-");
final ContainerBuilder cb =
new ContainerBuilder()
.withName(image.toLowerCase().replaceAll("[^\\d\\w-]", "-"))
.withName(containerName)
.withImage(image)
.withArgs(
"-push-endpoint",
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment