Skip to content

Commit

Permalink
Enable java debugging support (vscode-kubernetes-tools#72)
Browse files Browse the repository at this point in the history
* Enable java debugging support

Signed-off-by: Jinbo Wang <[email protected]>

* Return undefined for readable

* Avoid to let user to pick up the debugger type twice
  • Loading branch information
testforstephen authored Mar 9, 2018
1 parent 9ecdcf5 commit 2791ab7
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 14 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ Where `<your-image-prefix-here>` is something like `docker.io/brendanburns`.
* `Kubernetes: Run` - Run the current application as a Kubernetes Deployment
* `Kubernetes: Terminal` - Open an interactive terminal session in a pod of the Kubernetes Deployment
* `Kubernetes: Exec` - Run a command in a pod of the Kubernetes Deployment
* `Kubernetes: Debug` - Run the current application as a Kubernetes Deployment and attach a debugging session to it (currently works only for Node.js deployments)
* `Kubernetes: Remove Debug` - Remove the deployment and/or service created for a `Kubernetes Debug` session
* `Kubernetes: Debug (Launch)` - Run the current application as a Kubernetes Deployment and attach a debugging session to it (currently works only for Java/Node.js deployments)
* `Kubernetes: Debug (Attach)` - Attach a debugging session to an existing Kubernetes Deployment (currently works only for Java deployments)
* `Kubernetes: Remove Debug` - Remove the deployment and/or service created for a `Kubernetes Debug (Launch)` session

### Configuration commands

Expand Down
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@
"group": "1@3",
"when": "view == extension.vsKubernetesExplorer && viewItem == vsKubernetes.resource.pod"
},
{
"command": "extension.vsKubernetesDebugAttach",
"group": "1@4",
"when": "view == extension.vsKubernetesExplorer && viewItem == vsKubernetes.resource.pod"
},
{
"command": "extension.vsKubernetesDescribe",
"group": "2",
Expand Down Expand Up @@ -317,7 +322,12 @@
},
{
"command": "extension.vsKubernetesDebug",
"title": "Debug",
"title": "Debug (Launch)",
"category": "Kubernetes"
},
{
"command": "extension.vsKubernetesDebugAttach",
"title": "Debug (Attach)",
"category": "Kubernetes"
},
{
Expand Down
11 changes: 8 additions & 3 deletions src/debug/debugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface ProxyResult {
}

export interface IDebugSession {
launch(workspaceFolder: vscode.WorkspaceFolder): Promise<void>;
launch(workspaceFolder: vscode.WorkspaceFolder, debugProvider?: IDebugProvider): Promise<void>;
attach(workspaceFolder: vscode.WorkspaceFolder, pod?: string): Promise<void>;
}

Expand All @@ -40,8 +40,9 @@ export class DebugSession implements IDebugSession {
* Besides, when the debug session is terminated, kill the port-forward and cleanup the created kubernetes resources (deployment/pod) automatically.
*
* @param workspaceFolder the active workspace folder.
* @param debugProvider the debug provider. If not specified, prompt user to pick up a debug provider from the supported list.
*/
public async launch(workspaceFolder: vscode.WorkspaceFolder): Promise<void> {
public async launch(workspaceFolder: vscode.WorkspaceFolder, debugProvider?: IDebugProvider): Promise<void> {
if (!workspaceFolder) {
return;
}
Expand All @@ -52,7 +53,11 @@ export class DebugSession implements IDebugSession {
return;
}
const dockerfile = new DockerfileParser().parse(dockerfilePath);
this.debugProvider = await this.pickupAndInstallDebugProvider(dockerfile.getBaseImage());
if (debugProvider) {
this.debugProvider = (await debugProvider.isDebuggerInstalled())? debugProvider : null;
} else {
this.debugProvider = await this.pickupAndInstallDebugProvider(dockerfile.getBaseImage());
}
if (!this.debugProvider) {
return;
}
Expand Down
14 changes: 8 additions & 6 deletions src/debug/providerRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ const supportedProviders: IDebugProvider[] = [
];

async function showProviderPick(): Promise<IDebugProvider> {
if (supportedProviders.length < 1) {
return null;
} else if (supportedProviders.length === 1) {
return supportedProviders[0];
}

const providerItems = supportedProviders.map((provider) => {
return {
label: provider.getDebuggerType(),
Expand All @@ -39,3 +33,11 @@ export async function getDebugProvider(baseImage?: string): Promise<IDebugProvid
}
return debugProvider;
}

export function getSupportedDebuggerTypes(): string[] {
return supportedProviders.map((provider) => provider.getDebuggerType());
}

export function getDebugProviderOfType(debuggerType: string): IDebugProvider {
return supportedProviders.find((debugProvider) => debugProvider.getDebuggerType() === debuggerType);
}
43 changes: 41 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import { HelmTemplateCompletionProvider } from './helm.completionProvider';
import { Reporter } from './telemetry';
import * as telemetry from './telemetry-helper';
import {dashboardKubernetes} from './components/kubectl/proxy';
import { DebugSession } from './debug/debugSession';
import { getDebugProviderOfType, getSupportedDebuggerTypes } from './debug/providerRegistry';

import { registerYamlSchemaSupport } from './yaml-support/yaml-schema';

Expand Down Expand Up @@ -105,6 +107,7 @@ export async function activate(context) {
registerCommand('extension.vsKubernetesScale', scaleKubernetes),
registerCommand('extension.vsKubernetesDebug', debugKubernetes),
registerCommand('extension.vsKubernetesRemoveDebug', removeDebugKubernetes),
registerCommand('extension.vsKubernetesDebugAttach', debugAttachKubernetes),
registerCommand('extension.vsKubernetesConfigureFromCluster', configureFromClusterKubernetes),
registerCommand('extension.vsKubernetesCreateCluster', createClusterKubernetes),
registerCommand('extension.vsKubernetesRefreshExplorer', () => treeProvider.refresh()),
Expand Down Expand Up @@ -1197,8 +1200,44 @@ const diffKubernetes = (callback) => {
});
};

const debugKubernetes = () => {
buildPushThenExec(_debugInternal);
async function showWorkspaceFolderPick(): Promise<vscode.WorkspaceFolder> {
if (!vscode.workspace.workspaceFolders) {
vscode.window.showErrorMessage('This command requires an open folder.');
return undefined;
} else if (vscode.workspace.workspaceFolders.length === 1) {
return vscode.workspace.workspaceFolders[0];
}
return await vscode.window.showWorkspaceFolderPick();
}

const debugKubernetes = async () => {
const workspaceFolder = await showWorkspaceFolderPick();
if (workspaceFolder) {
const legacySupportedDebuggers = ["node"]; // legacy code support node debugging.
const providerSupportedDebuggers = getSupportedDebuggerTypes();
const supportedDebuggers = providerSupportedDebuggers.concat(legacySupportedDebuggers);
const debuggerType = await vscode.window.showQuickPick(supportedDebuggers, {
placeHolder: "Select the environment"
});

if (!debuggerType) {
return;
}

const debugProvider = getDebugProviderOfType(debuggerType);
if (debugProvider) {
new DebugSession(kubectl).launch(vscode.workspace.workspaceFolders[0], debugProvider);
} else {
buildPushThenExec(_debugInternal);
}
}
};

const debugAttachKubernetes = async (explorerNode: explorer.KubernetesObject) => {
const workspaceFolder = await showWorkspaceFolderPick();
if (workspaceFolder) {
new DebugSession(kubectl).attach(workspaceFolder, explorerNode ? explorerNode.id : null);
}
};

const _debugInternal = (name, image) => {
Expand Down

0 comments on commit 2791ab7

Please sign in to comment.