Skip to content

Commit 0d6dfaa

Browse files
Add, delete and update support on helm repo (#3617)
* add helm tree node Signed-off-by: msivasubramaniaan <msivasub@redhat.com> * add,delete,update and sync functionalities were added Signed-off-by: msivasubramaniaan <msivasub@redhat.com> * added context menu for add,edit and delete Signed-off-by: msivasubramaniaan <msivasub@redhat.com> * rebase Signed-off-by: msivasubramaniaan <msivasub@redhat.com> --------- Signed-off-by: msivasubramaniaan <msivasub@redhat.com>
1 parent 720b650 commit 0d6dfaa

26 files changed

+1661
-108
lines changed

build/esbuild.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const webviews = [
1414
'create-component',
1515
'devfile-registry',
1616
'helm-chart',
17+
'helm-manage-repository',
1718
'welcome',
1819
'feedback',
1920
'serverless-function',

package.json

Lines changed: 87 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@
242242
"onCommand:clusters.openshift.deployment.openConsole",
243243
"onCommand:clusters.openshift.imagestream.openConsole",
244244
"onCommand:openshift.componentTypesView.registry.openInView",
245-
"onCommand:openshift.componentTypesView.registry.openHelmChartsInView",
245+
"onCommand:openshift.helm.openView",
246246
"onCommand:openshift.component.deleteConfigurationFiles",
247247
"onCommand:openshift.component.deleteSourceFolder",
248248
"onWalkthrough:openshiftWalkthrough",
@@ -364,20 +364,45 @@
364364
"category": "OpenShift"
365365
},
366366
{
367-
"command": "openshift.componentTypesView.registry.openHelmChartsInView",
368-
"title": "Open Helm Charts",
367+
"command": "openshift.helm.openView",
368+
"title": "Open Helm View",
369369
"category": "OpenShift"
370370
},
371371
{
372-
"command": "openshift.componentTypesView.registry.helmChart.install",
373-
"title": "Open Helm Charts",
372+
"command": "openshift.helm.install",
373+
"title": "Install",
374374
"category": "OpenShift"
375375
},
376376
{
377-
"command": "openshift.componentTypesView.registry.helmChart.open",
377+
"command": "openshift.helm.manageRepository",
378+
"title": "Manage Repositories",
379+
"category": "OpenShift"
380+
},
381+
{
382+
"command": "openshift.helm.open",
378383
"title": "Open Helm Charts",
379384
"category": "OpenShift"
380385
},
386+
{
387+
"command": "openshift.helm.add",
388+
"title": "Add repository",
389+
"category": "OpenShift"
390+
},
391+
{
392+
"command": "openshift.helm.edit",
393+
"title": "Edit repository",
394+
"category": "OpenShift"
395+
},
396+
{
397+
"command": "openshift.helm.delete",
398+
"title": "Delete repository",
399+
"category": "OpenShift"
400+
},
401+
{
402+
"command": "openshift.helm.sync",
403+
"title": "Sync repository",
404+
"category": "OpenShift"
405+
},
381406
{
382407
"command": "openshift.project.delete",
383408
"title": "Delete",
@@ -1171,15 +1196,35 @@
11711196
"when": "false"
11721197
},
11731198
{
1174-
"command": "openshift.componentTypesView.registry.openHelmChartsInView",
1199+
"command": "openshift.helm.manageRepository",
1200+
"when": "false"
1201+
},
1202+
{
1203+
"command": "openshift.helm.openView",
1204+
"when": "false"
1205+
},
1206+
{
1207+
"command": "openshift.helm.install",
1208+
"when": "false"
1209+
},
1210+
{
1211+
"command": "openshift.helm.add",
1212+
"when": "false"
1213+
},
1214+
{
1215+
"command": "openshift.helm.open",
1216+
"when": "false"
1217+
},
1218+
{
1219+
"command": "openshift.helm.edit",
11751220
"when": "false"
11761221
},
11771222
{
1178-
"command": "openshift.componentTypesView.registry.helmChart.install",
1223+
"command": "openshift.helm.delete",
11791224
"when": "false"
11801225
},
11811226
{
1182-
"command": "openshift.componentTypesView.registry.helmChart.open",
1227+
"command": "openshift.helm.sync",
11831228
"when": "false"
11841229
},
11851230
{
@@ -1434,7 +1479,7 @@
14341479
],
14351480
"view/item/context/createService": [
14361481
{
1437-
"command": "openshift.componentTypesView.registry.openHelmChartsInView",
1482+
"command": "openshift.helm.openView",
14381483
"when": "view == openshiftProjectExplorer && viewItem == openshift.k8sContext && isLoggedIn",
14391484
"group": "c2"
14401485
},
@@ -1751,6 +1796,36 @@
17511796
"command": "openshift.component.commands.command.run",
17521797
"when": "view == openshiftComponentsView && viewItem =~ /openshift\\-component-command.*\\.dev-run.*/",
17531798
"group": "inline"
1799+
},
1800+
{
1801+
"command": "openshift.helm.add",
1802+
"when": "view == openshiftProjectExplorer && viewItem == openshift.helm.repos",
1803+
"group": "c1"
1804+
},
1805+
{
1806+
"command": "openshift.helm.manageRepository",
1807+
"when": "view == openshiftProjectExplorer && viewItem == openshift.helm.repos",
1808+
"group": "c2"
1809+
},
1810+
{
1811+
"command": "openshift.helm.openView",
1812+
"when": "view == openshiftProjectExplorer && viewItem == openshift.helm.repos",
1813+
"group": "c3"
1814+
},
1815+
{
1816+
"command": "openshift.helm.edit",
1817+
"when": "view == openshiftProjectExplorer && viewItem == openshift.helm.repo",
1818+
"group": "c1"
1819+
},
1820+
{
1821+
"command": "openshift.helm.delete",
1822+
"when": "view == openshiftProjectExplorer && viewItem == openshift.helm.repo",
1823+
"group": "c2"
1824+
},
1825+
{
1826+
"command": "openshift.helm.sync",
1827+
"when": "view == openshiftProjectExplorer && viewItem == openshift.helm.repo",
1828+
"group": "c3"
17541829
}
17551830
]
17561831
},
@@ -1808,13 +1883,13 @@
18081883
{
18091884
"id": "helmChart",
18101885
"title": "Work with Helm Charts",
1811-
"description": "Browse the catalog to discover and install Helm Charts.\n[Browse Helm Chart](command:openshift.componentTypesView.registry.openHelmChartsInView)",
1886+
"description": "Browse the catalog to discover and install Helm Charts.\n[Browse Helm Chart](command:openshift.helm.openView)",
18121887
"media": {
18131888
"image": "images/walkthrough/helm.gif",
18141889
"altText": "helm chart"
18151890
},
18161891
"completionEvents": [
1817-
"onCommand:openshift.componentTypesView.registry.openHelmChartsInView"
1892+
"onCommand:openshift.helm.openView"
18181893
]
18191894
},
18201895
{

src/explorer.ts

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,20 @@ import { Progress } from './util/progress';
3131
import { FileContentChangeNotifier, WatchUtil } from './util/watch';
3232
import { vsCommand } from './vscommand';
3333
import { CustomResourceDefinitionStub } from './webview/common/createServiceTypes';
34+
import { HelmRepo } from './helm/helmChartType';
3435

35-
type ExplorerItem = KubernetesObject | Helm.HelmRelease | Context | TreeItem;
36+
type ExplorerItem = KubernetesObject | Helm.HelmRelease | Context | TreeItem | OpenShiftObject | HelmRepo;
37+
38+
export type OpenShiftObject = {
39+
kind: string,
40+
metadata: {
41+
name: string
42+
},
43+
}
3644

3745
type PackageJSON = {
38-
version: string;
39-
bugs: string;
46+
version: string;
47+
bugs: string;
4048
};
4149

4250
const CREATE_OR_SET_PROJECT_ITEM = {
@@ -108,8 +116,8 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
108116
return element;
109117
}
110118

111-
if('label' in element) {
112-
return {
119+
if ('label' in element) {
120+
return {
113121
contextValue: 'openshift.openConfigFile',
114122
label: element.label,
115123
collapsibleState: TreeItemCollapsibleState.None,
@@ -122,14 +130,24 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
122130
// check if element is Context instance
123131
if ('name' in element && 'cluster' in element && 'user' in element) { // Context instance could be without namespace
124132
void commands.executeCommand('setContext', 'isLoggedIn', true);
125-
return {
133+
return {
126134
contextValue: 'openshift.k8sContext',
127135
label: this.kubeConfig.getCluster(element.cluster).server,
128136
collapsibleState: TreeItemCollapsibleState.Collapsed,
129137
iconPath: path.resolve(__dirname, '../../images/context/cluster-node.png')
130138
};
131139
}
132140

141+
if ('name' in element && 'url' in element) {
142+
return {
143+
contextValue: 'openshift.helm.repo',
144+
label: element.name,
145+
tooltip: element.url,
146+
collapsibleState: TreeItemCollapsibleState.None,
147+
iconPath: new ThemeIcon('repo')
148+
};
149+
}
150+
133151
// It's a Helm installation
134152
if ('chart' in element) {
135153
return {
@@ -150,6 +168,14 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
150168
collapsibleState: TreeItemCollapsibleState.Collapsed,
151169
iconPath: path.resolve(__dirname, '../../images/context/project-node.png')
152170
}
171+
} else if (element.kind === 'helm') {
172+
return {
173+
contextValue: 'openshift.helm.repos',
174+
label: element.metadata.name,
175+
collapsibleState: TreeItemCollapsibleState.Collapsed,
176+
description: 'Repositories',
177+
iconPath: path.resolve(__dirname, '../../images/context/helm.png')
178+
}
153179
}
154180
return {
155181
contextValue: 'openshift.k8sObject',
@@ -181,7 +207,7 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
181207
const config = getKubeConfigFiles();
182208
const canCreateNamespace = await Oc.Instance.canCreateNamespace();
183209
void commands.executeCommand('setContext', 'canCreateNamespace', canCreateNamespace);
184-
result.unshift({label: process.env.KUBECONFIG ? 'Custom KubeConfig' : 'Default KubeConfig', description: config.join(':')})
210+
result.unshift({ label: process.env.KUBECONFIG ? 'Custom KubeConfig' : 'Default KubeConfig', description: config.join(':') })
185211
}
186212
} catch (err) {
187213
// ignore because ether server is not accessible or user is logged out
@@ -198,6 +224,12 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
198224
// (3) there is namespace set in context and namespace exists in the cluster
199225
// (4) there is namespace set in context and namespace does not exist in the cluster
200226
const namespaces = await Odo.Instance.getProjects();
227+
const helmContext = {
228+
kind: 'helm',
229+
metadata: {
230+
name: 'Helm'
231+
},
232+
} as OpenShiftObject
201233
if (this.kubeContext.namespace) {
202234
if (namespaces.find(item => item.name === this.kubeContext.namespace)) {
203235
result = [{
@@ -226,8 +258,16 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
226258
result = [CREATE_OR_SET_PROJECT_ITEM]
227259
}
228260
}
261+
result.push(helmContext);
262+
} else if ('kind' in element && element.kind === 'helm') {
263+
const cliData = await Helm.getHelmRepos();
264+
if (!cliData.error && !cliData.stderr) {
265+
const helmRepos = JSON.parse(cliData.stdout) as HelmRepo[];
266+
if (helmRepos?.length > 0) {
267+
result = [...helmRepos.sort(Helm.ascRepoName)];
268+
}
269+
}
229270
} else {
230-
231271
let serviceKinds: CustomResourceDefinitionStub[] = [];
232272
try {
233273
serviceKinds = await getServiceKindStubs();
@@ -249,6 +289,7 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
249289
result = await Promise.all(toCollect).then(listOfLists => listOfLists.flatMap(a => a as ExplorerItem[]));
250290

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

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

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

286327
@vsCommand('openshift.resource.openInConsole')
287328
public static openInConsole(component: KubernetesObject) {
288-
void commands.executeCommand('extension.vsKubernetesLoad', {namespace: component.metadata.namespace, kindName: `${component.kind}/${component.metadata.name}`});
329+
void commands.executeCommand('extension.vsKubernetesLoad', { namespace: component.metadata.namespace, kindName: `${component.kind}/${component.metadata.name}` });
289330
}
290331

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

302343
@vsCommand('openshift.open.configFile')
303344
async openConfigFile(context: TreeItem): Promise<void> {
304-
if(context.description && typeof context.description === 'string'){
345+
if (context.description && typeof context.description === 'string') {
305346
await commands.executeCommand('vscode.open', Uri.file(context.description));
306347
}
307348
}

src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export async function activate(extensionContext: ExtensionContext): Promise<unkn
9191
'./componentsView',
9292
'./webview/devfile-registry/registryViewLoader',
9393
'./webview/helm-chart/helmChartLoader',
94+
'./webview/helm-manage-repository/manageRepositoryLoader',
9495
'./feedback'
9596
)),
9697
commands.registerCommand('clusters.openshift.useProject', (context) =>

0 commit comments

Comments
 (0)