Search in sources :

Example 16 with Project

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();
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName)

Example 17 with Project

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());
}
Also used : ResourceConfig(io.fabric8.maven.core.config.ResourceConfig) Test(org.junit.Test)

Example 18 with Project

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());
}
Also used : ResourceConfig(io.fabric8.maven.core.config.ResourceConfig) VolumeConfig(io.fabric8.maven.core.config.VolumeConfig) Test(org.junit.Test)

Example 19 with Project

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());
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Test(org.junit.Test)

Example 20 with Project

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());
}
Also used : ArrayList(java.util.ArrayList) ResourceConfig(io.fabric8.maven.core.config.ResourceConfig) VolumeConfig(io.fabric8.maven.core.config.VolumeConfig) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)51 ResourceConfig (io.fabric8.maven.core.config.ResourceConfig)29 File (java.io.File)14 Expectations (mockit.Expectations)14 ArrayList (java.util.ArrayList)13 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)11 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)11 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)9 IOException (java.io.IOException)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)8 VolumeConfig (io.fabric8.maven.core.config.VolumeConfig)7 GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)6 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)6 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)5 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)5 MojoFailureException (org.apache.maven.plugin.MojoFailureException)5 MavenProject (org.apache.maven.project.MavenProject)5 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)4 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3