Skip to content

Commit

Permalink
Helm repo explorer context menu (vscode-kubernetes-tools#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
itowlson authored Aug 5, 2018
1 parent c82492b commit 784c4d3
Show file tree
Hide file tree
Showing 6 changed files with 366 additions and 40 deletions.
86 changes: 86 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@
"onCommand:extension.helmCreate",
"onCommand:extension.helmInsertReq",
"onCommand:extension.helmDepUp",
"onCommand:extension.helmInspectChart",
"onCommand:extension.helmInspectValues",
"onCommand:extension.helmGet",
"onCommand:extension.helmPackage",
"onCommand:extension.helmFetch",
"onCommand:extension.helmInstall",
"onCommand:extension.helmDependencies",
"onCommand:extension.draftVersion",
"onCommand:extension.draftCreate",
"onCommand:extension.draftUp",
Expand Down Expand Up @@ -433,6 +437,56 @@
"command": "extension.vsKubernetesDeleteFile",
"group": "3",
"when": "view == extension.vsKubernetesExplorer && viewItem == vsKubernetes.file"
},
{
"command": "extension.helmFetch",
"group": "1",
"when": "view == extension.vsKubernetesHelmRepoExplorer && viewItem == vsKubernetes.chart"
},
{
"command": "extension.helmFetch",
"group": "1",
"when": "view == extension.vsKubernetesHelmRepoExplorer && viewItem == vsKubernetes.chartversion"
},
{
"command": "extension.helmInstall",
"group": "2",
"when": "view == extension.vsKubernetesHelmRepoExplorer && viewItem == vsKubernetes.chart"
},
{
"command": "extension.helmInstall",
"group": "2",
"when": "view == extension.vsKubernetesHelmRepoExplorer && viewItem == vsKubernetes.chartversion"
},
{
"command": "extension.helmDependencies",
"group": "0@3",
"when": "view == extension.vsKubernetesHelmRepoExplorer && viewItem == vsKubernetes.chart"
},
{
"command": "extension.helmDependencies",
"group": "0@3",
"when": "view == extension.vsKubernetesHelmRepoExplorer && viewItem == vsKubernetes.chartversion"
},
{
"command": "extension.helmInspectChart",
"group": "0@1",
"when": "view == extension.vsKubernetesHelmRepoExplorer && viewItem == vsKubernetes.chart"
},
{
"command": "extension.helmInspectChart",
"group": "0@1",
"when": "view == extension.vsKubernetesHelmRepoExplorer && viewItem == vsKubernetes.chartversion"
},
{
"command": "extension.helmInspectValues",
"group": "0@2",
"when": "view == extension.vsKubernetesHelmRepoExplorer && viewItem == vsKubernetes.chart"
},
{
"command": "extension.helmInspectValues",
"group": "0@2",
"when": "view == extension.vsKubernetesHelmRepoExplorer && viewItem == vsKubernetes.chartversion"
}
],
"commandPalette": [
Expand Down Expand Up @@ -479,6 +533,14 @@
{
"command": "extension.helmInspectValues",
"when": "filesExplorerFocus"
},
{
"command": "extension.helmInspectValues",
"when": "view === extension.vsKubernetesHelmRepoExplorer"
},
{
"command": "extension.helmInspectChart",
"when": "view === extension.vsKubernetesHelmRepoExplorer"
}
]
},
Expand Down Expand Up @@ -738,6 +800,12 @@
},
{
"command": "extension.helmInspectValues",
"title": "Inspect Values",
"description": "Inspect a Helm Chart",
"category": "Helm"
},
{
"command": "extension.helmInspectChart",
"title": "Inspect Chart",
"description": "Inspect a Helm Chart",
"category": "Helm"
Expand All @@ -759,6 +827,24 @@
"title": "Package",
"description": "Package a chart directory into a versioned chart archive file.",
"category": "Helm"
},
{
"command": "extension.helmFetch",
"title": "Fetch",
"description": "Fetch a Helm chart into the current project",
"category": "Helm"
},
{
"command": "extension.helmInstall",
"title": "Install",
"description": "Install a Helm chart into the cluster",
"category": "Helm"
},
{
"command": "extension.helmDependencies",
"title": "Show Dependencies",
"description": "List the dependencies of a Helm chart",
"category": "Helm"
}
],
"languages": [
Expand Down
10 changes: 8 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import * as helm from './helm';
import * as helmexec from './helm.exec';
import { HelmRequirementsCodeLensProvider } from './helm.requirementsCodeLens';
import { HelmTemplateHoverProvider } from './helm.hoverProvider';
import { HelmTemplatePreviewDocumentProvider, HelmInspectDocumentProvider } from './helm.documentProvider';
import { HelmTemplatePreviewDocumentProvider, HelmInspectDocumentProvider, HelmDependencyDocumentProvider } from './helm.documentProvider';
import { HelmTemplateCompletionProvider } from './helm.completionProvider';
import { Reporter } from './telemetry';
import * as telemetry from './telemetry-helper';
Expand Down Expand Up @@ -115,6 +115,7 @@ export async function activate(context): Promise<extensionapi.ExtensionAPI> {
const resourceDocProvider = new KubernetesResourceVirtualFileSystemProvider(kubectl, host, vscode.workspace.rootPath);
const previewProvider = new HelmTemplatePreviewDocumentProvider();
const inspectProvider = new HelmInspectDocumentProvider();
const dependenciesProvider = new HelmDependencyDocumentProvider();
const completionProvider = new HelmTemplateCompletionProvider();
const completionFilter = [
"helm",
Expand Down Expand Up @@ -173,12 +174,16 @@ export async function activate(context): Promise<extensionapi.ExtensionAPI> {
registerCommand('extension.helmTemplatePreview', helmexec.helmTemplatePreview),
registerCommand('extension.helmLint', helmexec.helmLint),
registerCommand('extension.helmInspectValues', helmexec.helmInspectValues),
registerCommand('extension.helmInspectChart', helmexec.helmInspectChart),
registerCommand('extension.helmDryRun', helmexec.helmDryRun),
registerCommand('extension.helmDepUp', helmexec.helmDepUp),
registerCommand('extension.helmInsertReq', helmexec.insertRequirement),
registerCommand('extension.helmCreate', helmexec.helmCreate),
registerCommand('extension.helmGet', helmexec.helmGet),
registerCommand('extension.helmPackage', helmexec.helmPackage),
registerCommand('extension.helmFetch', helmexec.helmFetch),
registerCommand('extension.helmInstall', (o) => helmexec.helmInstall(kubectl, o)),
registerCommand('extension.helmDependencies', helmexec.helmDependencies),

// Commands - Draft
registerCommand('extension.draftVersion', execDraftVersion),
Expand All @@ -192,8 +197,9 @@ export async function activate(context): Promise<extensionapi.ExtensionAPI> {
vscode.workspace.registerTextDocumentContentProvider(configureFromCluster.uriScheme, configureFromClusterUI),
vscode.workspace.registerTextDocumentContentProvider(createCluster.uriScheme, createClusterUI),
vscode.workspace.registerTextDocumentContentProvider(helm.PREVIEW_SCHEME, previewProvider),
vscode.workspace.registerTextDocumentContentProvider(helm.INSPECT_SCHEME, inspectProvider),
vscode.workspace.registerTextDocumentContentProvider(helm.INSPECT_VALUES_SCHEME, inspectProvider),
vscode.workspace.registerTextDocumentContentProvider(helm.INSPECT_CHART_SCHEME, inspectProvider),
vscode.workspace.registerTextDocumentContentProvider(helm.DEPENDENCIES_SCHEME, dependenciesProvider),

// Completion providers
vscode.languages.registerCompletionItemProvider(completionFilter, completionProvider),
Expand Down
55 changes: 47 additions & 8 deletions src/helm.documentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { escape as htmlEscape } from 'lodash';

import * as helm from './helm';
import * as logger from './logger';
import { failed } from './errorable';

interface HelmDocumentResult {
readonly title: string;
Expand All @@ -32,13 +33,16 @@ function render(document: HelmDocumentResult): string {
}

function extractChartName(uri: vscode.Uri): string {
if (uri.scheme === helm.INSPECT_CHART_SCHEME && uri.authority === helm.INSPECT_CHART_REPO_AUTHORITY) {
if (uri.authority === helm.INSPECT_REPO_AUTHORITY) {
const id = uri.path.substring(1);
const version = uri.query;
return `${id} ${version}`;
}
if (filepath.extname(uri.fsPath) === ".tgz") {
return filepath.basename(uri.fsPath);
if (uri.authority === helm.INSPECT_FILE_AUTHORITY) {
const fsPath = uri.query;
if (filepath.extname(fsPath) === ".tgz") {
return filepath.basename(fsPath);
}
}
return "Chart";
}
Expand All @@ -57,8 +61,9 @@ export class HelmInspectDocumentProvider implements vscode.TextDocumentContentPr
reject(err);
};

if (uri.scheme === helm.INSPECT_SCHEME) {
const file = uri.fsPath || uri.authority;
if (uri.authority === helm.INSPECT_FILE_AUTHORITY) {
// currently always INSPECT_VALUES_SCHEME
const file = uri.query;
const fi = fs.statSync(file);
if (!fi.isDirectory() && filepath.extname(file) === ".tgz") {
exec.helmExec(`inspect values "${file}"`, printer);
Expand All @@ -70,10 +75,15 @@ export class HelmInspectDocumentProvider implements vscode.TextDocumentContentPr
exec.pickChartForFile(file, { warnIfNoCharts: true }, (path) => {
exec.helmExec(`inspect values "${path}"`, printer);
});
} else if (uri.scheme === helm.INSPECT_CHART_SCHEME && uri.authority === helm.INSPECT_CHART_REPO_AUTHORITY) {
} else if (uri.authority === helm.INSPECT_REPO_AUTHORITY) {
const id = uri.path.substring(1);
const version = uri.query;
exec.helmExec(`inspect ${id} --version ${version}`, printer);
const versionArg = version ? `--version ${version}` : '';
if (uri.scheme === helm.INSPECT_CHART_SCHEME) {
exec.helmExec(`inspect ${id} ${versionArg}`, printer);
} else if (uri.scheme === helm.INSPECT_VALUES_SCHEME) {
exec.helmExec(`inspect values ${id} ${versionArg}`, printer);
}
}
});

Expand Down Expand Up @@ -134,4 +144,33 @@ export class HelmTemplatePreviewDocumentProvider implements vscode.TextDocumentC
});

}
}
}

export class HelmDependencyDocumentProvider implements vscode.TextDocumentContentProvider {
public provideTextDocumentContent(uri: vscode.Uri, tok: vscode.CancellationToken): vscode.ProviderResult<string> {
return this.provideTextDocumentContentImpl(uri);
}

async provideTextDocumentContentImpl(uri: vscode.Uri): Promise<string> {
const chartId = uri.path.substring(1);
const version = uri.query;
const dependencies = await exec.helmDependenciesCore(chartId, version);
if (failed(dependencies)) {
return `<p>${dependencies.error[0]}</p>`;
}

const list = dependencies.result
.map(this.formatDependency)
.join('<br>');
return `<p>${chartId} depends on:</p><ul>${list}</ul>`;
}

formatDependency(d: { [key: string]: string }): string {
const name = d.name;
const version = d.version === '*' ? '' : ` (v${d.version})`;
const repoPrefix = d.repository.startsWith('alias:') ? d.repository.substring('alias:'.length) + '/' : '';
const repoSuffix = d.repository.startsWith('alias:') ? '' : ` from ${d.repository}`;
const status = ` - ${d.status}`;
return `<li>${repoPrefix}${name}${version}${repoSuffix}${status}</li>`;
}
}
Loading

0 comments on commit 784c4d3

Please sign in to comment.