Skip to content

Commit

Permalink
Fix #152: Namespace ignored during debug goal
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanKanojia authored and manusa committed Apr 21, 2020
1 parent ad0e6a2 commit d021430
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Usage:
* Fix #120: Critical bugs reported by Sonar
* Fix #88: Unreachable statement in DockerAssemblyManager
* Fix #122: Bug 561261 - jkube-kit - insecure yaml load leading to RCE (CWE-502)
* Fix #152: kubernetes namespace is ignored in debug goal

### 0.2.0 (2020-03-05)
* Fix #71: script to extract changelog information for notifications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void run() {

if (nextPod != null) {
log.info("Starting port-forward to pod %s", KubernetesHelper.getName(nextPod));
currentPortForward = forwardPortAsync(externalProcessKitLogger, KubernetesHelper.getName(nextPod), remotePort, localPort);
currentPortForward = forwardPortAsync(externalProcessKitLogger, KubernetesHelper.getName(nextPod), null, remotePort, localPort);
} else {
log.info("Waiting for a pod to become ready before starting port-forward");
}
Expand Down Expand Up @@ -220,18 +220,21 @@ private Pod getNewestPod(List<Pod> items) {
return targetPod;
}

public void forwardPort(KitLogger externalProcessKitLogger, String pod, int remotePort, int localPort) throws JKubeServiceException {
forwardPortAsync(externalProcessKitLogger, pod, remotePort, localPort).await();
public void forwardPort(KitLogger externalProcessKitLogger, String pod, String namespace, int remotePort, int localPort) throws JKubeServiceException {
forwardPortAsync(externalProcessKitLogger, pod, namespace, remotePort, localPort).await();
}

public ProcessUtil.ProcessExecutionContext forwardPortAsync(KitLogger externalProcessKitLogger, String pod, int remotePort, int localPort) throws JKubeServiceException {
public ProcessUtil.ProcessExecutionContext forwardPortAsync(KitLogger externalProcessKitLogger, String pod, String namespace, int remotePort, int localPort) throws JKubeServiceException {
File command = clientToolsService.getKubeCtlExecutable(OpenshiftHelper.isOpenShiftClient(kubernetes));
log.info("Port forwarding to port " + remotePort + " on pod " + pod + " using command " + command);

List<String> args = new ArrayList<>();
args.add("port-forward");
args.add(pod);
args.add(localPort + ":" + remotePort);
if (namespace != null) {
args.add("-n" + namespace);
}

String commandLine = command + " " + StringUtils.join(args, " ");
log.verbose("Executing command " + commandLine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void testSimpleScenario() throws Exception {
OpenShiftClient client = mockServer.createOpenShiftClient();
PortForwardService service = new PortForwardService(client, logger) {
@Override
public ProcessUtil.ProcessExecutionContext forwardPortAsync(KitLogger externalProcessLogger, String pod, int remotePort, int localPort) throws JKubeServiceException {
public ProcessUtil.ProcessExecutionContext forwardPortAsync(KitLogger externalProcessLogger, String pod, String namespace, int remotePort, int localPort) throws JKubeServiceException {
return new ProcessUtil.ProcessExecutionContext(process, Collections.<Thread>emptyList(), logger);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ protected void applyEntities(KubernetesClient kubernetes, String namespace, Stri
}

String podName = waitForRunningPodWithEnvVar(kubernetes, namespace, firstSelector, envVars);
portForward(podName);
portForward(podName, namespace);
}
}

Expand Down Expand Up @@ -235,9 +235,9 @@ private boolean podHasEnvVarValue(Pod pod, String envVarName, String envVarValue
}


private void portForward(String podName) throws MojoExecutionException {
private void portForward(String podName, String namespace) throws MojoExecutionException {
try {
portForwardService.forwardPort(createExternalProcessLogger("[[B]]port-forward[[B]] "), podName, portToInt(remoteDebugPort, "remoteDebugPort"), portToInt(localDebugPort, "localDebugPort"));
portForwardService.forwardPort(createExternalProcessLogger("[[B]]port-forward[[B]] "), podName, namespace, portToInt(remoteDebugPort, "remoteDebugPort"), portToInt(localDebugPort, "localDebugPort"));

log.info("");
log.info("Now you can start a Remote debug execution in your IDE by using localhost and the debug port " + localDebugPort);
Expand Down

0 comments on commit d021430

Please sign in to comment.