forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kubernetes: Provide properties to remote debugging
This PR allows to easily configure the remote debugging and describes how to do this in the documentation. I've also tried to expose another route to map the java agent port, but as intellij could handle this port from localhost (it threw a handshake error), I decided to not over-complicate this guide and simple do the port-forward bit (see my changes in documentation). Fix quarkusio#17581 Fix quarkusio#23765
- Loading branch information
Showing
10 changed files
with
256 additions
and
2 deletions.
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
55 changes: 55 additions & 0 deletions
55
...rnetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/DebugConfig.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,55 @@ | ||
package io.quarkus.kubernetes.deployment; | ||
|
||
import io.dekorate.kubernetes.config.Env; | ||
import io.dekorate.kubernetes.config.EnvBuilder; | ||
import io.dekorate.kubernetes.config.Port; | ||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
|
||
@ConfigGroup | ||
public class DebugConfig { | ||
|
||
private static final String PORT_NAME = "debug"; | ||
private static final String JAVA_TOOL_OPTIONS = "JAVA_TOOL_OPTIONS"; | ||
private static final String AGENTLIB_FORMAT = "-agentlib:jdwp=transport=%s,server=y,suspend=%s,address=%s"; | ||
|
||
/** | ||
* If true, the debug mode in pods will be enabled. | ||
*/ | ||
@ConfigItem(defaultValue = "false") | ||
boolean enabled; | ||
|
||
/** | ||
* The transport to use. | ||
*/ | ||
@ConfigItem(defaultValue = "dt_socket") | ||
String transport; | ||
|
||
/** | ||
* If enabled, it means the JVM will wait for the debugger to attach before executing the main class. | ||
* If false, the JVM will immediately execute the main class, while listening for | ||
* the debugger connection. | ||
*/ | ||
@ConfigItem(defaultValue = "n") | ||
String suspend; | ||
|
||
/** | ||
* It specifies the address at which the debug socket will listen. | ||
*/ | ||
@ConfigItem(defaultValue = "5005") | ||
Integer addressPort; | ||
|
||
protected Env buildJavaToolOptionsEnv() { | ||
return new EnvBuilder() | ||
.withName(JAVA_TOOL_OPTIONS) | ||
.withValue(String.format(AGENTLIB_FORMAT, transport, suspend, addressPort)) | ||
.build(); | ||
} | ||
|
||
protected Port buildDebugPort() { | ||
return Port.newBuilder() | ||
.withName(PORT_NAME) | ||
.withContainerPort(addressPort) | ||
.build(); | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
...us-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithRemoteDebugTest.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,65 @@ | ||
package io.quarkus.it.kubernetes; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.fabric8.kubernetes.api.model.EnvVar; | ||
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
import io.fabric8.kubernetes.api.model.Service; | ||
import io.fabric8.kubernetes.api.model.apps.Deployment; | ||
import io.quarkus.test.ProdBuildResults; | ||
import io.quarkus.test.ProdModeTestResults; | ||
import io.quarkus.test.QuarkusProdModeTest; | ||
|
||
public class KubernetesWithRemoteDebugTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusProdModeTest config = new QuarkusProdModeTest() | ||
.withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) | ||
.setApplicationName("kubernetes-with-debug") | ||
.setApplicationVersion("0.1-SNAPSHOT") | ||
.withConfigurationResource("kubernetes-with-debug.properties"); | ||
|
||
@ProdBuildResults | ||
private ProdModeTestResults prodModeTestResults; | ||
|
||
@Test | ||
public void assertGeneratedResources() throws IOException { | ||
Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); | ||
List<HasMetadata> openshiftList = DeserializationUtil.deserializeAsList( | ||
kubernetesDir.resolve("kubernetes.yml")); | ||
|
||
assertThat(openshiftList).filteredOn(h -> "Deployment".equals(h.getKind())).singleElement().satisfies(h -> { | ||
Deployment deployment = (Deployment) h; | ||
assertThat(deployment.getSpec().getTemplate().getSpec().getContainers()).singleElement().satisfies(container -> { | ||
List<EnvVar> envVars = container.getEnv(); | ||
assertThat(envVars).anySatisfy(envVar -> { | ||
assertThat(envVar.getName()).isEqualTo("JAVA_TOOL_OPTIONS"); | ||
assertThat(envVar.getValue()) | ||
.isEqualTo("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000"); | ||
}); | ||
}); | ||
}); | ||
|
||
assertThat(openshiftList).filteredOn(h -> "Service".equals(h.getKind())).singleElement().satisfies(h -> { | ||
Service service = (Service) h; | ||
assertThat(service.getSpec().getPorts()).anySatisfy(p -> { | ||
assertThat(p.getName()).isEqualTo("http"); | ||
assertThat(p.getPort()).isEqualTo(80); | ||
assertThat(p.getTargetPort().getIntVal()).isEqualTo(8080); | ||
}); | ||
|
||
assertThat(service.getSpec().getPorts()).anySatisfy(p -> { | ||
assertThat(p.getName()).isEqualTo("debug"); | ||
assertThat(p.getPort()).isEqualTo(8000); | ||
assertThat(p.getTargetPort().getIntVal()).isEqualTo(8000); | ||
}); | ||
}); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...kus-standard-way/src/test/java/io/quarkus/it/kubernetes/OpenshiftWithRemoteDebugTest.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,74 @@ | ||
package io.quarkus.it.kubernetes; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.fabric8.kubernetes.api.model.EnvVar; | ||
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
import io.fabric8.kubernetes.api.model.Service; | ||
import io.fabric8.openshift.api.model.DeploymentConfig; | ||
import io.quarkus.bootstrap.model.AppArtifact; | ||
import io.quarkus.builder.Version; | ||
import io.quarkus.test.ProdBuildResults; | ||
import io.quarkus.test.ProdModeTestResults; | ||
import io.quarkus.test.QuarkusProdModeTest; | ||
|
||
public class OpenshiftWithRemoteDebugTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusProdModeTest config = new QuarkusProdModeTest() | ||
.withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) | ||
.setApplicationName("openshift-with-debug") | ||
.setApplicationVersion("0.1-SNAPSHOT") | ||
.withConfigurationResource("openshift-with-debug.properties") | ||
.setForcedDependencies(Collections.singletonList( | ||
new AppArtifact("io.quarkus", "quarkus-openshift", Version.getVersion()))); | ||
|
||
@ProdBuildResults | ||
private ProdModeTestResults prodModeTestResults; | ||
|
||
@Test | ||
public void assertGeneratedResources() throws IOException { | ||
Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); | ||
|
||
assertThat(kubernetesDir) | ||
.isDirectoryContaining(p -> p.getFileName().endsWith("openshift.json")) | ||
.isDirectoryContaining(p -> p.getFileName().endsWith("openshift.yml")); | ||
List<HasMetadata> openshiftList = DeserializationUtil.deserializeAsList( | ||
kubernetesDir.resolve("openshift.yml")); | ||
|
||
assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { | ||
DeploymentConfig deployment = (DeploymentConfig) h; | ||
assertThat(deployment.getSpec().getTemplate().getSpec().getContainers()).singleElement().satisfies(container -> { | ||
List<EnvVar> envVars = container.getEnv(); | ||
assertThat(envVars).anySatisfy(envVar -> { | ||
assertThat(envVar.getName()).isEqualTo("JAVA_TOOL_OPTIONS"); | ||
assertThat(envVar.getValue()) | ||
.isEqualTo("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"); | ||
}); | ||
}); | ||
}); | ||
|
||
assertThat(openshiftList).filteredOn(h -> "Service".equals(h.getKind())).singleElement().satisfies(h -> { | ||
Service service = (Service) h; | ||
assertThat(service.getSpec().getPorts()).anySatisfy(p -> { | ||
assertThat(p.getName()).isEqualTo("http"); | ||
assertThat(p.getPort()).isEqualTo(80); | ||
assertThat(p.getTargetPort().getIntVal()).isEqualTo(8080); | ||
}); | ||
|
||
assertThat(service.getSpec().getPorts()).anySatisfy(p -> { | ||
assertThat(p.getName()).isEqualTo("debug"); | ||
assertThat(p.getPort()).isEqualTo(5005); | ||
assertThat(p.getTargetPort().getIntVal()).isEqualTo(5005); | ||
}); | ||
}); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-debug.properties
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,2 @@ | ||
quarkus.kubernetes.remote-debug.enabled=true | ||
quarkus.kubernetes.remote-debug.address-port=8000 |
1 change: 1 addition & 0 deletions
1
...-tests/kubernetes/quarkus-standard-way/src/test/resources/openshift-with-debug.properties
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 @@ | ||
quarkus.openshift.remote-debug.enabled=true |