use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.
the class KubernetesResourceUtil method extractImageUser.
private static String extractImageUser(String image, MavenProject project) {
ImageName name = new ImageName(image);
String imageUser = name.getUser();
return imageUser != null ? imageUser : project.getGroupId();
}
use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.
the class ContainerHandlerTest method imagePullPolicyWithoutPolicySetTest.
@Test
public void imagePullPolicyWithoutPolicySetTest() {
// project with version and ending in SNAPSHOT
project1.setVersion("3.5-SNAPSHOT");
// project with version but not ending in SNAPSHOT
project2.setVersion("3.5-NEW");
// creating container Handler for two
ContainerHandler handler1 = new ContainerHandler(project1, envVarHandler, probeHandler);
ContainerHandler handler2 = new ContainerHandler(project2, envVarHandler, probeHandler);
// project without version
ContainerHandler handler3 = new ContainerHandler(project, envVarHandler, probeHandler);
images.clear();
images.add(imageConfiguration1);
// check if policy is not set then both in case of version is set or not
ResourceConfig config2 = new ResourceConfig.Builder().imagePullPolicy("").build();
containers = handler1.getContainers(config2, images);
assertEquals("PullAlways", containers.get(0).getImagePullPolicy());
containers = handler2.getContainers(config2, images);
assertEquals("", containers.get(0).getImagePullPolicy());
containers = handler3.getContainers(config2, images);
assertEquals("", containers.get(0).getImagePullPolicy());
}
use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.
the class ContainerHandlerTest method getVolumeMountWithoutMountTest.
@Test
public void getVolumeMountWithoutMountTest() {
ContainerHandler handler = new ContainerHandler(project, envVarHandler, probeHandler);
images.clear();
images.add(imageConfiguration1);
// volume config without mount
VolumeConfig volumeConfig1 = new VolumeConfig.Builder().name("first").build();
volumes1.add(volumeConfig1);
ResourceConfig config1 = new ResourceConfig.Builder().volumes(volumes1).build();
containers = handler.getContainers(config1, images);
assertTrue(containers.get(0).getVolumeMounts().isEmpty());
}
use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.
the class ContainerHandlerTest method getContainerTestWithUser.
@Test
public void getContainerTestWithUser() {
project.setArtifactId("test-artifact");
project.setGroupId("test-group");
ports.add("8080");
ports.add("9090");
tags.add("latest");
tags.add("test");
// container name with user and image with tag
ContainerHandler handler = new ContainerHandler(project, envVarHandler, probeHandler);
BuildImageConfiguration buildImageConfiguration = new BuildImageConfiguration.Builder().ports(ports).from("fabric8/").cleanup("try").tags(tags).compression("gzip").dockerFile("testFile").dockerFileDir("/demo").build();
ImageConfiguration imageConfiguration = new ImageConfiguration.Builder().name("user/test:latest").buildConfig(buildImageConfiguration).registry("docker.io").build();
images.clear();
images.add(imageConfiguration);
containers = handler.getContainers(config, images);
assertNotNull(containers);
assertEquals("user-test-artifact", containers.get(0).getName());
assertEquals("docker.io/user/test:latest", containers.get(0).getImage());
assertEquals("IfNotPresent", containers.get(0).getImagePullPolicy());
}
use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.
the class ContainerHandlerTest method getVolumeMountWithMultipleMountTest.
@Test
public void getVolumeMountWithMultipleMountTest() {
ContainerHandler handler = new ContainerHandler(project, envVarHandler, probeHandler);
images.clear();
images.add(imageConfiguration1);
List<String> mounts = new ArrayList<>();
mounts.add("/path/etc");
// volume config with name and multiple mount
mounts.add("/path/system");
mounts.add("/path/sys");
VolumeConfig volumeConfig4 = new VolumeConfig.Builder().name("test").mounts(mounts).build();
volumes1.clear();
volumes1.add(volumeConfig4);
ResourceConfig config4 = new ResourceConfig.Builder().volumes(volumes1).build();
containers = handler.getContainers(config4, images);
assertEquals(3, containers.get(0).getVolumeMounts().size());
for (int i = 0; i <= 2; i++) assertEquals("test", containers.get(0).getVolumeMounts().get(i).getName());
}
Aggregations