2
2
* Copyright (c) Red Hat, Inc. All rights reserved.
3
3
* Licensed under the MIT License. See LICENSE file in the project root for license information.
4
4
*-----------------------------------------------------------------------------------------------*/
5
+ /* eslint-disable camelcase */
5
6
6
7
import { window , commands , env , QuickPickItem , ExtensionContext , Terminal , Uri , workspace } from 'vscode' ;
7
8
import { Command } from '../odo/command' ;
@@ -16,6 +17,11 @@ import { WindowUtil } from '../util/windowUtils';
16
17
import { vsCommand , VsCommandError } from '../vscommand' ;
17
18
import ClusterViewLoader from '../webview/cluster/clusterViewLoader' ;
18
19
20
+ interface Versions {
21
+ 'openshift_version' : string ;
22
+ 'kubernetes_version' : string ;
23
+ }
24
+
19
25
export class Cluster extends OpenShiftItem {
20
26
public static extensionContext : ExtensionContext ;
21
27
@@ -137,6 +143,32 @@ export class Cluster extends OpenShiftItem {
137
143
return ;
138
144
}
139
145
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
+
140
172
@vsCommand ( 'openshift.explorer.login' )
141
173
static async login ( context ?: any , skipConfirmation = false ) : Promise < string > {
142
174
const response = await Cluster . requestLoginConfirmation ( skipConfirmation ) ;
@@ -159,7 +191,16 @@ export class Cluster extends OpenShiftItem {
159
191
] ;
160
192
const loginActionSelected = await window . showQuickPick ( loginActions , { placeHolder : 'Select a way to log in to the cluster.' , ignoreFocusOut : true } ) ;
161
193
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 ;
163
204
}
164
205
165
206
private static async requestLoginConfirmation ( skipConfirmation = false ) : Promise < string > {
0 commit comments