io.fabric8.kubernetes.api.model.ProbeBuilder Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.ProbeBuilder. 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: QuarkusHealthCheckEnricher.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private Probe discoverQuarkusHealthCheck(int initialDelay) {
    if (!getContext().hasDependency("io.quarkus", "quarkus-smallrye-health")) {
        return null;
    }

    return new ProbeBuilder()
        .withNewHttpGet()
          .withNewPort(asInteger(getConfig(Config.port)))
          .withPath(getConfig(Config.path))
          .withScheme(getConfig(Config.scheme))
        .endHttpGet()
        .withFailureThreshold(asInteger(getConfig(Config.failureThreshold)))
        .withSuccessThreshold(asInteger(getConfig(Config.successThreshold)))
        .withInitialDelaySeconds(initialDelay)
        .build();
}
 
Example #2
Source File: WebAppHealthCheckEnricher.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private Probe getProbe(boolean readiness) {
    if (!isApplicable()) {
        return null;
    }

    Integer port = getPort();
    String scheme = getScheme().toUpperCase();
    String path = getPath();

    int delay = readiness ? getInitialReadinessDelay() : getInitialLivenessDelay();

    return new ProbeBuilder().
        withNewHttpGet().withNewPort(port).withPath(path).withScheme(scheme).endHttpGet().
        withInitialDelaySeconds(delay).build();

}
 
Example #3
Source File: WildFlySwarmHealthCheckEnricher.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private Probe discoverWildFlySwarmHealthCheck(int initialDelay) {
    if (getContext().hasDependency("org.wildfly.swarm", "monitor")
            || getContext().hasDependency("org.wildfly.swarm", "microprofile-health")) {
        Integer port = getPort();
        // scheme must be in upper case in k8s
        String scheme = getScheme().toUpperCase();
        String path = getPath();

        // lets default to adding a wildfly swarm health check
        return new ProbeBuilder()
                .withNewHttpGet().withNewPort(port).withPath(path).withScheme(scheme).endHttpGet()
                .withFailureThreshold(getFailureThreshold())
                .withSuccessThreshold(getSuccessThreshold())
                .withInitialDelaySeconds(initialDelay).build();
    }
    return null;
}
 
Example #4
Source File: ThorntailV2HealthCheckEnricher.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private Probe discoverThorntailHealthCheck(int initialDelay) {
    if (getContext().hasDependency(IO_THORNTAIL, "thorntail-kernel")) {
        // if there's thorntail-kernel, it's Thorntail v4
        return null;
    }

    if (getContext().hasDependency(IO_THORNTAIL, "monitor")
            || getContext().hasDependency(IO_THORNTAIL, "microprofile-health")) {
        Integer port = getPort();
        // scheme must be in upper case in k8s
        String scheme = getScheme().toUpperCase();
        String path = getPath();

        return new ProbeBuilder()
                 .withNewHttpGet().withNewPort(port).withPath(path).withScheme(scheme).endHttpGet()
                 .withFailureThreshold(getFailureThreshold())
                 .withSuccessThreshold(getSuccessThreshold())
                 .withInitialDelaySeconds(initialDelay).build();
    }
    return null;
}
 
Example #5
Source File: ProbeCreator.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 6 votes vote down vote up
Probe create() {
	HTTPGetActionBuilder httpGetActionBuilder = new HTTPGetActionBuilder()
			.withPath(getProbePath())
			.withNewPort(getPort());

	List<HTTPHeader> httpHeaders = getHttpHeaders();

	if (!httpHeaders.isEmpty()) {
		httpGetActionBuilder.withHttpHeaders(httpHeaders);
	}

	return new ProbeBuilder()
			.withHttpGet(httpGetActionBuilder.build())
			.withTimeoutSeconds(getTimeout())
			.withInitialDelaySeconds(getInitialDelay())
			.withPeriodSeconds(getPeriod())
			.build();
}
 
Example #6
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 #7
Source File: RabbitMQContainers.java    From rabbitmq-operator with Apache License 2.0 5 votes vote down vote up
private Probe buildReadinessProbe() {
    return new ProbeBuilder()
            .withNewExec().withCommand("/probes/readiness.sh").endExec()
            .withInitialDelaySeconds(20)
            .withTimeoutSeconds(5)
            .withPeriodSeconds(5)
            .withFailureThreshold(3)
            .withSuccessThreshold(1)
            .build();
}
 
Example #8
Source File: DockerHealthCheckEnricher.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
private Probe getProbe(ImageConfiguration image) {
    if (hasHealthCheck(image)) {
        HealthCheckConfiguration health = image.getBuildConfiguration().getHealthCheck();
        return new ProbeBuilder()
                .withExec(new ExecAction(health.getCmd().asStrings()))
                .withTimeoutSeconds(durationSeconds(health.getTimeout()))
                .withPeriodSeconds(durationSeconds(health.getInterval()))
                .withFailureThreshold(health.getRetries())
                .build();
    }

    return null;
}
 
Example #9
Source File: AbstractHealthCheckEnricherTest.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
protected AbstractHealthCheckEnricher createEnricher(Properties properties, Map<String, String> pi) {

        JavaProject project = JavaProject.builder().properties(new Properties()).build();
        project.getProperties().putAll(properties);

        final JKubeEnricherContext.JKubeEnricherContextBuilder enricherContextBuilder = JKubeEnricherContext.builder()
                .project(project)
                .log(log);
        if(pi != null && !pi.isEmpty()) {
            enricherContextBuilder.processingInstructions(pi);
        }
        EnricherContext context = enricherContextBuilder.build();

        AbstractHealthCheckEnricher enricher = new AbstractHealthCheckEnricher(context, "basic") {
            @Override
            protected Probe getLivenessProbe() {
                return getReadinessProbe();
            }

            @Override
            protected Probe getReadinessProbe() {
                return new ProbeBuilder()
                        .withNewHttpGet()
                        .withHost("localhost")
                        .withNewPort(8080)
                        .endHttpGet()
                        .build();
            }
        };
        return enricher;
    }
 
Example #10
Source File: LanderPodFactory.java    From data-highway with Apache License 2.0 5 votes vote down vote up
private Container container(String roadName, List<String> args, Map<String, String> config, String truckParkName) {
  List<EnvVar> env = ImmutableList
      .<EnvVar> builder()
      .add(envFromFieldPath("KUBERNETES_NAMESPACE", "metadata.namespace"))
      .add(env("POD_NAME", truckParkName))
      .add(env("ENVIRONMENT", environment))
      .add(env("JVM_ARGS", config.get(JVM_ARGS)))
      .add(env("CLOUDWATCH_REGION", config.get(CLOUDWATCH_REGION)))
      .add(env("CLOUDWATCH_GROUP", config.get(CLOUDWATCH_GROUP)))
      .add(env("CLOUDWATCH_STREAM", "${KUBERNETES_NAMESPACE}-truck-park-" + roadName))
      .build();
  Map<String, Quantity> limits = ImmutableMap
      .<String, Quantity> builder()
      .put(CPU, new Quantity(config.get(CPU)))
      .put(MEMORY, new Quantity(config.get(MEMORY)))
      .build();
  return new ContainerBuilder()
      .withName(truckParkName)
      .withImage(config.get(DOCKER_IMAGE))
      .withArgs(args)
      .withEnv(env)
      .withResources(new ResourceRequirementsBuilder().withLimits(limits).withRequests(limits).build())
      .withLivenessProbe(new ProbeBuilder()
          .withHttpGet(new HTTPGetActionBuilder().withPath("/").withPort(new IntOrString("http")).build())
          .withInitialDelaySeconds(getConfigOrDefault(config, "livenessInitialDelay", 30))
          .withPeriodSeconds(getConfigOrDefault(config, "livenessPeriod", 5))
          .withSuccessThreshold(getConfigOrDefault(config, "livenessSuccessThreshold", 1))
          .withTimeoutSeconds(getConfigOrDefault(config, "livenessTimeout", 5))
          .withFailureThreshold(getConfigOrDefault(config, "livenessFailureThreshold", 3))
          .build())
      .build();
}
 
Example #11
Source File: KnativeServiceHandler.java    From module-ballerina-kubernetes with Apache License 2.0 5 votes vote down vote up
private Probe generateProbe(ProbeModel probeModel) {
    if (null == probeModel) {
        return null;
    }
    TCPSocketAction tcpSocketAction = new TCPSocketActionBuilder()
            .withNewPort(probeModel.getPort())
            .build();
    return new ProbeBuilder()
            .withInitialDelaySeconds(probeModel.getInitialDelaySeconds())
            .withPeriodSeconds(probeModel.getPeriodSeconds())
            .withTcpSocket(tcpSocketAction)
            .build();
}
 
Example #12
Source File: DeploymentHandler.java    From module-ballerina-kubernetes with Apache License 2.0 5 votes vote down vote up
private Probe generateProbe(ProbeModel probeModel) {
    if (null == probeModel) {
        return null;
    }
    TCPSocketAction tcpSocketAction = new TCPSocketActionBuilder()
            .withNewPort(probeModel.getPort())
            .build();
    return new ProbeBuilder()
            .withInitialDelaySeconds(probeModel.getInitialDelaySeconds())
            .withPeriodSeconds(probeModel.getPeriodSeconds())
            .withTcpSocket(tcpSocketAction)
            .build();
}
 
Example #13
Source File: KubeUtilTest.java    From enmasse with Apache License 2.0 5 votes vote down vote up
@Test
public void appliesContainerReadinessProbeSettingsToPodTemplate() {
    Container actualContainer = new ContainerBuilder()
            .withName("foo")
            .withReadinessProbe(new ProbeBuilder()
                    .withInitialDelaySeconds(1).build()).build();
    Container desiredContainer = new ContainerBuilder()
            .withName("foo")
            .withReadinessProbe(new ProbeBuilder()
                    .withInitialDelaySeconds(10).build()).build();
    PodTemplateSpec actual = doApplyContainers(actualContainer, desiredContainer);

    Container container = actual.getSpec().getContainers().get(0);
    assertThat(container.getReadinessProbe().getInitialDelaySeconds(), equalTo(10));
}
 
Example #14
Source File: ModelUtils.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
protected static ProbeBuilder newProbeBuilder(io.strimzi.api.kafka.model.Probe userProbe) {
    return new ProbeBuilder()
            .withInitialDelaySeconds(userProbe.getInitialDelaySeconds())
            .withTimeoutSeconds(userProbe.getTimeoutSeconds())
            .withPeriodSeconds(userProbe.getPeriodSeconds())
            .withSuccessThreshold(userProbe.getSuccessThreshold())
            .withFailureThreshold(userProbe.getFailureThreshold());
}
 
Example #15
Source File: PodTemplateBuilder.java    From kubernetes-plugin with Apache License 2.0 4 votes vote down vote up
private Container createContainer(ContainerTemplate containerTemplate, Collection<TemplateEnvVar> globalEnvVars,
        Collection<VolumeMount> volumeMounts) {
    Map<String, EnvVar> envVarsMap = new HashMap<>();
    String workingDir = substituteEnv(containerTemplate.getWorkingDir());
    if (JNLP_NAME.equals(containerTemplate.getName())) {
        envVarsMap.putAll(jnlpEnvVars(workingDir));
    }
    envVarsMap.putAll(defaultEnvVars(globalEnvVars));

    if (containerTemplate.getEnvVars() != null) {
        containerTemplate.getEnvVars().forEach(item ->
                envVarsMap.put(item.getKey(), item.buildEnvVar())
        );
    }

    EnvVar[] envVars = envVarsMap.values().stream().toArray(EnvVar[]::new);

    String cmd = containerTemplate.getArgs();
    if (slave != null && cmd != null) {
        SlaveComputer computer = slave.getComputer();
        if (computer != null) {
            cmd = cmd.replaceAll(JNLPMAC_REF, computer.getJnlpMac()) //
                    .replaceAll(NAME_REF, computer.getName());
        }
    }
    List<String> arguments = Strings.isNullOrEmpty(containerTemplate.getArgs()) ? Collections.emptyList()
            : parseDockerCommand(cmd);

    ContainerPort[] ports = containerTemplate.getPorts().stream().map(entry -> entry.toPort()).toArray(size -> new ContainerPort[size]);


    List<VolumeMount> containerMounts = getContainerVolumeMounts(volumeMounts, workingDir);

    ContainerLivenessProbe clp = containerTemplate.getLivenessProbe();
    Probe livenessProbe = null;
    if (clp != null && parseLivenessProbe(clp.getExecArgs()) != null) {
        livenessProbe = new ProbeBuilder()
                .withExec(new ExecAction(parseLivenessProbe(clp.getExecArgs())))
                .withInitialDelaySeconds(clp.getInitialDelaySeconds())
                .withTimeoutSeconds(clp.getTimeoutSeconds())
                .withFailureThreshold(clp.getFailureThreshold())
                .withPeriodSeconds(clp.getPeriodSeconds())
                .withSuccessThreshold(clp.getSuccessThreshold())
                .build();
    }

    return new ContainerBuilder()
            .withName(substituteEnv(containerTemplate.getName()))
            .withImage(substituteEnv(containerTemplate.getImage()))
            .withImagePullPolicy(containerTemplate.isAlwaysPullImage() ? "Always" : "IfNotPresent")
            .withNewSecurityContext()
            .withPrivileged(containerTemplate.isPrivileged())
            .withRunAsUser(containerTemplate.getRunAsUserAsLong())
            .withRunAsGroup(containerTemplate.getRunAsGroupAsLong())
            .endSecurityContext()
            .withWorkingDir(workingDir)
            .withVolumeMounts(containerMounts.toArray(new VolumeMount[containerMounts.size()]))
            .addToEnv(envVars)
            .addToPorts(ports)
            .withCommand(parseDockerCommand(containerTemplate.getCommand()))
            .withArgs(arguments)
            .withLivenessProbe(livenessProbe)
            .withTty(containerTemplate.isTtyEnabled())
            .withNewResources()
            .withRequests(getResourcesMap(containerTemplate.getResourceRequestMemory(), containerTemplate.getResourceRequestCpu()))
            .withLimits(getResourcesMap(containerTemplate.getResourceLimitMemory(), containerTemplate.getResourceLimitCpu()))
            .endResources()
            .build();
}
 
Example #16
Source File: OpenShiftServiceImplTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
DeploymentConfigBuilder baseDeploymentFor(final String name, final DeploymentData deploymentData) {
    return new DeploymentConfigBuilder()
        .withNewMetadata()
            .withName(openshiftName(name))
            .addToAnnotations(deploymentData.getAnnotations())
            .addToLabels(deploymentData.getLabels())
        .endMetadata()
        .withNewSpec()
            .withReplicas(1)
            .addToSelector("syndesis.io/integration", openshiftName(name))
            .withNewStrategy()
                .withType("Recreate")
                .withNewResources()
                   .addToLimits("memory", new Quantity(config.getDeploymentMemoryLimitMi()  + "Mi"))
                   .addToRequests("memory", new Quantity(config.getDeploymentMemoryRequestMi() +  "Mi"))
                .endResources()
            .endStrategy()
            .withRevisionHistoryLimit(0)
            .withNewTemplate()
                .withNewMetadata()
                    .addToLabels("syndesis.io/integration", openshiftName(name))
                    .addToLabels(OpenShiftServiceImpl.COMPONENT_LABEL, "integration")
                    .addToLabels(deploymentData.getLabels())
                    .addToAnnotations(deploymentData.getAnnotations())
                    .addToAnnotations("prometheus.io/scrape", "true")
                    .addToAnnotations("prometheus.io/port", "9779")
                .endMetadata()
                .withNewSpec()
                    .addNewContainer()
                        .withImage(deploymentData.getImage())
                        .withImagePullPolicy("Always")
                        .withName(openshiftName(name))
                        .addToEnv(new EnvVarBuilder().withName("LOADER_HOME").withValue(config.getIntegrationDataPath()).build())
                        .addToEnv(new EnvVarBuilder().withName("AB_JMX_EXPORTER_CONFIG").withValue("/tmp/src/prometheus-config.yml").build())
                        .addToEnv(new EnvVarBuilder().withName("JAEGER_ENDPOINT").withValue("http://syndesis-jaeger-collector:14268/api/traces").build())
                        .addToEnv(new EnvVarBuilder().withName("JAEGER_TAGS").withValue("integration.version="+deploymentData.getVersion()).build())
                        .addToEnv(new EnvVarBuilder().withName("JAEGER_SAMPLER_TYPE").withValue("const").build())
                        .addToEnv(new EnvVarBuilder().withName("JAEGER_SAMPLER_PARAM").withValue("1").build())
                        .addNewPort()
                            .withName("jolokia")
                            .withContainerPort(8778)
                        .endPort()
                        .addNewPort()
                            .withName("metrics")
                            .withContainerPort(9779)
                        .endPort()
                        .addNewPort()
                            .withName("management")
                            .withContainerPort(8081)
                        .endPort()
                        .addNewVolumeMount()
                            .withName("secret-volume")
                            .withMountPath("/deployments/config")
                            .withReadOnly(false)
                        .endVolumeMount()
                        .withLivenessProbe(new ProbeBuilder()
                            .withInitialDelaySeconds(config.getIntegrationLivenessProbeInitialDelaySeconds())
                            .withNewHttpGet()
                                .withPath("/actuator/health")
                                .withNewPort(8081)
                            .endHttpGet()
                            .build())
                    .endContainer()
                    .addNewVolume()
                        .withName("secret-volume")
                        .withNewSecret()
                            .withSecretName(openshiftName(name))
                        .endSecret()
                    .endVolume()
                .endSpec()
            .endTemplate()
            .addNewTrigger()
                .withNewImageChangeParams()
                    .withAutomatic(true)
                    .withContainerNames(openshiftName(name))
                    .withNewFrom()
                        .withKind("ImageStreamTag")
                        .withName(openshiftName(name) + ":0")
                    .endFrom()
                .endImageChangeParams()
                .withType("ImageChange")
            .endTrigger()
            .addNewTrigger()
                .withType("ConfigChange")
            .endTrigger()
        .endSpec();
}
 
Example #17
Source File: SpringBootHealthCheckEnricher.java    From jkube with Eclipse Public License 2.0 4 votes vote down vote up
protected Probe buildProbe(Properties springBootProperties, Integer initialDelay, Integer period, Integer timeout, Integer failureTh, Integer successTh) {
    SpringBootConfigurationHelper propertyHelper = new SpringBootConfigurationHelper(getContext().getDependencyVersion(SpringBootConfigurationHelper.SPRING_BOOT_GROUP_ID, SpringBootConfigurationHelper.SPRING_BOOT_ARTIFACT_ID));
    Integer managementPort = propertyHelper.getManagementPort(springBootProperties);
    boolean usingManagementPort = managementPort != null;

    Integer port = managementPort;
    if (port == null) {
        port = propertyHelper.getServerPort(springBootProperties);
    }

    String scheme;
    String prefix;
    if (usingManagementPort) {
        scheme = StringUtils.isNotBlank(springBootProperties.getProperty(propertyHelper.getManagementKeystorePropertyKey())) ? SCHEME_HTTPS : SCHEME_HTTP;
        prefix = springBootProperties.getProperty(propertyHelper.getManagementContextPathPropertyKey(), "");
    } else {
        scheme = StringUtils.isNotBlank(springBootProperties.getProperty(propertyHelper.getServerKeystorePropertyKey())) ? SCHEME_HTTPS : SCHEME_HTTP;
        prefix = springBootProperties.getProperty(propertyHelper.getServerContextPathPropertyKey(), "");
        prefix += springBootProperties.getProperty(propertyHelper.getServletPathPropertyKey(), "");
        prefix += springBootProperties.getProperty(propertyHelper.getManagementContextPathPropertyKey(), "");
    }

    String actuatorBasePathKey = propertyHelper.getActuatorBasePathPropertyKey();
    String actuatorBasePath = propertyHelper.getActuatorDefaultBasePath();
    if (actuatorBasePathKey != null) {
        actuatorBasePath = springBootProperties.getProperty(actuatorBasePathKey, actuatorBasePath);
    }

    // lets default to adding a spring boot actuator health check
    ProbeBuilder probeBuilder = new ProbeBuilder().
            withNewHttpGet().withNewPort(port).withPath(normalizeMultipleSlashes(prefix + actuatorBasePath + Configs.asString(getConfig(Config.path)))).withScheme(scheme).endHttpGet();

    if (initialDelay != null) {
        probeBuilder = probeBuilder.withInitialDelaySeconds(initialDelay);
    }
    if (period != null) {
        probeBuilder = probeBuilder.withPeriodSeconds(period);
    }
    if (timeout != null) {
        probeBuilder.withTimeoutSeconds(timeout);
    }
    if(failureTh != null) {
        probeBuilder.withFailureThreshold(failureTh);
    }
    if(successTh != null) {
        probeBuilder.withSuccessThreshold(successTh);
    }

    return probeBuilder.build();
}