Skip to content

Commit

Permalink
feat: introduce build item to set port name
Browse files Browse the repository at this point in the history
  • Loading branch information
iocanel committed Jan 24, 2023
1 parent 664ce65 commit a013f38
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.quarkus.kubernetes.spi;

import io.quarkus.builder.item.SimpleBuildItem;

/**
* A build item for selecting which port is going
*/
public class KubernetesProbePortNameBuildItem extends SimpleBuildItem {

private final String name;

public KubernetesProbePortNameBuildItem(String name) {
this.name = name;
}

public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package io.quarkus.kubernetes.deployment;

import static io.quarkus.kubernetes.deployment.Constants.DEFAULT_HTTP_PORT;
import static io.quarkus.kubernetes.deployment.Constants.HTTP_PORT;
import static io.quarkus.kubernetes.deployment.Constants.QUARKUS_ANNOTATIONS_BUILD_TIMESTAMP;
import static io.quarkus.kubernetes.deployment.Constants.QUARKUS_ANNOTATIONS_COMMIT_ID;
import static io.quarkus.kubernetes.deployment.Constants.QUARKUS_ANNOTATIONS_VCS_URL;
Expand Down Expand Up @@ -81,6 +82,7 @@
import io.quarkus.kubernetes.spi.KubernetesJobBuildItem;
import io.quarkus.kubernetes.spi.KubernetesLabelBuildItem;
import io.quarkus.kubernetes.spi.KubernetesPortBuildItem;
import io.quarkus.kubernetes.spi.KubernetesProbePortNameBuildItem;
import io.quarkus.kubernetes.spi.KubernetesRoleBindingBuildItem;
import io.quarkus.kubernetes.spi.KubernetesRoleBuildItem;

Expand Down Expand Up @@ -671,16 +673,28 @@ private static List<DecoratorBuildItem> createAnnotationDecorators(Optional<Proj
}

/**
* Create a decorator that sets the port to the http probe.
* The rules for setting the probe are the following:
* 1. if 'http-action-port' is set, use that.
* 2. if 'http-action-port-name' is set, use that to lookup the port value.
* 3. if a `KubernetesPorbePortBuild` is set, then use that to lookup the port.
* 4. if we still haven't found a port fallback to 8080.
*
* @return a decorator for configures the port of the http action of the probe.
*/
public static DecoratorBuildItem createProbeHttpPortDecorator(String name, String target, ProbeConfig probeConfig,
Optional<KubernetesProbePortNameBuildItem> portName,
List<KubernetesPortBuildItem> ports) {

//1. check if `httpActionPort` is defined
//2. lookup port by `httpPortName`
//3. fallback to DEFAULT_HTTP_PORT
String httpPortName = probeConfig.httpActionPortName
.or(() -> portName.map(KubernetesProbePortNameBuildItem::getName))
.orElse(HTTP_PORT);

Integer port = probeConfig.httpActionPort
.orElse(ports.stream().filter(p -> probeConfig.httpActionPortName.equals(p.getName()))
.orElse(ports.stream().filter(p -> httpPortName.equals(p.getName()))
.map(KubernetesPortBuildItem::getPort).findFirst().orElse(DEFAULT_HTTP_PORT));
return new DecoratorBuildItem(target, new ApplyHttpGetActionPortDecorator(name, name, port));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import io.quarkus.kubernetes.spi.KubernetesJobBuildItem;
import io.quarkus.kubernetes.spi.KubernetesLabelBuildItem;
import io.quarkus.kubernetes.spi.KubernetesPortBuildItem;
import io.quarkus.kubernetes.spi.KubernetesProbePortNameBuildItem;
import io.quarkus.kubernetes.spi.KubernetesResourceMetadataBuildItem;
import io.quarkus.kubernetes.spi.KubernetesRoleBindingBuildItem;
import io.quarkus.kubernetes.spi.KubernetesRoleBuildItem;
Expand Down Expand Up @@ -176,6 +177,7 @@ public List<DecoratorBuildItem> createDecorators(ApplicationInfoBuildItem applic
Optional<BaseImageInfoBuildItem> baseImage,
Optional<ContainerImageInfoBuildItem> image,
Optional<KubernetesCommandBuildItem> command,
Optional<KubernetesProbePortNameBuildItem> portName,
List<KubernetesPortBuildItem> ports,
Optional<KubernetesHealthLivenessPathBuildItem> livenessPath,
Optional<KubernetesHealthReadinessPathBuildItem> readinessPath,
Expand Down Expand Up @@ -296,8 +298,9 @@ public List<DecoratorBuildItem> createDecorators(ApplicationInfoBuildItem applic
}

// Probe port handling
result.add(KubernetesCommonHelper.createProbeHttpPortDecorator(name, OPENSHIFT, config.livenessProbe, ports));
result.add(KubernetesCommonHelper.createProbeHttpPortDecorator(name, OPENSHIFT, config.readinessProbe, ports));
result.add(KubernetesCommonHelper.createProbeHttpPortDecorator(name, OPENSHIFT, config.livenessProbe, portName, ports));
result.add(
KubernetesCommonHelper.createProbeHttpPortDecorator(name, OPENSHIFT, config.readinessProbe, portName, ports));

// Handle non-openshift builds
if (deploymentKind == DeploymentResourceKind.DeploymentConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public class ProbeConfig {
/**
* The port name ot use for selecting the port to congiure for the http get.
*/
@ConfigItem(defaultValue = "http")
String httpActionPortName;
@ConfigItem
Optional<String> httpActionPortName;

/**
* The http path to use for the probe For this to work, the container port also
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import io.quarkus.kubernetes.spi.KubernetesJobBuildItem;
import io.quarkus.kubernetes.spi.KubernetesLabelBuildItem;
import io.quarkus.kubernetes.spi.KubernetesPortBuildItem;
import io.quarkus.kubernetes.spi.KubernetesProbePortNameBuildItem;
import io.quarkus.kubernetes.spi.KubernetesResourceMetadataBuildItem;
import io.quarkus.kubernetes.spi.KubernetesRoleBindingBuildItem;
import io.quarkus.kubernetes.spi.KubernetesRoleBuildItem;
Expand Down Expand Up @@ -132,6 +133,7 @@ public List<DecoratorBuildItem> createDecorators(ApplicationInfoBuildItem applic
List<KubernetesAnnotationBuildItem> annotations,
List<KubernetesLabelBuildItem> labels, List<KubernetesEnvBuildItem> envs,
Optional<ContainerImageInfoBuildItem> image, Optional<KubernetesCommandBuildItem> command,
Optional<KubernetesProbePortNameBuildItem> portName,
List<KubernetesPortBuildItem> ports, Optional<KubernetesHealthLivenessPathBuildItem> livenessPath,
Optional<KubernetesHealthReadinessPathBuildItem> readinessPath, List<KubernetesRoleBuildItem> roles,
List<KubernetesRoleBindingBuildItem> roleBindings, Optional<CustomProjectRootBuildItem> customProjectRoot,
Expand Down Expand Up @@ -244,8 +246,10 @@ public List<DecoratorBuildItem> createDecorators(ApplicationInfoBuildItem applic
}

// Probe port handling
result.add(KubernetesCommonHelper.createProbeHttpPortDecorator(name, KUBERNETES, config.livenessProbe, ports));
result.add(KubernetesCommonHelper.createProbeHttpPortDecorator(name, KUBERNETES, config.readinessProbe, ports));
result.add(
KubernetesCommonHelper.createProbeHttpPortDecorator(name, KUBERNETES, config.livenessProbe, portName, ports));
result.add(
KubernetesCommonHelper.createProbeHttpPortDecorator(name, KUBERNETES, config.readinessProbe, portName, ports));

// Handle remote debug configuration
if (config.remoteDebug.enabled) {
Expand Down

0 comments on commit a013f38

Please sign in to comment.