Search in sources :

Example 86 with Config

use of io.fabric8.docker.client.Config in project fabric8-maven-plugin by fabric8io.

the class StatefulSetHandlerTest method statefulSetHandlerWithInvalidNameTest.

@Test(expected = IllegalArgumentException.class)
public void statefulSetHandlerWithInvalidNameTest() {
    // invalid controller name
    ContainerHandler containerHandler = new ContainerHandler(project, envVarHandler, probeHandler);
    PodTemplateHandler podTemplateHandler = new PodTemplateHandler(containerHandler);
    StatefulSetHandler statefulSetHandler = new StatefulSetHandler(podTemplateHandler);
    // with invalid controller name
    ResourceConfig config = new ResourceConfig.Builder().imagePullPolicy("IfNotPresent").controllerName("TesTing").withServiceAccount("test-account").withReplicas(5).volumes(volumes1).build();
    statefulSetHandler.getStatefulSet(config, images);
}
Also used : ResourceConfig(io.fabric8.maven.core.config.ResourceConfig) Test(org.junit.Test)

Example 87 with Config

use of io.fabric8.docker.client.Config in project fabric8-maven-plugin by fabric8io.

the class StatefulSetHandlerTest method before.

@Before
public void before() {
    // volume config with name and multiple mount
    mounts.add("/path/system");
    mounts.add("/path/sys");
    ports.add("8080");
    ports.add("9090");
    tags.add("latest");
    tags.add("test");
    VolumeConfig volumeConfig1 = new VolumeConfig.Builder().name("test").mounts(mounts).type("hostPath").path("/test/path").build();
    volumes1.add(volumeConfig1);
    // container name with alias
    BuildImageConfiguration buildImageConfiguration = new BuildImageConfiguration.Builder().ports(ports).from("fabric8/maven:latest").cleanup("try").tags(tags).compression("gzip").build();
    ImageConfiguration imageConfiguration = new ImageConfiguration.Builder().name("test").alias("test-app").buildConfig(buildImageConfiguration).registry("docker.io").build();
    images.add(imageConfiguration);
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) VolumeConfig(io.fabric8.maven.core.config.VolumeConfig) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Before(org.junit.Before)

Example 88 with Config

use of io.fabric8.docker.client.Config in project fabric8-maven-plugin by fabric8io.

the class StatefulSetHandlerTest method statefulSetHandlerTest.

@Test
public void statefulSetHandlerTest() {
    ContainerHandler containerHandler = new ContainerHandler(project, envVarHandler, probeHandler);
    PodTemplateHandler podTemplateHandler = new PodTemplateHandler(containerHandler);
    StatefulSetHandler statefulSetHandler = new StatefulSetHandler(podTemplateHandler);
    ResourceConfig config = new ResourceConfig.Builder().imagePullPolicy("IfNotPresent").controllerName("testing").withServiceAccount("test-account").withReplicas(5).volumes(volumes1).build();
    StatefulSet statefulSet = statefulSetHandler.getStatefulSet(config, images);
    // Assertion
    assertNotNull(statefulSet.getSpec());
    assertNotNull(statefulSet.getMetadata());
    assertEquals(5, statefulSet.getSpec().getReplicas().intValue());
    assertNotNull(statefulSet.getSpec().getTemplate());
    assertEquals("testing", statefulSet.getMetadata().getName());
    assertEquals("testing", statefulSet.getSpec().getServiceName());
    assertEquals("test-account", statefulSet.getSpec().getTemplate().getSpec().getServiceAccountName());
    assertFalse(statefulSet.getSpec().getTemplate().getSpec().getVolumes().isEmpty());
    assertEquals("test", statefulSet.getSpec().getTemplate().getSpec().getVolumes().get(0).getName());
    assertEquals("/test/path", statefulSet.getSpec().getTemplate().getSpec().getVolumes().get(0).getHostPath().getPath());
    assertNotNull(statefulSet.getSpec().getTemplate().getSpec().getContainers());
}
Also used : ResourceConfig(io.fabric8.maven.core.config.ResourceConfig) StatefulSet(io.fabric8.kubernetes.api.model.extensions.StatefulSet) Test(org.junit.Test)

Example 89 with Config

use of io.fabric8.docker.client.Config in project fabric8-maven-plugin by fabric8io.

the class ContainerHandler method getVolumeMounts.

private List<VolumeMount> getVolumeMounts(ResourceConfig config) {
    List<VolumeConfig> volumeConfigs = config.getVolumes();
    List<VolumeMount> ret = new ArrayList<>();
    if (volumeConfigs != null) {
        for (VolumeConfig volumeConfig : volumeConfigs) {
            List<String> mounts = volumeConfig.getMounts();
            if (mounts != null) {
                for (String mount : mounts) {
                    ret.add(new VolumeMountBuilder().withName(volumeConfig.getName()).withMountPath(mount).withReadOnly(false).build());
                }
            }
        }
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) VolumeConfig(io.fabric8.maven.core.config.VolumeConfig)

Example 90 with Config

use of io.fabric8.docker.client.Config in project fabric8-maven-plugin by fabric8io.

the class ContainerHandler method getContainers.

List<Container> getContainers(ResourceConfig config, List<ImageConfiguration> images) {
    List<Container> ret = new ArrayList<>();
    for (ImageConfiguration imageConfig : images) {
        if (imageConfig.getBuildConfiguration() != null) {
            Probe livenessProbe = probeHandler.getProbe(config.getLiveness());
            Probe readinessProbe = probeHandler.getProbe(config.getReadiness());
            Container container = new ContainerBuilder().withName(KubernetesResourceUtil.extractContainerName(project, imageConfig)).withImage(getImageName(imageConfig)).withImagePullPolicy(getImagePullPolicy(config)).withEnv(envVarHandler.getEnvironmentVariables(config.getEnv())).withSecurityContext(createSecurityContext(config)).withPorts(getContainerPorts(imageConfig)).withVolumeMounts(getVolumeMounts(config)).withLivenessProbe(livenessProbe).withReadinessProbe(readinessProbe).build();
            ret.add(container);
        }
    }
    return ret;
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) ArrayList(java.util.ArrayList) Probe(io.fabric8.kubernetes.api.model.Probe)

Aggregations

Test (org.junit.Test)106 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)37 HashMap (java.util.HashMap)34 IOException (java.io.IOException)32 ResourceConfig (io.fabric8.maven.core.config.ResourceConfig)28 File (java.io.File)26 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)24 Map (java.util.Map)24 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)23 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)21 Expectations (mockit.Expectations)20 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)17 ArrayList (java.util.ArrayList)17 VolumeConfig (io.fabric8.maven.core.config.VolumeConfig)15 AbstractConfigHandlerTest (io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)15 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)14 AuthConfig (io.fabric8.maven.docker.access.AuthConfig)13 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)12 Before (org.junit.Before)12 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)11