Java Code Examples for io.fabric8.kubernetes.api.model.Container#getLivenessProbe()

The following examples show how to use io.fabric8.kubernetes.api.model.Container#getLivenessProbe() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KafkaMirrorMakerClusterTest.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultProbes() {
    KafkaMirrorMakerCluster mmc = KafkaMirrorMakerCluster.fromCrd(this.resource, VERSIONS);

    Deployment dep = mmc.generateDeployment(Collections.EMPTY_MAP, true, null, null);
    Container cont = dep.getSpec().getTemplate().getSpec().getContainers().get(0);
    Probe livenessProbe = cont.getLivenessProbe();
    Probe readinessProbe = cont.getReadinessProbe();

    assertThat(livenessProbe.getExec().getCommand().get(0), is("/opt/kafka/kafka_mirror_maker_liveness.sh"));
    assertThat(livenessProbe.getInitialDelaySeconds(), is(new Integer(60)));
    assertThat(livenessProbe.getTimeoutSeconds(), is(new Integer(5)));

    assertThat(readinessProbe.getExec().getCommand().size(), is(3));
    assertThat(readinessProbe.getExec().getCommand().get(0), is("test"));
    assertThat(readinessProbe.getExec().getCommand().get(1), is("-f"));
    assertThat(readinessProbe.getExec().getCommand().get(2), is("/tmp/mirror-maker-ready"));
    assertThat(readinessProbe.getInitialDelaySeconds(), is(new Integer(60)));
    assertThat(readinessProbe.getTimeoutSeconds(), is(new Integer(5)));

    assertThat(cont.getEnv().stream().filter(env -> "STRIMZI_READINESS_PERIOD".equals(env.getName())).map(EnvVar::getValue).findFirst().orElse("").equals("10"), is(true));
    assertThat(cont.getEnv().stream().filter(env -> "STRIMZI_LIVENESS_PERIOD".equals(env.getName())).map(EnvVar::getValue).findFirst().orElse("").equals("10"), is(true));
}
 
Example 2
Source File: KubeUtilTest.java    From enmasse with Apache License 2.0 6 votes vote down vote up
@Test
public void appliesContainerLivenessProbeSettingsToPodTemplate() {
    Container actualContainer = new ContainerBuilder()
            .withName("foo")
            .withLivenessProbe(new ProbeBuilder()
                    .withInitialDelaySeconds(1)
                    .withPeriodSeconds(2)
                    .withFailureThreshold(4).build()).build();
    Container desiredContainer = new ContainerBuilder()
            .withName("foo")
            .withLivenessProbe(new ProbeBuilder()
                    .withInitialDelaySeconds(10)
                    .withSuccessThreshold(80).build()).build();
    PodTemplateSpec actual = doApplyContainers(actualContainer, desiredContainer);

    Container container = actual.getSpec().getContainers().get(0);
    Probe probe = container.getLivenessProbe();
    assertThat(probe.getInitialDelaySeconds(), equalTo(10));
    assertThat(probe.getPeriodSeconds(), equalTo(2));
    assertThat(probe.getFailureThreshold(), equalTo(4));
    assertThat(probe.getSuccessThreshold(), equalTo(80));
}
 
Example 3
Source File: Issue369Test.java    From dekorate with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldContainUserProvidedProbeConfiguration() {
  KubernetesList list = Serialization.unmarshalAsList(Issue369Test.class.getClassLoader().getResourceAsStream("META-INF/dekorate/kubernetes.yml"));
  assertNotNull(list);
  Deployment d = findFirst(list, Deployment.class).orElseThrow(() -> new IllegalStateException());
  assertNotNull(d);
  Container c = d.getSpec().getTemplate().getSpec().getContainers().get(0);
  assertNotNull(c);
  Probe p = c.getLivenessProbe();
  assertTrue(100 == p.getInitialDelaySeconds());
  assertTrue(100 == p.getPeriodSeconds());
}
 
Example 4
Source File: KafkaMirrorMakerClusterTest.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfiguredProbes() {
    KafkaMirrorMaker resource = new KafkaMirrorMakerBuilder(this.resource)
            .editSpec()
                .withNewLivenessProbe()
                    .withInitialDelaySeconds(120)
                    .withTimeoutSeconds(10)
                    .withPeriodSeconds(60)
                .endLivenessProbe()
                .withNewReadinessProbe()
                    .withInitialDelaySeconds(121)
                    .withTimeoutSeconds(11)
                    .withPeriodSeconds(61)
                .endReadinessProbe()
            .endSpec()
            .build();
    KafkaMirrorMakerCluster mmc = KafkaMirrorMakerCluster.fromCrd(resource, VERSIONS);

    Deployment dep = mmc.generateDeployment(Collections.EMPTY_MAP, true, null, null);
    Container cont = dep.getSpec().getTemplate().getSpec().getContainers().get(0);
    Probe livenessProbe = cont.getLivenessProbe();
    Probe readinessProbe = cont.getReadinessProbe();

    assertThat(livenessProbe.getExec().getCommand().get(0), is("/opt/kafka/kafka_mirror_maker_liveness.sh"));
    assertThat(livenessProbe.getInitialDelaySeconds(), is(new Integer(120)));
    assertThat(livenessProbe.getTimeoutSeconds(), is(new Integer(10)));
    assertThat(livenessProbe.getPeriodSeconds(), is(new Integer(60)));

    assertThat(readinessProbe.getExec().getCommand().size(), is(3));
    assertThat(readinessProbe.getExec().getCommand().get(0), is("test"));
    assertThat(readinessProbe.getExec().getCommand().get(1), is("-f"));
    assertThat(readinessProbe.getExec().getCommand().get(2), is("/tmp/mirror-maker-ready"));
    assertThat(readinessProbe.getInitialDelaySeconds(), is(new Integer(121)));
    assertThat(readinessProbe.getTimeoutSeconds(), is(new Integer(11)));
    assertThat(readinessProbe.getPeriodSeconds(), is(new Integer(61)));

    assertThat(cont.getEnv().stream().filter(env -> "STRIMZI_READINESS_PERIOD".equals(env.getName())).map(EnvVar::getValue).findFirst().orElse("").equals("61"), is(true));
    assertThat(cont.getEnv().stream().filter(env -> "STRIMZI_LIVENESS_PERIOD".equals(env.getName())).map(EnvVar::getValue).findFirst().orElse("").equals("60"), is(true));
}