Skip to content

Commit

Permalink
Add Delete now to Pod context menu (vscode-kubernetes-tools#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
ubikusss authored and itowlson committed Aug 5, 2018
1 parent b62b9ea commit c82492b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
19 changes: 15 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"activationEvents": [
"onCommand:extension.vsKubernetesCreate",
"onCommand:extension.vsKubernetesDelete",
"onCommand:extension.vsKubernetesDeleteNow",
"onCommand:extension.vsKubernetesApply",
"onCommand:extension.vsKubernetesExplain",
"onCommand:extension.vsKubernetesLoad",
Expand Down Expand Up @@ -334,20 +335,25 @@
"when": "view == extension.vsKubernetesExplorer && viewItem == vsKubernetes.resource.pod"
},
{
"command": "extension.vsKubernetesTerminal",
"command": "extension.vsKubernetesDeleteNow",
"group": "2@3",
"when": "view == extension.vsKubernetesExplorer && viewItem == vsKubernetes.resource.pod"
},
{
"command": "extension.vsKubernetesDebugAttach",
"command": "extension.vsKubernetesTerminal",
"group": "2@4",
"when": "view == extension.vsKubernetesExplorer && viewItem == vsKubernetes.resource.pod"
},
{
"command": "extension.vsKubernetesPortForward",
"command": "extension.vsKubernetesDebugAttach",
"group": "2@5",
"when": "view == extension.vsKubernetesExplorer && viewItem == vsKubernetes.resource.pod"
},
{
"command": "extension.vsKubernetesPortForward",
"group": "2@6",
"when": "view == extension.vsKubernetesExplorer && viewItem == vsKubernetes.resource.pod"
},
{
"command": "extension.vsKubernetesDescribe",
"group": "3",
Expand Down Expand Up @@ -487,6 +493,11 @@
"title": "Delete",
"category": "Kubernetes"
},
{
"command": "extension.vsKubernetesDeleteNow",
"title": "Delete Now",
"category": "Kubernetes"
},
{
"command": "extension.vsKubernetesApply",
"title": "Apply",
Expand Down Expand Up @@ -943,4 +954,4 @@
"type": "git",
"url": "https://github.com/Azure/vscode-kubernetes-tools"
}
}
}
21 changes: 15 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ export async function activate(context): Promise<extensionapi.ExtensionAPI> {
registerCommand('extension.vsKubernetesCreate',
maybeRunKubernetesCommandForActiveWindow.bind(this, 'create', "Kubernetes Creating...")
),
registerCommand('extension.vsKubernetesDelete', deleteKubernetes),
registerCommand('extension.vsKubernetesDelete', (explorerNode: explorer.ResourceNode) => { deleteKubernetes(KubernetesDeleteMode.Graceful, explorerNode); }),
registerCommand('extension.vsKubernetesDeleteNow', (explorerNode: explorer.ResourceNode) => { deleteKubernetes(KubernetesDeleteMode.Now, explorerNode); }),
registerCommand('extension.vsKubernetesApply', applyKubernetes),
registerCommand('extension.vsKubernetesExplain', explainActiveWindow),
registerCommand('extension.vsKubernetesLoad', loadKubernetes),
Expand Down Expand Up @@ -1276,14 +1277,17 @@ async function reportDeleteResult(resourceId: string, shellResult: ShellResult)
refreshExplorer();
}

const deleteKubernetes = async (explorerNode?: explorer.ResourceNode) => {
async function deleteKubernetes(delMode: KubernetesDeleteMode, explorerNode?: explorer.ResourceNode) {

const delModeArg = delMode === KubernetesDeleteMode.Now ? ' --now' : '';

if (explorerNode) {
const answer = await vscode.window.showWarningMessage(`Do you want to delete the resource '${explorerNode.resourceId}'?`, ...deleteMessageItems);
if (answer.isCloseAffordance) {
return;
}
const nsarg = explorerNode.namespace ? `--namespace ${explorerNode.namespace}` : '';
const shellResult = await kubectl.invokeAsyncWithProgress(`delete ${explorerNode.resourceId} ${nsarg}`, `Deleting ${explorerNode.resourceId}...`);
const shellResult = await kubectl.invokeAsyncWithProgress(`delete ${explorerNode.resourceId} ${nsarg} ${delModeArg}`, `Deleting ${explorerNode.resourceId}...`);
await reportDeleteResult(explorerNode.resourceId, shellResult);
} else {
promptKindName(kuberesources.commonKinds, 'delete', { nameOptional: true }, async (kindName) => {
Expand All @@ -1292,12 +1296,17 @@ const deleteKubernetes = async (explorerNode?: explorer.ResourceNode) => {
if (!containsName(kindName)) {
commandArgs = kindName + " --all";
}
const shellResult = await kubectl.invokeAsyncWithProgress(`delete ${commandArgs}`, `Deleting ${kindName}...`);
const shellResult = await kubectl.invokeAsyncWithProgress(`delete ${commandArgs} ${delModeArg}`, `Deleting ${kindName}...`);
await reportDeleteResult(kindName, shellResult);
}
});
}
};
}

enum KubernetesDeleteMode {
Graceful,
Now
}

enum DiffResultKind {
Succeeded,
Expand Down Expand Up @@ -1815,4 +1824,4 @@ async function execDraftUp() {
function editorIsActive(): boolean {
// force type coercion
return (vscode.window.activeTextEditor) ? true : false;
}
}

0 comments on commit c82492b

Please sign in to comment.