Skip to content

Commit e268b89

Browse files
authored
Iterate over projects when checking for resources form previous odo (#1155)
1 parent 0559f1c commit e268b89

File tree

1 file changed

+44
-32
lines changed

1 file changed

+44
-32
lines changed

src/odo.ts

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,46 +1114,58 @@ export class OdoImpl implements Odo {
11141114
}
11151115

11161116
async convertObjectsFromPreviousOdoReleases() {
1117-
const getPreviosOdoResourceNames = (resourceId) => `oc get ${resourceId} -l app.kubernetes.io/component-name -o jsonpath="{range .items[*]}{.metadata.name}{\\"\\n\\"}{end}"`;
1118-
const result1 = await this.execute(getPreviosOdoResourceNames('dc'), __dirname, false);
1119-
const dcs = result1.stdout.split('\n');
1120-
const result2 = await this.execute(getPreviosOdoResourceNames('ServiceInstance'), __dirname, false);
1121-
const sis = result2.stdout.split('\n');
1122-
if ((result2.stdout !== '' && sis.length > 0) || (result1.stdout !== '' && dcs.length > 0)) {
1123-
const choice = await window.showWarningMessage(`Some of the resources in cluster must be updated to work with latest release of OpenShift Connector Extension.`, 'Update', 'Don\'t show it again', 'Help', 'Cancel');
1117+
1118+
const projectsResult = await this.execute(`oc get project -o jsonpath="{range .items[*]}{.metadata.name}{\\"\\n\\"}{end}"`);
1119+
const projects = projectsResult.stdout.split('\n');
1120+
const projectsToMigrate: string[] = [];
1121+
const getPreviosOdoResourceNames = (resourceId: string, project: string) => `oc get ${resourceId} -l app.kubernetes.io/component-name -o jsonpath="{range .items[*]}{.metadata.name}{\\"\\n\\"}{end}" --namespace=${project}`;
1122+
1123+
for (const project of projects) {
1124+
const result1 = await this.execute(getPreviosOdoResourceNames('dc', project), __dirname, false);
1125+
const dcs = result1.stdout.split('\n');
1126+
const result2 = await this.execute(getPreviosOdoResourceNames('ServiceInstance', project), __dirname, false);
1127+
const sis = result2.stdout.split('\n');
1128+
if ((result2.stdout !== '' && sis.length > 0) || (result1.stdout !== '' && dcs.length > 0)) {
1129+
projectsToMigrate.push(project);
1130+
}
1131+
1132+
}
1133+
if (projectsToMigrate.length > 0) {
1134+
const choice = await window.showWarningMessage(`Some of the resources in cluster must be updated to work with latest release of OpenShift Connector Extension.`, 'Update', 'Don\'t check again', 'Help', 'Cancel');
11241135
if (choice === 'Help') {
11251136
open('https://github.com/redhat-developer/vscode-openshift-tools/wiki/Migration-to-v0.1.0');
11261137
this.subject.next(new OdoEventImpl('changed', this.getClusters()[0]));
1127-
} else if (choice === 'Don\'t show it again') {
1138+
} else if (choice === 'Don\'t check again') {
11281139
workspace.getConfiguration("openshiftConnector").update("disableCheckForMigration", true, true);
11291140
} else if (choice === 'Update') {
11301141
const errors = [];
11311142
await Progress.execFunctionWithProgress('Updating cluster resources to work with latest OpenShift Connector release', async (progress) => {
1132-
for (const resourceId of ['DeploymentConfig', 'Route', 'BuildConfig', 'ImageStream', 'Service', 'pvc', 'Secret', 'ServiceInstance']) {
1133-
progress.report({increment: 100/8, message: resourceId});
1134-
const cmd = getPreviosOdoResourceNames(resourceId);
1135-
const result = await this.execute(cmd, __dirname, false);
1136-
const resourceNames = result.error || result.stdout === '' ? [] : result.stdout.split('\n');
1137-
for (const resourceName of resourceNames) {
1138-
try {
1139-
const result = await this.execute(`oc get ${resourceId} ${resourceName} -o json`);
1140-
const labels = JSON.parse(result.stdout).metadata.labels;
1141-
let command = `oc label ${resourceId} ${resourceName} --overwrite app.kubernetes.io/instance=${labels['app.kubernetes.io/component-name']}`;
1142-
command = command + ` app.kubernetes.io/part-of=${labels['app.kubernetes.io/name']}`;
1143-
if (labels['app.kubernetes.io/component-type']) {
1144-
command = command + ` app.kubernetes.io/name=${labels['app.kubernetes.io/component-type']}`;
1145-
}
1146-
if (labels['app.kubernetes.io/component-version']) {
1147-
command = command + ` app.openshift.io/runtime-version=${labels['app.kubernetes.io/component-version']}`;
1148-
}
1149-
if (labels['app.kubernetes.io/url-name']) {
1150-
command = command + ` odo.openshift.io/url-name=${labels['app.kubernetes.io/url-name']}`;
1143+
for (const project of projectsToMigrate) {
1144+
for (const resourceId of ['DeploymentConfig', 'Route', 'BuildConfig', 'ImageStream', 'Service', 'pvc', 'Secret', 'ServiceInstance']) {
1145+
progress.report({increment: 100/8, message: resourceId});
1146+
const result = await this.execute(getPreviosOdoResourceNames(resourceId, project), __dirname, false);
1147+
const resourceNames = result.error || result.stdout === '' ? [] : result.stdout.split('\n');
1148+
for (const resourceName of resourceNames) {
1149+
try {
1150+
const result = await this.execute(`oc get ${resourceId} ${resourceName} -o json --namespace=${project}`);
1151+
const labels = JSON.parse(result.stdout).metadata.labels;
1152+
let command = `oc label ${resourceId} ${resourceName} --overwrite app.kubernetes.io/instance=${labels['app.kubernetes.io/component-name']}`;
1153+
command = command + ` app.kubernetes.io/part-of=${labels['app.kubernetes.io/name']}`;
1154+
if (labels['app.kubernetes.io/component-type']) {
1155+
command = command + ` app.kubernetes.io/name=${labels['app.kubernetes.io/component-type']}`;
1156+
}
1157+
if (labels['app.kubernetes.io/component-version']) {
1158+
command = command + ` app.openshift.io/runtime-version=${labels['app.kubernetes.io/component-version']}`;
1159+
}
1160+
if (labels['app.kubernetes.io/url-name']) {
1161+
command = command + ` odo.openshift.io/url-name=${labels['app.kubernetes.io/url-name']}`;
1162+
}
1163+
await this.execute(command + ` --namespace=${project}`);
1164+
await this.execute(`oc label ${resourceId} ${resourceName} app.kubernetes.io/component-name- --namespace=${project}`);
1165+
await this.execute(`oc label ${resourceId} ${resourceName} odo.openshift.io/migrated=true --namespace=${project}`);
1166+
} catch (err) {
1167+
errors.push(err);
11511168
}
1152-
await this.execute(command);
1153-
await this.execute(`oc label ${resourceId} ${resourceName} app.kubernetes.io/component-name-`);
1154-
await this.execute(`oc label ${resourceId} ${resourceName} odo.openshift.io/migrated=true`);
1155-
} catch (err) {
1156-
errors.push(err);
11571169
}
11581170
}
11591171
}

0 commit comments

Comments
 (0)