diff --git a/jkube-kit/config/image/src/main/java/org/eclipse/jkube/kit/config/image/ImageName.java b/jkube-kit/config/image/src/main/java/org/eclipse/jkube/kit/config/image/ImageName.java index 68d3e9b0ab..c9aa1c16d5 100644 --- a/jkube-kit/config/image/src/main/java/org/eclipse/jkube/kit/config/image/ImageName.java +++ b/jkube-kit/config/image/src/main/java/org/eclipse/jkube/kit/config/image/ImageName.java @@ -274,11 +274,6 @@ private void doValidate() { String user = inferUser(); String image = user != null ? repository.substring(user.length() + 1) : repository; - //Check repository name length - if (image.length() > 255) { - errors.add(String.format("Repository name '%s' exceeds the maximum allowed length of 255 characters.", image)); - } - Object[] checks = new Object[] { "registry", DOMAIN_REGEXP, registry, "image", IMAGE_NAME_REGEXP, image, @@ -288,7 +283,6 @@ private void doValidate() { }; - for (int i = 0; i < checks.length; i +=3) { String value = (String) checks[i + 2]; Pattern checkPattern = (Pattern) checks[i + 1]; @@ -299,6 +293,14 @@ private void doValidate() { } } + // Additional validation for repository length + if (repository != null) { + int repositoryLength = repository.length(); + if (repositoryLength > 255) { + errors.add(String.format("Repository name '%s' has a length of %d characters, which exceeds the maximum of 255 characters.", repository, repositoryLength)); + } + } + if (!errors.isEmpty()) { StringBuilder buf = new StringBuilder(); buf.append(String.format("Given Docker name '%s' is invalid:%n", getFullName())); @@ -362,5 +364,4 @@ private boolean isRegistryValidPathComponent() { private static final Pattern TAG_REGEXP = Pattern.compile("^[\\w][\\w.-]{0,127}$"); private static final Pattern DIGEST_REGEXP = Pattern.compile("^sha256:[a-z0-9]{32,}$"); - }