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");
});
});
}
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;
}
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;
}
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;
}
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();
}
Aggregations