Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1321 from rohanKanojia/issue1312
Browse files Browse the repository at this point in the history
Fix #1312 : Container name should not be generated from maven group Id
  • Loading branch information
rhuss authored Jul 30, 2018
2 parents c888d84 + e2f694e commit be0bf66
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ After this we will switch probably to real [Semantic Versioning 2.0.0](http://se

###3.5.41
* Feature 1032: Improvements of the Vert.x Generator and enrichers
* Removed unused Maven goals. Please contact us if something's missing for you.
* Feature 1313: Removed unused Maven goals. Please contact us if something's missing for you.
* Fix 1276: Proper inclusion of webapp's war regardless of the final name
* Feature: New 'path' config option for the webapp generator to set the context path
* Fix 1334: support for docker.pull.registry
* Fix 1268: Java console for OpenShift builds reachable again.
* Fix 1312: Container name should not be generated from maven group id

###3.5.40
* Feature 1264: Added `osio` profile, with enricher to apply OpenShift.io space labels to resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ public class KubernetesResourceUtil {

public static final HashSet<Class<?>> SIMPLE_FIELD_TYPES = new HashSet<>();

public static final String CONTAINER_NAME_REGEX = "^[a-z0-9]([-a-z0-9]*[a-z0-9])?$";

protected static final String DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ssX";


Expand Down Expand Up @@ -402,7 +404,17 @@ public static String extractContainerName(MavenProject project, ImageConfigurati
private static String extractImageUser(String image, MavenProject project) {
ImageName name = new ImageName(image);
String imageUser = name.getUser();
return imageUser != null ? imageUser : project.getGroupId();
String projectGroupId = project.getGroupId();
if(imageUser != null) {
return imageUser;
} else {
if(projectGroupId == null || projectGroupId.matches(CONTAINER_NAME_REGEX)) {
return projectGroupId;
}
else {
return projectGroupId.replaceAll("[^a-zA-Z0-9-]", "").replaceFirst("^-*(.*?)-*$","$1");
}
}
}

public static Map<String, String> removeVersionSelector(Map<String, String> selector) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
import io.fabric8.kubernetes.api.model.KubernetesList;
import io.fabric8.kubernetes.api.model.KubernetesListBuilder;

import io.fabric8.maven.docker.config.ImageConfiguration;
import mockit.Expectations;
import mockit.Mocked;
import org.apache.maven.project.MavenProject;
import org.junit.BeforeClass;
import org.junit.Test;

Expand All @@ -45,6 +49,9 @@ public class KubernetesResourceUtilTest {

private static File fabric8Dir;

@Mocked
final MavenProject project = new MavenProject();

@BeforeClass
public static void initPath() throws UnsupportedEncodingException {
ClassLoader classLoader = KubernetesResourceUtil.class.getClassLoader();
Expand Down Expand Up @@ -143,6 +150,25 @@ public void invalidExtension() throws IOException {
}
}

@Test
public void containerName() {
new Expectations() {{
project.getGroupId();
result = "io.fabric8-test-";

project.getArtifactId();
result = "fabric8-maven-plugin-dummy";
}};

ImageConfiguration imageConfiguration = new ImageConfiguration.Builder()
.name("dummy-image")
.registry("example.com/someregistry")
.name("test")
.build();
String containerName = KubernetesResourceUtil.extractContainerName(project, imageConfiguration);
assertTrue(containerName.matches(KubernetesResourceUtil.CONTAINER_NAME_REGEX));
}

@Test
public void readWholeDir() throws IOException {
ResourceVersioning v = new ResourceVersioning()
Expand Down

0 comments on commit be0bf66

Please sign in to comment.