Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
55 changes: 55 additions & 0 deletions src/odo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import * as odo from './odo/config';
import { ComponentSettings } from './odo/config';
import { GlyphChars } from './util/constants';
import { Subject } from 'rxjs';
import open = require('open');
import { Progress } from './util/progress';

const Collapsed = TreeItemCollapsibleState.Collapsed;

Expand Down Expand Up @@ -552,6 +554,10 @@ export class OdoImpl implements Odo {
if (clusters.length === 0) {
clusters = await this.getClustersWithOc();
}
if (clusters.length > 0 && clusters[0].contextValue === ContextType.CLUSTER) {
// kick out migration
this.convertObjectsFromPreviousOdoReleases();
}
return clusters;
}

Expand Down Expand Up @@ -1075,4 +1081,53 @@ export class OdoImpl implements Odo {
}
return data;
}

async convertObjectsFromPreviousOdoReleases() {
const getPreviosOdoResourceNames = (resourceId) => `oc get ${resourceId} -l app.kubernetes.io/component-name -o jsonpath="{range .items[*]}{.metadata.name}{\\"\\n\\"}{end}"`;
const result1 = await this.execute(getPreviosOdoResourceNames('dc'), __dirname, false);
const dcs = result1.stdout.split('\n');
const result2 = await this.execute(getPreviosOdoResourceNames('ServiceInstance'), __dirname, false);
const sis = result2.stdout.split('\n');
if ((result2.stdout !== '' && sis.length > 0) || (result1.stdout !== '' && dcs.length > 0)) {
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');
if (choice === 'Learn more...') {
open('https://github.com/redhat-developer/vscode-openshift-tools/wiki/Migration-to-v0.0.24');
this.subject.next(new OdoEventImpl('changed', this.getClusters()[0]));
} else if (choice === 'Update') {
const errors = [];
Progress.execFunctionWithProgress('Updating cluster resources to work with latest OpenShift Connector release', async (progress) => {
for (const resourceId of ['DeploymentConfig', 'Route', 'BuildConfig', 'ImageStream', 'Service', 'pvc', 'Secret', 'ServiceInstance']) {
progress.report({increment: 100/8, message: resourceId});
const cmd = getPreviosOdoResourceNames(resourceId);
const result = await this.execute(cmd, __dirname, false);
const resourceNames = result.error || result.stdout === '' ? [] : result.stdout.split('\n');
for (const resourceName of resourceNames) {
try {
const result = await this.execute(`oc get ${resourceId} ${resourceName} -o json`);
const labels = JSON.parse(result.stdout).metadata.labels;
let command = `oc label ${resourceId} ${resourceName} --overwrite app.kubernetes.io/instance=${labels['app.kubernetes.io/component-name']}`;
command = command + ` app.kubernetes.io/part-of=${labels['app.kubernetes.io/name']}`;
if (labels['app.kubernetes.io/component-type']) {
command = command + ` app.kubernetes.io/name=${labels['app.kubernetes.io/component-type']}`;
}
if (labels['app.kubernetes.io/component-version']) {
command = command + ` app.openshift.io/runtime-version=${labels['app.kubernetes.io/component-version']}`;
}
await this.execute(command);
await this.execute(`oc label ${resourceId} ${resourceName} app.kubernetes.io/component-name-`);
} catch (err) {
errors.push(err);
}
}
}
this.subject.next(new OdoEventImpl('changed', this.getClusters()[0]));
});
if (errors.length) {
window.showErrorMessage('Not all resources were updates, please see log for details.');
} else {
window.showInformationMessage('Cluster resources have been successfuly updated.');
}
}
}
}
}
1 change: 1 addition & 0 deletions test/odo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ suite("odo", () => {

setup(() => {
execStub = sandbox.stub(odoCli, 'execute');
sandbox.stub(odo.OdoImpl.prototype, 'convertObjectsFromPreviousOdoReleases');
yamlStub = sandbox.stub(jsYaml, 'safeLoad');
sandbox.stub(fs, 'readFileSync');
});
Expand Down
1 change: 1 addition & 0 deletions test/openshift/component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ suite('OpenShift/Component', () => {
getApps = sandbox.stub(OpenShiftItem, 'getApplicationNames').resolves([appItem]);
sandbox.stub(OpenShiftItem, 'getComponentNames').resolves([componentItem]);
sandbox.stub(OpenShiftItem, 'getServiceNames').resolves([serviceItem]);
sandbox.stub(OdoImpl.prototype, 'convertObjectsFromPreviousOdoReleases');
});

teardown(() => {
Expand Down