22 * Copyright (c) Red Hat, Inc. All rights reserved.
33 * Licensed under the MIT License. See LICENSE file in the project root for license information.
44 *-----------------------------------------------------------------------------------------------*/
5+ /* eslint-disable camelcase */
56
67import { window , commands , env , QuickPickItem , ExtensionContext , Terminal , Uri , workspace } from 'vscode' ;
78import { Command } from '../odo/command' ;
@@ -16,6 +17,11 @@ import { WindowUtil } from '../util/windowUtils';
1617import { vsCommand , VsCommandError } from '../vscommand' ;
1718import ClusterViewLoader from '../webview/cluster/clusterViewLoader' ;
1819
20+ interface Versions {
21+ 'openshift_version' : string ;
22+ 'kubernetes_version' : string ;
23+ }
24+
1925export class Cluster extends OpenShiftItem {
2026 public static extensionContext : ExtensionContext ;
2127
@@ -137,6 +143,32 @@ export class Cluster extends OpenShiftItem {
137143 return ;
138144 }
139145
146+ public static async getVersions ( ) : Promise < Versions > {
147+ const result = await Cluster . odo . execute ( Command . printOcVersionJson ( ) , undefined , false ) ;
148+ const versions : Versions = {
149+ 'kubernetes_version' : undefined ,
150+ 'openshift_version' : undefined
151+ } ;
152+ if ( ! result . error ) {
153+ try {
154+ // try to fetch versions for stdout
155+ const versionsJson = JSON . parse ( result . stdout ) ;
156+ if ( versionsJson ?. serverVersion ?. major && versionsJson ?. serverVersion ?. minor ) {
157+ // eslint-disable-next-line @typescript-eslint/camelcase
158+ versions . kubernetes_version = `${ versionsJson . serverVersion . major } .${ versionsJson . serverVersion . minor } ` ;
159+ }
160+ if ( versionsJson ?. openshiftVersion ) {
161+ // eslint-disable-next-line @typescript-eslint/camelcase
162+ versions . openshift_version = versionsJson . openshiftVersion ;
163+ }
164+
165+ } catch ( err ) {
166+ // ignore and return undefined
167+ }
168+ }
169+ return versions ;
170+ }
171+
140172 @vsCommand ( 'openshift.explorer.login' )
141173 static async login ( context ?: any , skipConfirmation = false ) : Promise < string > {
142174 const response = await Cluster . requestLoginConfirmation ( skipConfirmation ) ;
@@ -159,7 +191,16 @@ export class Cluster extends OpenShiftItem {
159191 ] ;
160192 const loginActionSelected = await window . showQuickPick ( loginActions , { placeHolder : 'Select a way to log in to the cluster.' , ignoreFocusOut : true } ) ;
161193 if ( ! loginActionSelected ) return null ;
162- return loginActionSelected . label === 'Credentials' ? await Cluster . credentialsLogin ( true , clusterURL ) : await Cluster . tokenLogin ( clusterURL , true ) ;
194+ let result :any = loginActionSelected . label === 'Credentials' ? await Cluster . credentialsLogin ( true , clusterURL ) : await Cluster . tokenLogin ( clusterURL , true ) ;
195+ if ( result ) {
196+ const versions = await Cluster . getVersions ( ) ;
197+ if ( versions ) {
198+ result = new String ( result ) ;
199+ // get cluster information using 'oc version'
200+ result . properties = versions ;
201+ }
202+ }
203+ return result ;
163204 }
164205
165206 private static async requestLoginConfirmation ( skipConfirmation = false ) : Promise < string > {
0 commit comments