Skip to content

Commit

Permalink
feat: add health probes
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosthe19916 committed Aug 1, 2024
1 parent 044b439 commit 2889ace
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 54 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/trustify/operator/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class Constants {
//
public static final Integer HTTP_PORT = 8080;
public static final Integer HTTPS_PORT = 8443;
public static final Integer HTTP_INFRAESTRUCTURE_PORT = 9010;
public static final String SERVICE_PROTOCOL = "TCP";

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ private DeploymentSpec getDeploymentSpec(Trustify cr, Context<Trustify> context,
.orElse(null);

return new DeploymentSpecBuilder()
.withMinReadySeconds(2)
.withStrategy(new DeploymentStrategyBuilder()
.withType("Recreate")
.build()
Expand All @@ -136,61 +135,72 @@ private DeploymentSpec getDeploymentSpec(Trustify cr, Context<Trustify> context,
.withImage(image)
.withImagePullPolicy(imagePullPolicy)
.withEnv(envVars)
.withCommand("/usr/local/bin/trustd", "api", "--devmode")
.withCommand(
"/usr/local/bin/trustd",
"api",
"--devmode",
"--infrastructure-enabled",
"--infrastructure-bind=0.0.0.0:" + Constants.HTTP_INFRAESTRUCTURE_PORT
)
.withPorts(
new ContainerPortBuilder()
.withName("http")
.withProtocol("TCP")
.withContainerPort(8080)
.build()
.withContainerPort(Constants.HTTP_PORT)
.build(),
// new ContainerPortBuilder()
// .withName("https")
// .withProtocol("TCP")
// .withContainerPort(8443)
// .build()
new ContainerPortBuilder()
.withName("http-infra")
.withProtocol("TCP")
.withContainerPort(Constants.HTTP_INFRAESTRUCTURE_PORT)
.build()
)
.withLivenessProbe(new ProbeBuilder()
.withHttpGet(new HTTPGetActionBuilder()
.withPath("/health/live")
.withNewPort(Constants.HTTP_INFRAESTRUCTURE_PORT)
.withScheme("HTTP")
.build()
)
.withInitialDelaySeconds(5)
.withTimeoutSeconds(10)
.withPeriodSeconds(10)
.withSuccessThreshold(1)
.withFailureThreshold(3)
.build()
)
.withReadinessProbe(new ProbeBuilder()
.withHttpGet(new HTTPGetActionBuilder()
.withPath("health/ready")
.withNewPort(Constants.HTTP_INFRAESTRUCTURE_PORT)
.withScheme("HTTP")
.build()
)
.withInitialDelaySeconds(5)
.withTimeoutSeconds(1)
.withPeriodSeconds(10)
.withSuccessThreshold(1)
.withFailureThreshold(3)
.build()
)
.withStartupProbe(new ProbeBuilder()
.withHttpGet(new HTTPGetActionBuilder()
.withPath("/health/startup")
.withNewPort(Constants.HTTP_INFRAESTRUCTURE_PORT)
.withScheme("HTTP")
.build()
)
.withInitialDelaySeconds(5)
.withTimeoutSeconds(1)
.withPeriodSeconds(10)
.withSuccessThreshold(1)
.withFailureThreshold(3)
.build()
)
// .withLivenessProbe(new ProbeBuilder()
// .withHttpGet(new HTTPGetActionBuilder()
// .withPath("/q/health/live")
// .withNewPort(8080)
// .withScheme("HTTP")
// .build()
// )
// .withInitialDelaySeconds(5)
// .withTimeoutSeconds(10)
// .withPeriodSeconds(10)
// .withSuccessThreshold(1)
// .withFailureThreshold(3)
// .build()
// )
// .withReadinessProbe(new ProbeBuilder()
// .withHttpGet(new HTTPGetActionBuilder()
// .withPath("/q/health/ready")
// .withNewPort(8080)
// .withScheme("HTTP")
// .build()
// )
// .withInitialDelaySeconds(5)
// .withTimeoutSeconds(1)
// .withPeriodSeconds(10)
// .withSuccessThreshold(1)
// .withFailureThreshold(3)
// .build()
// )
// .withStartupProbe(new ProbeBuilder()
// .withHttpGet(new HTTPGetActionBuilder()
// .withPath("/q/health/started")
// .withNewPort(8080)
// .withScheme("HTTP")
// .build()
// )
// .withInitialDelaySeconds(5)
// .withTimeoutSeconds(1)
// .withPeriodSeconds(10)
// .withSuccessThreshold(1)
// .withFailureThreshold(3)
// .build()
// )
.withVolumeMounts(volumeMounts)
.withResources(new ResourceRequirementsBuilder()
.withRequests(Map.of(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.trustify.operator.cdrs.v2alpha1.server;

import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.api.model.ServiceBuilder;
import io.fabric8.kubernetes.api.model.ServiceSpec;
import io.fabric8.kubernetes.api.model.ServiceSpecBuilder;
import io.fabric8.kubernetes.api.model.*;
import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource;
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent;
Expand Down Expand Up @@ -49,10 +46,18 @@ private Service newService(Trustify cr, Context context) {

private ServiceSpec getServiceSpec(Trustify cr) {
return new ServiceSpecBuilder()
.addNewPort()
.withPort(getServicePort(cr))
.withProtocol(Constants.SERVICE_PROTOCOL)
.endPort()
.withPorts(
new ServicePortBuilder()
.withName("http")
.withPort(getServicePort(cr))
.withProtocol(Constants.SERVICE_PROTOCOL)
.build(),
new ServicePortBuilder()
.withName("http-infra")
.withPort(getServiceInfraestructurePort(cr))
.withProtocol(Constants.SERVICE_PROTOCOL)
.build()
)
.withSelector(Constants.SERVER_SELECTOR_LABELS)
.withType("ClusterIP")
.build();
Expand All @@ -62,6 +67,10 @@ public static int getServicePort(Trustify cr) {
return Constants.HTTP_PORT;
}

public static int getServiceInfraestructurePort(Trustify cr) {
return Constants.HTTP_INFRAESTRUCTURE_PORT;
}

public static String getServiceName(Trustify cr) {
return cr.getMetadata().getName() + Constants.SERVER_SERVICE_SUFFIX;
}
Expand Down

0 comments on commit 2889ace

Please sign in to comment.