-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow configuring port of http probes #30566
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...ernetes/spi/src/main/java/io/quarkus/kubernetes/spi/KubernetesProbePortNameBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 to use for probes using an {@literal HTTP get} action. | ||
*/ | ||
public class KubernetesProbePortNameBuildItem extends SimpleBuildItem { | ||
|
||
private final String name; | ||
|
||
public KubernetesProbePortNameBuildItem(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |
70 changes: 63 additions & 7 deletions
70
...yment/src/main/java/io/quarkus/kubernetes/deployment/ApplyHttpGetActionPortDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
package io.quarkus.kubernetes.deployment; | ||
|
||
import static io.dekorate.kubernetes.decorator.AddServiceResourceDecorator.distinct; | ||
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; | ||
|
@@ -81,6 +83,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; | ||
|
||
|
@@ -687,6 +690,46 @@ private static List<DecoratorBuildItem> createAnnotationDecorators(Optional<Proj | |
return result; | ||
} | ||
|
||
/** | ||
* 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. | ||
* | ||
* @param name The name of the deployment / container. | ||
* @param target The deployment target | ||
* @param the probe kind (e.g. readinessProbe, livenessProbe etc) | ||
* @param portName the probe port name build item | ||
* @paramt ports a list of kubernetes port build items | ||
* @return a decorator for configures the port of the http action of the probe. | ||
*/ | ||
public static DecoratorBuildItem createProbeHttpPortDecorator(String name, String target, String probeKind, | ||
ProbeConfig probeConfig, | ||
Optional<KubernetesProbePortNameBuildItem> portName, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's awesome! I just have to emit that build item if the management interface is used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's exactly the idea. |
||
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 -> httpPortName.equals(p.getName())) | ||
.map(KubernetesPortBuildItem::getPort).findFirst().orElse(DEFAULT_HTTP_PORT)); | ||
return new DecoratorBuildItem(target, new ApplyHttpGetActionPortDecorator(name, name, port, probeKind)); | ||
} | ||
|
||
/** | ||
* Create the decorators needed for setting up probes. | ||
* The method will not create decorators related to ports, as they are not supported by all targets (e.g. knative) | ||
* Port related decorators are created by `applyProbePort` instead. | ||
* | ||
* @return a list of decorators that configure the probes | ||
*/ | ||
private static List<DecoratorBuildItem> createProbeDecorators(String name, String target, ProbeConfig livenessProbe, | ||
ProbeConfig readinessProbe, | ||
Optional<KubernetesHealthLivenessPathBuildItem> livenessPath, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same goes for change decorators.
Now, things may work even without those changes but it will be circumstantial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same. I am wrong, let me completely wipe them.