Skip to content

Commit b9cc8ae

Browse files
authored
Import command for components without context (#1117)
1 parent b8a74e7 commit b9cc8ae

File tree

5 files changed

+247
-51
lines changed

5 files changed

+247
-51
lines changed

package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"onCommand:openshift.app.describe",
5353
"onCommand:openshift.app.create",
5454
"onCommand:openshift.app.delete",
55+
"onCommand:openshift.component.import",
5556
"onCommand:openshift.component.create",
5657
"onCommand:openshift.component.createFromLocal",
5758
"onCommand:openshift.component.createFromGit",
@@ -212,6 +213,11 @@
212213
"title": "Delete",
213214
"category": "OpenShift"
214215
},
216+
{
217+
"command": "openshift.component.import",
218+
"title": "Import",
219+
"category": "OpenShift"
220+
},
215221
{
216222
"command": "openshift.component.create",
217223
"title": "New Component",
@@ -525,6 +531,10 @@
525531
"command": "openshift.project.delete",
526532
"when": "view == openshiftProjectExplorer"
527533
},
534+
{
535+
"command": "openshift.component.import",
536+
"when": "view == openshiftProjectExplorer"
537+
},
528538
{
529539
"command": "openshift.component.create",
530540
"when": "view == openshiftProjectExplorer"
@@ -764,6 +774,11 @@
764774
"when": "view == openshiftProjectExplorer && viewItem == component_no_context",
765775
"group": "c2@1"
766776
},
777+
{
778+
"command": "openshift.component.import",
779+
"when": "view == openshiftProjectExplorer && viewItem == component_no_context",
780+
"group": "c2@2"
781+
},
767782
{
768783
"command": "openshift.component.log",
769784
"when": "view == openshiftProjectExplorer && viewItem == component",
@@ -884,6 +899,12 @@
884899
"type": "number",
885900
"default": 0,
886901
"description": "Output verbosity level (value between 0 and 9) for OpenShift Create, Push and Watch commands in output channel and integrated terminal."
902+
},
903+
"openshiftConnector.disableCheckForMigration": {
904+
"title": "Disable check if migration required",
905+
"type": "boolean",
906+
"default": false,
907+
"description": "Dsable check if migration is required for resources created with previous version of the extension and mirgation request message."
887908
}
888909
}
889910
}

src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export async function activate(context: vscode.ExtensionContext) {
5555
vscode.commands.registerCommand('openshift.app.describe', (context) => execute(Application.describe, context)),
5656
vscode.commands.registerCommand('openshift.app.describe.palette', (context) => execute(Application.describe, context)),
5757
vscode.commands.registerCommand('openshift.app.delete', (context) => execute(Application.del, context)),
58+
vscode.commands.registerCommand('openshift.component.import', (context) => execute(Component.import, context)),
5859
vscode.commands.registerCommand('openshift.component.describe', (context) => execute(Component.describe, context)),
5960
vscode.commands.registerCommand('openshift.component.describe.palette', (context) => execute(Component.describe, context)),
6061
vscode.commands.registerCommand('openshift.component.create', (context) => execute(Component.create, context)),

src/odo.ts

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ export enum ContextType {
4949
COMPONENT_ROUTE = 'component_route'
5050
}
5151

52+
export enum ComponentType {
53+
LOCAL = 'local',
54+
GIT = 'git',
55+
BINARY = 'binary'
56+
}
57+
5258
function verbose(_target: any, key: string, descriptor: any) {
5359
let fnKey: string | undefined;
5460
let fn: Function | undefined;
@@ -321,11 +327,11 @@ export class OpenShiftObjectImpl implements OpenShiftObject {
321327

322328
get iconPath(): Uri {
323329
if (this.contextValue === ContextType.COMPONENT_PUSHED || this.contextValue === ContextType.COMPONENT || this.contextValue === ContextType.COMPONENT_NO_CONTEXT) {
324-
if (this.compType === 'git') {
330+
if (this.compType === ComponentType.GIT) {
325331
return Uri.file(path.join(__dirname, "../../images/component", 'git.png'));
326-
} else if (this.compType === 'local') {
332+
} else if (this.compType === ComponentType.LOCAL) {
327333
return Uri.file(path.join(__dirname, "../../images/component", 'workspace.png'));
328-
} else if (this.compType === 'binary') {
334+
} else if (this.compType === ComponentType.BINARY) {
329335
return Uri.file(path.join(__dirname, "../../images/component", 'binary.png'));
330336
}
331337
} else {
@@ -382,6 +388,7 @@ export interface Odo {
382388
getClusters(): Promise<OpenShiftObject[]>;
383389
getProjects(): Promise<OpenShiftObject[]>;
384390
loadWorkspaceComponents(event: WorkspaceFoldersChangeEvent): void;
391+
addWorkspaceComponent(WorkspaceFolder: WorkspaceFolder, component: OpenShiftObject);
385392
getApplications(project: OpenShiftObject): Promise<OpenShiftObject[]>;
386393
getApplicationChildren(application: OpenShiftObject): Promise<OpenShiftObject[]>;
387394
getComponents(application: OpenShiftObject, condition?: (value: OpenShiftObject) => boolean): Promise<OpenShiftObject[]>;
@@ -555,8 +562,10 @@ export class OdoImpl implements Odo {
555562
clusters = await this.getClustersWithOc();
556563
}
557564
if (clusters.length > 0 && clusters[0].contextValue === ContextType.CLUSTER) {
558-
// kick out migration
559-
this.convertObjectsFromPreviousOdoReleases();
565+
// kick out migration if enabled
566+
if (!workspace.getConfiguration("openshiftConnector").get("disableCheckForMigration")) {
567+
this.convertObjectsFromPreviousOdoReleases();
568+
}
560569
}
561570
return clusters;
562571
}
@@ -663,16 +672,16 @@ export class OdoImpl implements Odo {
663672
let compSource: string = '';
664673
try {
665674
if (value.source.startsWith('https://')) {
666-
compSource = 'git';
675+
compSource = ComponentType.GIT;
667676
} else if (statSync(Uri.parse(value.source).fsPath).isFile()) {
668-
compSource = 'binary';
677+
compSource = ComponentType.BINARY;
669678
} else if (statSync(Uri.parse(value.source).fsPath).isDirectory()) {
670-
compSource = 'local';
679+
compSource = ComponentType.LOCAL;
671680
}
672681
} catch (ignore) {
673682
// treat component as local in case of error when calling statSync
674683
// for not existing file or folder
675-
compSource = 'local';
684+
compSource = ComponentType.LOCAL;
676685
}
677686
return new OpenShiftObjectImpl(application, value.name, ContextType.COMPONENT_NO_CONTEXT, true, this, Collapsed, undefined, compSource);
678687
});
@@ -917,7 +926,7 @@ export class OdoImpl implements Odo {
917926
if (!targetApplication) {
918927
await this.insertAndReveal(application);
919928
}
920-
await this.insertAndReveal(new OpenShiftObjectImpl(application, name, ContextType.COMPONENT, false, this, Collapsed, context, 'git'));
929+
await this.insertAndReveal(new OpenShiftObjectImpl(application, name, ContextType.COMPONENT, false, this, Collapsed, context, ComponentType.GIT));
921930
}
922931
workspace.updateWorkspaceFolders(workspace.workspaceFolders? workspace.workspaceFolders.length : 0 , null, { uri: context });
923932
return null;
@@ -930,7 +939,7 @@ export class OdoImpl implements Odo {
930939
if (!targetApplication) {
931940
await this.insertAndReveal(application);
932941
}
933-
this.insertAndReveal(new OpenShiftObjectImpl(application, name, ContextType.COMPONENT, false, this, Collapsed, context, 'binary'));
942+
this.insertAndReveal(new OpenShiftObjectImpl(application, name, ContextType.COMPONENT, false, this, Collapsed, context, ComponentType.BINARY));
934943
}
935944
workspace.updateWorkspaceFolders(workspace.workspaceFolders? workspace.workspaceFolders.length : 0 , null, { uri: context });
936945
return null;
@@ -1017,6 +1026,11 @@ export class OdoImpl implements Odo {
10171026
OdoImpl.data.clearTreeData();
10181027
}
10191028

1029+
addWorkspaceComponent(folder: WorkspaceFolder, component: OpenShiftObject) {
1030+
OdoImpl.data.addContexts([folder]);
1031+
this.subject.next(new OdoEventImpl('changed', null));
1032+
}
1033+
10201034
loadWorkspaceComponents(event: WorkspaceFoldersChangeEvent): void {
10211035
if (event === null && workspace.workspaceFolders) {
10221036
OdoImpl.data.addContexts(workspace.workspaceFolders);
@@ -1089,13 +1103,15 @@ export class OdoImpl implements Odo {
10891103
const result2 = await this.execute(getPreviosOdoResourceNames('ServiceInstance'), __dirname, false);
10901104
const sis = result2.stdout.split('\n');
10911105
if ((result2.stdout !== '' && sis.length > 0) || (result1.stdout !== '' && dcs.length > 0)) {
1092-
const choice = await window.showWarningMessage(`Some of resources in cluster must be updated to work with latest release of OpenShift Connector Extension.`, 'Learn more...', 'Update', 'Cancel');
1093-
if (choice === 'Learn more...') {
1094-
open('https://github.com/redhat-developer/vscode-openshift-tools/wiki/Migration-to-v0.0.24');
1106+
const choice = await window.showWarningMessage(`Some of resources in cluster must be updated to work with latest release of OpenShift Connector Extension.`, 'Update', 'Don\'t show it again', 'Help', 'Cancel');
1107+
if (choice === 'Help') {
1108+
open('https://github.com/redhat-developer/vscode-openshift-tools/wiki/Migration-to-v0.1.0');
10951109
this.subject.next(new OdoEventImpl('changed', this.getClusters()[0]));
1110+
} else if (choice === 'Don\'t show it again') {
1111+
workspace.getConfiguration("openshiftConnector").update("disableCheckForMigration", true, true);
10961112
} else if (choice === 'Update') {
10971113
const errors = [];
1098-
Progress.execFunctionWithProgress('Updating cluster resources to work with latest OpenShift Connector release', async (progress) => {
1114+
await Progress.execFunctionWithProgress('Updating cluster resources to work with latest OpenShift Connector release', async (progress) => {
10991115
for (const resourceId of ['DeploymentConfig', 'Route', 'BuildConfig', 'ImageStream', 'Service', 'pvc', 'Secret', 'ServiceInstance']) {
11001116
progress.report({increment: 100/8, message: resourceId});
11011117
const cmd = getPreviosOdoResourceNames(resourceId);
@@ -1113,8 +1129,12 @@ export class OdoImpl implements Odo {
11131129
if (labels['app.kubernetes.io/component-version']) {
11141130
command = command + ` app.openshift.io/runtime-version=${labels['app.kubernetes.io/component-version']}`;
11151131
}
1132+
if (labels['app.kubernetes.io/url-name']) {
1133+
command = command + ` odo.openshift.io/url-name=${labels['app.kubernetes.io/url-name']}`;
1134+
}
11161135
await this.execute(command);
11171136
await this.execute(`oc label ${resourceId} ${resourceName} app.kubernetes.io/component-name-`);
1137+
await this.execute(`oc label ${resourceId} ${resourceName} odo.openshift.io/migrated=true`);
11181138
} catch (err) {
11191139
errors.push(err);
11201140
}
@@ -1123,7 +1143,7 @@ export class OdoImpl implements Odo {
11231143
this.subject.next(new OdoEventImpl('changed', this.getClusters()[0]));
11241144
});
11251145
if (errors.length) {
1126-
window.showErrorMessage('Not all resources were updates, please see log for details.');
1146+
window.showErrorMessage('Not all resources were updates, please see OpenShift output channel for details.');
11271147
} else {
11281148
window.showInformationMessage('Cluster resources have been successfuly updated.');
11291149
}

0 commit comments

Comments
 (0)