Search in sources :

Example 1 with HealthCheck

use of io.fabric8.core.jmx.HealthCheck in project docker-maven-plugin by fabric8io.

the class DockerFileBuilderTest method testHealthCheckNone.

@Test
public void testHealthCheckNone() {
    HealthCheckConfiguration hc = new HealthCheckConfiguration.Builder().mode(HealthCheckMode.none).build();
    String dockerfileContent = new DockerFileBuilder().healthCheck(hc).content();
    assertThat(dockerfileToMap(dockerfileContent), hasEntry("HEALTHCHECK", "NONE"));
}
Also used : HealthCheckConfiguration(io.fabric8.maven.docker.config.HealthCheckConfiguration) Test(org.junit.Test)

Example 2 with HealthCheck

use of io.fabric8.core.jmx.HealthCheck in project fabric8-maven-plugin by fabric8io.

the class DockerHealthCheckEnricherTest method testUnmatchingHealthCheck.

@Test
public void testUnmatchingHealthCheck() throws Exception {
    // Setup mock behaviour
    new Expectations() {

        {
            context.getImages();
            result = Arrays.asList(new ImageConfiguration.Builder().alias("myImage").buildConfig(new BuildImageConfiguration.Builder().healthCheck(new HealthCheckConfiguration.Builder().mode(HealthCheckMode.cmd).cmd("/bin/check").timeout("1s").interval("1h1s").retries(3).build()).build()).build());
        }
    };
    KubernetesListBuilder builder = createDeployment("myUnmatchingImage");
    DockerHealthCheckEnricher enricher = new DockerHealthCheckEnricher(context);
    enricher.addMissingResources(builder);
    KubernetesList list = builder.build();
    assertEquals(1, list.getItems().size());
    assertNoProbes(list.getItems().get(0));
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Test(org.junit.Test)

Example 3 with HealthCheck

use of io.fabric8.core.jmx.HealthCheck in project fabric8-maven-plugin by fabric8io.

the class DockerHealthCheckEnricherTest method testEnrichFromSingleImage.

@Test
public void testEnrichFromSingleImage() throws Exception {
    // Setup mock behaviour
    new Expectations() {

        {
            context.getImages();
            result = Arrays.asList(new ImageConfiguration.Builder().alias("myImage").buildConfig(new BuildImageConfiguration.Builder().healthCheck(new HealthCheckConfiguration.Builder().mode(HealthCheckMode.cmd).cmd("/bin/check").timeout("1s").interval("1h1s").retries(3).build()).build()).build(), new ImageConfiguration.Builder().alias("myImage2").buildConfig(new BuildImageConfiguration.Builder().healthCheck(new HealthCheckConfiguration.Builder().mode(HealthCheckMode.cmd).cmd("/xxx/check").timeout("3s").interval("3h1s").retries(9).build()).build()).build());
        }
    };
    KubernetesListBuilder builder = createDeployment("myImage");
    DockerHealthCheckEnricher enricher = new DockerHealthCheckEnricher(context);
    enricher.addMissingResources(builder);
    KubernetesList list = builder.build();
    assertEquals(1, list.getItems().size());
    assertHealthCheckMatching(builder.build().getItems().get(0), "livenessProbe", "/bin/check", 1, 3601, 3);
    assertHealthCheckMatching(builder.build().getItems().get(0), "readinessProbe", "/bin/check", 1, 3601, 3);
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Test(org.junit.Test)

Example 4 with HealthCheck

use of io.fabric8.core.jmx.HealthCheck in project strimzi by strimzi.

the class OpenShiftTemplatesTest method testStrimziPersistentWithCustomParameters.

@Test
public void testStrimziPersistentWithCustomParameters() throws IOException {
    String clusterName = "test-persistent-with-custom-parameters";
    oc.newApp("strimzi-persistent", map("CLUSTER_NAME", clusterName, "ZOOKEEPER_HEALTHCHECK_DELAY", "30", "ZOOKEEPER_HEALTHCHECK_TIMEOUT", "10", "KAFKA_HEALTHCHECK_DELAY", "30", "KAFKA_HEALTHCHECK_TIMEOUT", "10", "KAFKA_DEFAULT_REPLICATION_FACTOR", "2", "KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR", "5", "KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR", "5", "ZOOKEEPER_VOLUME_CAPACITY", "2Gi", "KAFKA_VOLUME_CAPACITY", "2Gi"));
    // TODO Add assertions to check that Kafka brokers have a custom configuration
    ConfigMap cm = client.configMaps().inNamespace(NAMESPACE).withName(clusterName).get();
    assertNotNull(cm);
    Map<String, String> cmData = cm.getData();
    assertEquals("30", cmData.get("zookeeper-healthcheck-delay"));
    assertEquals("10", cmData.get("zookeeper-healthcheck-timeout"));
    assertEquals("30", cmData.get("kafka-healthcheck-delay"));
    assertEquals("10", cmData.get("kafka-healthcheck-timeout"));
    assertEquals("2", cmData.get("KAFKA_DEFAULT_REPLICATION_FACTOR"));
    assertEquals("5", cmData.get("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR"));
    assertEquals("5", cmData.get("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR"));
    assertEquals("2Gi", mapper.readTree(cmData.get("kafka-storage")).get("size").asText());
    assertEquals("2Gi", mapper.readTree(cmData.get("zookeeper-storage")).get("size").asText());
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Test(org.junit.Test)

Example 5 with HealthCheck

use of io.fabric8.core.jmx.HealthCheck in project docker-maven-plugin by fabric8io.

the class HealthCheckChecker method check.

@Override
public boolean check() {
    try {
        final ContainerDetails container = docker.getContainer(containerId);
        if (container == null) {
            log.debug("HealthWaitChecker: Container %s not found");
            return false;
        }
        if (container.getHealthcheck() == null) {
            throw new IllegalArgumentException("Can not wait for healthstate of " + imageConfigDesc + ". No HEALTHCHECK configured.");
        }
        if (first) {
            log.info("%s: Waiting to become healthy", imageConfigDesc);
            log.debug("HealthWaitChecker: Waiting for healthcheck: '%s'", container.getHealthcheck());
            first = false;
        } else if (log.isDebugEnabled()) {
            log.debug("HealthWaitChecker: Waiting on healthcheck '%s'", container.getHealthcheck());
        }
        return container.isHealthy();
    } catch (DockerAccessException e) {
        log.warn("Error while checking health: %s", e.getMessage());
        return false;
    }
}
Also used : DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) ContainerDetails(io.fabric8.maven.docker.model.ContainerDetails)

Aggregations

Test (org.junit.Test)8 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)4 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)4 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)4 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)4 Expectations (mockit.Expectations)4 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 HealthCheckConfiguration (io.fabric8.maven.docker.config.HealthCheckConfiguration)2 FabricManager (io.fabric8.core.jmx.FabricManager)1 FileSystem (io.fabric8.core.jmx.FileSystem)1 HealthCheck (io.fabric8.core.jmx.HealthCheck)1 ZooKeeperFacade (io.fabric8.core.jmx.ZooKeeperFacade)1 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)1 ContainerDetails (io.fabric8.maven.docker.model.ContainerDetails)1