@@ -19,6 +19,8 @@ import * as odo from './odo/config';
1919import { ComponentSettings } from './odo/config' ;
2020import { GlyphChars } from './util/constants' ;
2121import { Subject } from 'rxjs' ;
22+ import open = require( 'open' ) ;
23+ import { Progress } from './util/progress' ;
2224
2325const Collapsed = TreeItemCollapsibleState . Collapsed ;
2426
@@ -552,6 +554,10 @@ export class OdoImpl implements Odo {
552554 if ( clusters . length === 0 ) {
553555 clusters = await this . getClustersWithOc ( ) ;
554556 }
557+ if ( clusters . length > 0 && clusters [ 0 ] . contextValue === ContextType . CLUSTER ) {
558+ // kick out migration
559+ this . convertObjectsFromPreviousOdoReleases ( ) ;
560+ }
555561 return clusters ;
556562 }
557563
@@ -1075,4 +1081,53 @@ export class OdoImpl implements Odo {
10751081 }
10761082 return data ;
10771083 }
1084+
1085+ async convertObjectsFromPreviousOdoReleases ( ) {
1086+ const getPreviosOdoResourceNames = ( resourceId ) => `oc get ${ resourceId } -l app.kubernetes.io/component-name -o jsonpath="{range .items[*]}{.metadata.name}{\\"\\n\\"}{end}"` ;
1087+ const result1 = await this . execute ( getPreviosOdoResourceNames ( 'dc' ) , __dirname , false ) ;
1088+ const dcs = result1 . stdout . split ( '\n' ) ;
1089+ const result2 = await this . execute ( getPreviosOdoResourceNames ( 'ServiceInstance' ) , __dirname , false ) ;
1090+ const sis = result2 . stdout . split ( '\n' ) ;
1091+ 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' ) ;
1095+ this . subject . next ( new OdoEventImpl ( 'changed' , this . getClusters ( ) [ 0 ] ) ) ;
1096+ } else if ( choice === 'Update' ) {
1097+ const errors = [ ] ;
1098+ Progress . execFunctionWithProgress ( 'Updating cluster resources to work with latest OpenShift Connector release' , async ( progress ) => {
1099+ for ( const resourceId of [ 'DeploymentConfig' , 'Route' , 'BuildConfig' , 'ImageStream' , 'Service' , 'pvc' , 'Secret' , 'ServiceInstance' ] ) {
1100+ progress . report ( { increment : 100 / 8 , message : resourceId } ) ;
1101+ const cmd = getPreviosOdoResourceNames ( resourceId ) ;
1102+ const result = await this . execute ( cmd , __dirname , false ) ;
1103+ const resourceNames = result . error || result . stdout === '' ? [ ] : result . stdout . split ( '\n' ) ;
1104+ for ( const resourceName of resourceNames ) {
1105+ try {
1106+ const result = await this . execute ( `oc get ${ resourceId } ${ resourceName } -o json` ) ;
1107+ const labels = JSON . parse ( result . stdout ) . metadata . labels ;
1108+ let command = `oc label ${ resourceId } ${ resourceName } --overwrite app.kubernetes.io/instance=${ labels [ 'app.kubernetes.io/component-name' ] } ` ;
1109+ command = command + ` app.kubernetes.io/part-of=${ labels [ 'app.kubernetes.io/name' ] } ` ;
1110+ if ( labels [ 'app.kubernetes.io/component-type' ] ) {
1111+ command = command + ` app.kubernetes.io/name=${ labels [ 'app.kubernetes.io/component-type' ] } ` ;
1112+ }
1113+ if ( labels [ 'app.kubernetes.io/component-version' ] ) {
1114+ command = command + ` app.openshift.io/runtime-version=${ labels [ 'app.kubernetes.io/component-version' ] } ` ;
1115+ }
1116+ await this . execute ( command ) ;
1117+ await this . execute ( `oc label ${ resourceId } ${ resourceName } app.kubernetes.io/component-name-` ) ;
1118+ } catch ( err ) {
1119+ errors . push ( err ) ;
1120+ }
1121+ }
1122+ }
1123+ this . subject . next ( new OdoEventImpl ( 'changed' , this . getClusters ( ) [ 0 ] ) ) ;
1124+ } ) ;
1125+ if ( errors . length ) {
1126+ window . showErrorMessage ( 'Not all resources were updates, please see log for details.' ) ;
1127+ } else {
1128+ window . showInformationMessage ( 'Cluster resources have been successfuly updated.' ) ;
1129+ }
1130+ }
1131+ }
1132+ }
10781133}
0 commit comments