Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const webviews = [
'create-component',
'devfile-registry',
'helm-chart',
'helm-manage-repository',
'welcome',
'feedback',
'serverless-function',
Expand Down
41 changes: 30 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
"onCommand:clusters.openshift.deployment.openConsole",
"onCommand:clusters.openshift.imagestream.openConsole",
"onCommand:openshift.componentTypesView.registry.openInView",
"onCommand:openshift.componentTypesView.registry.openHelmChartsInView",
"onCommand:openshift.helm.openView",
"onCommand:openshift.component.deleteConfigurationFiles",
"onCommand:openshift.component.deleteSourceFolder",
"onWalkthrough:openshiftWalkthrough",
Expand Down Expand Up @@ -364,17 +364,22 @@
"category": "OpenShift"
},
{
"command": "openshift.componentTypesView.registry.openHelmChartsInView",
"title": "Open Helm Charts",
"command": "openshift.helm.openView",
"title": "Open Helm View",
"category": "OpenShift"
},
{
"command": "openshift.componentTypesView.registry.helmChart.install",
"command": "openshift.helm.install",
"title": "Open Helm Charts",
"category": "OpenShift"
},
{
"command": "openshift.componentTypesView.registry.helmChart.open",
"command": "openshift.helm.manageRepository",
"title": "Manage Repositories",
"category": "OpenShift"
},
{
"command": "openshift.helm.open",
"title": "Open Helm Charts",
"category": "OpenShift"
},
Expand Down Expand Up @@ -1171,15 +1176,19 @@
"when": "false"
},
{
"command": "openshift.componentTypesView.registry.openHelmChartsInView",
"command": "openshift.helm.manageRepository",
"when": "false"
},
{
"command": "openshift.helm.openView",
"when": "false"
},
{
"command": "openshift.componentTypesView.registry.helmChart.install",
"command": "openshift.helm.install",
"when": "false"
},
{
"command": "openshift.componentTypesView.registry.helmChart.open",
"command": "openshift.helm.open",
"when": "false"
},
{
Expand Down Expand Up @@ -1434,7 +1443,7 @@
],
"view/item/context/createService": [
{
"command": "openshift.componentTypesView.registry.openHelmChartsInView",
"command": "openshift.helm.openView",
"when": "view == openshiftProjectExplorer && viewItem == openshift.k8sContext && isLoggedIn",
"group": "c2"
},
Expand Down Expand Up @@ -1751,6 +1760,16 @@
"command": "openshift.component.commands.command.run",
"when": "view == openshiftComponentsView && viewItem =~ /openshift\\-component-command.*\\.dev-run.*/",
"group": "inline"
},
{
"command": "openshift.helm.manageRepository",
"when": "view == openshiftProjectExplorer && viewItem == openshift.helm.repos",
"group": "c1"
},
{
"command": "openshift.helm.openView",
"when": "view == openshiftProjectExplorer && viewItem == openshift.helm.repos",
"group": "c2"
}
]
},
Expand Down Expand Up @@ -1808,13 +1827,13 @@
{
"id": "helmChart",
"title": "Work with Helm Charts",
"description": "Browse the catalog to discover and install Helm Charts.\n[Browse Helm Chart](command:openshift.componentTypesView.registry.openHelmChartsInView)",
"description": "Browse the catalog to discover and install Helm Charts.\n[Browse Helm Chart](command:openshift.helm.openView)",
"media": {
"image": "images/walkthrough/helm.gif",
"altText": "helm chart"
},
"completionEvents": [
"onCommand:openshift.componentTypesView.registry.openHelmChartsInView"
"onCommand:openshift.helm.openView"
]
},
{
Expand Down
65 changes: 53 additions & 12 deletions src/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,20 @@ import { Progress } from './util/progress';
import { FileContentChangeNotifier, WatchUtil } from './util/watch';
import { vsCommand } from './vscommand';
import { CustomResourceDefinitionStub } from './webview/common/createServiceTypes';
import { HelmRepo } from './helm/helmChartType';

type ExplorerItem = KubernetesObject | Helm.HelmRelease | Context | TreeItem;
type ExplorerItem = KubernetesObject | Helm.HelmRelease | Context | TreeItem | OpenShiftObject | HelmRepo;

export type OpenShiftObject = {
kind: string,
metadata: {
name: string
},
}

type PackageJSON = {
version: string;
bugs: string;
version: string;
bugs: string;
};

const CREATE_OR_SET_PROJECT_ITEM = {
Expand Down Expand Up @@ -108,8 +116,8 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
return element;
}

if('label' in element) {
return {
if ('label' in element) {
return {
contextValue: 'openshift.openConfigFile',
label: element.label,
collapsibleState: TreeItemCollapsibleState.None,
Expand All @@ -122,14 +130,24 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
// check if element is Context instance
if ('name' in element && 'cluster' in element && 'user' in element) { // Context instance could be without namespace
void commands.executeCommand('setContext', 'isLoggedIn', true);
return {
return {
contextValue: 'openshift.k8sContext',
label: this.kubeConfig.getCluster(element.cluster).server,
collapsibleState: TreeItemCollapsibleState.Collapsed,
iconPath: path.resolve(__dirname, '../../images/context/cluster-node.png')
};
}

if ('name' in element && 'url' in element) {
return {
contextValue: 'openshift.helm.repo',
label: element.name,
tooltip: element.url,
collapsibleState: TreeItemCollapsibleState.None,
iconPath: new ThemeIcon('repo')
};
}

// It's a Helm installation
if ('chart' in element) {
return {
Expand All @@ -150,6 +168,14 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
collapsibleState: TreeItemCollapsibleState.Collapsed,
iconPath: path.resolve(__dirname, '../../images/context/project-node.png')
}
} else if (element.kind === 'helm') {
return {
contextValue: 'openshift.helm.repos',
label: element.metadata.name,
collapsibleState: TreeItemCollapsibleState.Collapsed,
description: 'Repositories',
iconPath: path.resolve(__dirname, '../../images/context/helm.png')
}
}
return {
contextValue: 'openshift.k8sObject',
Expand Down Expand Up @@ -181,7 +207,7 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
const config = getKubeConfigFiles();
const canCreateNamespace = await Oc.Instance.canCreateNamespace();
void commands.executeCommand('setContext', 'canCreateNamespace', canCreateNamespace);
result.unshift({label: process.env.KUBECONFIG ? 'Custom KubeConfig' : 'Default KubeConfig', description: config.join(':')})
result.unshift({ label: process.env.KUBECONFIG ? 'Custom KubeConfig' : 'Default KubeConfig', description: config.join(':') })
}
} catch (err) {
// ignore because ether server is not accessible or user is logged out
Expand All @@ -198,6 +224,12 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
// (3) there is namespace set in context and namespace exists in the cluster
// (4) there is namespace set in context and namespace does not exist in the cluster
const namespaces = await Odo.Instance.getProjects();
const helmContext = {
kind: 'helm',
metadata: {
name: 'Helm'
},
} as OpenShiftObject
if (this.kubeContext.namespace) {
if (namespaces.find(item => item.name === this.kubeContext.namespace)) {
result = [{
Expand Down Expand Up @@ -226,8 +258,16 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
result = [CREATE_OR_SET_PROJECT_ITEM]
}
}
result.push(helmContext);
} else if ('kind' in element && element.kind === 'helm') {
const cliData = await Helm.getHelmRepos();
if (!cliData.error && !cliData.stderr) {
const helmRepos = JSON.parse(cliData.stdout) as HelmRepo[];
if (helmRepos?.length > 0) {
result = [...helmRepos.sort(Helm.ascRepoName)];
}
}
} else {

let serviceKinds: CustomResourceDefinitionStub[] = [];
try {
serviceKinds = await getServiceKindStubs();
Expand All @@ -249,6 +289,7 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
result = await Promise.all(toCollect).then(listOfLists => listOfLists.flatMap(a => a as ExplorerItem[]));

}

// don't show Open In Developer Dashboard if not openshift cluster
const isOpenshiftCluster = await Oc.Instance.isOpenShiftCluster();
void commands.executeCommand('setContext', 'isOpenshiftCluster', isOpenshiftCluster);
Expand All @@ -272,7 +313,7 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos

@vsCommand('openshift.resource.load')
public static loadResource(component: KubernetesObject) {
void commands.executeCommand('extension.vsKubernetesLoad', {namespace: component.metadata.namespace, kindName: `${component.kind}/${component.metadata.name}`});
void commands.executeCommand('extension.vsKubernetesLoad', { namespace: component.metadata.namespace, kindName: `${component.kind}/${component.metadata.name}` });
}

@vsCommand('openshift.resource.unInstall')
Expand All @@ -285,13 +326,13 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos

@vsCommand('openshift.resource.openInConsole')
public static openInConsole(component: KubernetesObject) {
void commands.executeCommand('extension.vsKubernetesLoad', {namespace: component.metadata.namespace, kindName: `${component.kind}/${component.metadata.name}`});
void commands.executeCommand('extension.vsKubernetesLoad', { namespace: component.metadata.namespace, kindName: `${component.kind}/${component.metadata.name}` });
}

@vsCommand('openshift.explorer.reportIssue')
static async reportIssue(): Promise<unknown> {
const extensionPath = path.resolve(__dirname, '..', '..');
const templatePath = path.join(extensionPath,'resources', 'issueReport.md');
const templatePath = path.join(extensionPath, 'resources', 'issueReport.md');
const template = fs.readFileSync(templatePath, 'utf-8');
return commands.executeCommand('workbench.action.openIssueReporter', {
extensionId: 'redhat.vscode-openshift-connector',
Expand All @@ -301,7 +342,7 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos

@vsCommand('openshift.open.configFile')
async openConfigFile(context: TreeItem): Promise<void> {
if(context.description && typeof context.description === 'string'){
if (context.description && typeof context.description === 'string') {
await commands.executeCommand('vscode.open', Uri.file(context.description));
}
}
Expand Down
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export async function activate(extensionContext: ExtensionContext): Promise<unkn
'./componentsView',
'./webview/devfile-registry/registryViewLoader',
'./webview/helm-chart/helmChartLoader',
'./webview/helm-manage-repository/manageRepositoryLoader',
'./feedback'
)),
commands.registerCommand('clusters.openshift.useProject', (context) =>
Expand Down
45 changes: 37 additions & 8 deletions src/helm/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*-----------------------------------------------------------------------------------------------*/
import { CliChannel } from '../cli';
import { CliExitData } from '../util/childProcessUtil';
import { HelmRepo } from './helmChartType';
import * as HelmCommands from './helmCommands';

export type HelmRelease = {
Expand All @@ -22,7 +23,7 @@ export type HelmRelease = {
* @returns a list of all Helm releases in the current namespace on the current cluster
*/
export async function getHelmReleases(): Promise<HelmRelease[]> {
const res = await CliChannel.getInstance().executeTool(HelmCommands.listHelmReleases());
const res = await CliChannel.getInstance().executeTool(HelmCommands.listHelmReleases(), undefined, false);
return JSON.parse(res.stdout) as HelmRelease[];
}

Expand All @@ -31,21 +32,32 @@ export async function getHelmReleases(): Promise<HelmRelease[]> {
*
* @returns the CLI output data from running the necessary command
*/
export async function addHelmRepo(): Promise<CliExitData> {
return await CliChannel.getInstance().executeTool(HelmCommands.addHelmRepo());
export async function addHelmRepo(repoName: string, url: string): Promise<CliExitData> {
return await CliChannel.getInstance().executeTool(HelmCommands.addHelmRepo(repoName, url), undefined, false);
}

/**
* Delete the OpenShift Helm repo to the cluster.
*
* @returns the CLI output data from running the necessary command
*/
export async function deleteHelmRepo(repoName: string): Promise<CliExitData> {
return await CliChannel.getInstance().executeTool(HelmCommands.deleteRepo(repoName), undefined, false);
}

export async function getHelmRepos(): Promise<CliExitData> {
return await CliChannel.getInstance().executeTool(HelmCommands.getRepos());
return await CliChannel.getInstance().executeTool(HelmCommands.getRepos(), undefined, false);
}

/**
* Updates the content of all the Helm repos.
*
* @param repo name
*
* @returns the CLI output data from running the necessary command
*/
export async function updateHelmRepo(): Promise<CliExitData> {
return await CliChannel.getInstance().executeTool(HelmCommands.updateHelmRepo());
export async function updateHelmRepo(renameRepo: string): Promise<CliExitData> {
return await CliChannel.getInstance().executeTool(HelmCommands.updateHelmRepo(renameRepo), undefined, false);
}

/**
Expand All @@ -63,7 +75,7 @@ export async function installHelmChart(
version: string,
): Promise<CliExitData> {
return await CliChannel.getInstance().executeTool(
HelmCommands.installHelmChart(name, repoName, chartName, version),
HelmCommands.installHelmChart(name, repoName, chartName, version), undefined, false
);
}

Expand All @@ -74,5 +86,22 @@ export async function installHelmChart(
* @returns the CLI output data from running the necessary command
*/
export async function unInstallHelmChart(name: string): Promise<CliExitData> {
return await CliChannel.getInstance().executeTool(HelmCommands.unInstallHelmChart(name));
return await CliChannel.getInstance().executeTool(HelmCommands.unInstallHelmChart(name), undefined, false);
}

/**
* sort the repo list.
*
* @param helm repo
* @returns the CLI output data from running the necessary command
*/
export function ascRepoName(oldRepo: HelmRepo, newRepo: HelmRepo) {
const oldURLCheck = oldRepo.url.toLowerCase().includes('charts.openshift.io');
const newURLCheck = newRepo.url.toLowerCase().includes('charts.openshift.io');
if (oldURLCheck && !newURLCheck) {
return -1;
} else if (newURLCheck && !oldURLCheck) {
return 1;
}
return oldRepo.name.localeCompare(newRepo.name);
}
File renamed without changes.
12 changes: 8 additions & 4 deletions src/helm/helmCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@

import { CommandOption, CommandText } from '../base/command';

export function addHelmRepo(): CommandText {
return new CommandText('helm', 'repo add openshift https://charts.openshift.io/');
export function addHelmRepo(repoName: string, url: string): CommandText {
return new CommandText('helm', `repo add ${repoName} ${url}`);
}

export function updateHelmRepo(): CommandText {
return new CommandText('helm', 'repo update');
export function deleteRepo(repoName: string): CommandText {
return new CommandText('helm', `repo remove ${repoName}`);
}

export function updateHelmRepo(repoName: string): CommandText {
return new CommandText('helm', `repo update ${repoName}`);
}

export function getRepos(): CommandText {
Expand Down
Loading