Search in sources :

Example 1 with Readiness

use of io.fabric8.kubernetes.client.internal.readiness.Readiness in project vertx-openshift-it by cescoffier.

the class HealthCheckIT method testReadinessIsPresent.

@Test
public void testReadinessIsPresent() throws Exception {
    final List<Container> containers = getContainers();
    ensureThat("the readiness probe is configured correctly", () -> {
        containers.forEach(c -> {
            Probe readinessProbe = c.getReadinessProbe();
            assertThat(readinessProbe).as("Readiness probe should not be null.").isNotNull();
            softly.assertThat(readinessProbe.getHttpGet().getPort().getIntVal()).as("port should be defined for readiness probe").isEqualTo(8088);
            softly.assertThat(readinessProbe.getHttpGet().getPath()).as("path should be defined for readiness probe").isEqualTo("/start");
        });
    });
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) Probe(io.fabric8.kubernetes.api.model.Probe) Test(org.junit.Test)

Example 2 with Readiness

use of io.fabric8.kubernetes.client.internal.readiness.Readiness in project vertx-openshift-it by cescoffier.

the class Kube method setReplicasAndWait.

public static DeploymentConfig setReplicasAndWait(KubernetesClient client, String name, int number) {
    OpenShiftClient oc = oc(client);
    DeploymentConfig config = oc.deploymentConfigs().withName(name).get();
    if (config == null) {
        fail("Unable to find the deployment config " + name);
        return null;
    }
    if (config.getSpec().getReplicas() == number) {
        return config;
    }
    config = oc.deploymentConfigs().withName(name).edit().editSpec().withReplicas(number).endSpec().done();
    if (number == 0) {
        // Wait until no pods
        await().atMost(duration()).until(() -> getPodsForDeploymentConfig(client, name).size() == 0);
    } else {
        // Wait until the right number of pods
        await().atMost(duration()).until(() -> getPodsForDeploymentConfig(client, name).size() == number);
        // Wait for readiness
        await().atMost(duration()).until(() -> getPodsForDeploymentConfig(client, name).stream().filter(KubernetesHelper::isPodReady).count() == number);
    }
    return config;
}
Also used : OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig)

Example 3 with Readiness

use of io.fabric8.kubernetes.client.internal.readiness.Readiness in project fabric8-maven-plugin by fabric8io.

the class DebugMojo method enableDebugging.

private boolean enableDebugging(HasMetadata entity, PodTemplateSpec template) {
    if (template != null) {
        PodSpec podSpec = template.getSpec();
        if (podSpec != null) {
            List<Container> containers = podSpec.getContainers();
            boolean enabled = false;
            for (int i = 0; i < containers.size(); i++) {
                Container container = containers.get(i);
                List<EnvVar> env = container.getEnv();
                if (env == null) {
                    env = new ArrayList<>();
                }
                remoteDebugPort = KubernetesResourceUtil.getEnvVar(env, DebugConstants.ENV_VAR_JAVA_DEBUG_PORT, DebugConstants.ENV_VAR_JAVA_DEBUG_PORT_DEFAULT);
                if (KubernetesResourceUtil.setEnvVar(env, DebugConstants.ENV_VAR_JAVA_DEBUG, "true")) {
                    container.setEnv(env);
                    enabled = true;
                }
                if (KubernetesResourceUtil.setEnvVar(env, DebugConstants.ENV_VAR_JAVA_DEBUG_SUSPEND, String.valueOf(debugSuspend))) {
                    container.setEnv(env);
                    enabled = true;
                }
                List<ContainerPort> ports = container.getPorts();
                if (ports == null) {
                    ports = new ArrayList<>();
                }
                if (KubernetesResourceUtil.addPort(ports, remoteDebugPort, "debug", log)) {
                    container.setPorts(ports);
                    enabled = true;
                }
                if (debugSuspend) {
                    // Setting a random session value to force pod restart
                    this.debugSuspendValue = String.valueOf(new Random().nextLong());
                    KubernetesResourceUtil.setEnvVar(env, DebugConstants.ENV_VAR_JAVA_DEBUG_SESSION, this.debugSuspendValue);
                    container.setEnv(env);
                    if (container.getReadinessProbe() != null) {
                        log.info("Readiness probe will be disabled on " + getKind(entity) + " " + getName(entity) + " to allow attaching a remote debugger during suspension");
                        container.setReadinessProbe(null);
                    }
                    enabled = true;
                } else {
                    if (KubernetesResourceUtil.removeEnvVar(env, DebugConstants.ENV_VAR_JAVA_DEBUG_SESSION)) {
                        container.setEnv(env);
                        enabled = true;
                    }
                }
            }
            if (enabled) {
                log.info("Enabling debug on " + getKind(entity) + " " + getName(entity));
                return true;
            }
        }
    }
    return false;
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) Random(java.util.Random) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) EnvVar(io.fabric8.kubernetes.api.model.EnvVar)

Example 4 with Readiness

use of io.fabric8.kubernetes.client.internal.readiness.Readiness in project fabric8-maven-plugin by fabric8io.

the class KarafHealthCheckEnricher method discoverKarafProbe.

// 
// Karaf has a readiness/health URL exposed if the fabric8-karaf-check feature is installed.
// 
private Probe discoverKarafProbe(String path, int initialDelay) {
    for (Plugin plugin : this.getProject().getBuildPlugins()) {
        if ("karaf-maven-plugin".equals(plugin.getArtifactId())) {
            Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
            if (configuration == null)
                return null;
            Xpp3Dom startupFeatures = configuration.getChild("startupFeatures");
            if (startupFeatures == null)
                return null;
            for (Xpp3Dom feature : startupFeatures.getChildren("feature")) {
                if ("fabric8-karaf-checks".equals(feature.getValue())) {
                    // TODO: handle the case where the user changes the default port
                    return new ProbeBuilder().withNewHttpGet().withNewPort(DEFAULT_HEALTH_CHECK_PORT).withPath(path).endHttpGet().withInitialDelaySeconds(initialDelay).build();
                }
            }
        }
    }
    return null;
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) ProbeBuilder(io.fabric8.kubernetes.api.model.ProbeBuilder) Plugin(org.apache.maven.model.Plugin)

Example 5 with Readiness

use of io.fabric8.kubernetes.client.internal.readiness.Readiness in project fabric8-maven-plugin by fabric8io.

the class VertxHealthCheckEnricher method discoverVertxHealthCheck.

private Probe discoverVertxHealthCheck(int initialDelay, boolean readiness) {
    if (!isApplicable()) {
        return null;
    }
    int port = getPort();
    String path = null;
    if (readiness) {
        path = getReadinessPath();
        if (path != null && path.isEmpty()) {
            // Disabled.
            return null;
        }
    }
    if (path == null) {
        path = getPath();
    }
    if (port <= 0 || path == null || path.isEmpty()) {
        // Health check disabled
        return null;
    }
    String scheme = getScheme();
    return new ProbeBuilder().withNewHttpGet().withScheme(scheme).withNewPort(port).withPath(path).endHttpGet().withInitialDelaySeconds(initialDelay).build();
}
Also used : ProbeBuilder(io.fabric8.kubernetes.api.model.ProbeBuilder)

Aggregations

Container (io.fabric8.kubernetes.api.model.Container)2 ProbeBuilder (io.fabric8.kubernetes.api.model.ProbeBuilder)2 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)1 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)1 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)1 Probe (io.fabric8.kubernetes.api.model.Probe)1 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)1 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)1 Random (java.util.Random)1 Plugin (org.apache.maven.model.Plugin)1 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)1 Test (org.junit.Test)1