@@ -25,7 +25,8 @@ import { ServerlessFunctionView } from './serverlessFunction/view';
2525import { startTelemetry } from './telemetry' ;
2626import { ToolsConfig } from './tools' ;
2727import { TokenStore } from './util/credentialManager' ;
28- import { setKubeConfig } from './util/kubeUtils' ;
28+ import { KubeConfigUtils , setKubeConfig } from './util/kubeUtils' ;
29+ import { Context as KcuContext } from '@kubernetes/client-node/dist/config_types' ;
2930import { Platform } from './util/platform' ;
3031import { setupWorkspaceDevfileContext } from './util/workspace' ;
3132import { registerCommands } from './vscommand' ;
@@ -34,6 +35,7 @@ import { WelcomePage } from './welcomePage';
3435import { registerYamlHandlers } from './yaml/yamlDocumentFeatures' ;
3536
3637import fsx = require( 'fs-extra' ) ;
38+ import { Oc } from './oc/ocWrapper' ;
3739
3840// eslint-disable-next-line @typescript-eslint/no-empty-function
3941// this method is called when your extension is deactivated
@@ -79,6 +81,13 @@ export async function activate(extensionContext: ExtensionContext): Promise<unkn
7981
8082 const crcStatusItem = window . createStatusBarItem ( StatusBarAlignment . Left ) ;
8183 crcStatusItem . command = 'openshift.explorer.stopCluster' ;
84+
85+ const activeNamespaceStatusBarItem = window . createStatusBarItem ( StatusBarAlignment . Left , 1 ) ;
86+ activeNamespaceStatusBarItem . command = 'openshift.project.set' ;
87+
88+ const activeContextStatusBarItem = window . createStatusBarItem ( StatusBarAlignment . Left , 2 ) ;
89+ activeContextStatusBarItem . command = 'openshift.explorer.switchContext' ;
90+
8291 const disposable = [
8392 ...( await registerCommands (
8493 './k8s/route' ,
@@ -99,6 +108,8 @@ export async function activate(extensionContext: ExtensionContext): Promise<unkn
99108 commands . executeCommand ( 'extension.vsKubernetesUseNamespace' , context ) ,
100109 ) ,
101110 crcStatusItem ,
111+ activeNamespaceStatusBarItem ,
112+ activeContextStatusBarItem ,
102113 OpenShiftExplorer . getInstance ( ) ,
103114 new DebugSessionsView ( ) . createTreeView ( 'openshiftDebugView' ) ,
104115 ...Component . init ( ) ,
@@ -182,7 +193,7 @@ export async function activate(extensionContext: ExtensionContext): Promise<unkn
182193 }
183194
184195 function createStatusBarItem ( context : ExtensionContext ) {
185- const item = window . createStatusBarItem ( StatusBarAlignment . Left , 1 ) ;
196+ const item = window . createStatusBarItem ( StatusBarAlignment . Left , 3 ) ;
186197 item . command = 'openshift.openStatusBar' ;
187198 context . subscriptions . push ( item ) ;
188199 context . subscriptions . push ( statusBarFunctions ( ) ) ;
@@ -201,6 +212,57 @@ export async function activate(extensionContext: ExtensionContext): Promise<unkn
201212 statusBarItem . show ( ) ;
202213 }
203214
215+ // Disable the k8s extension displaying its context/namespace status bar items...
216+ // ...and setup our own context and namespace status bar informer/picker items
217+
218+ // if true will disable displaying the namespace from the status bar
219+ function isNamespaceInfoStatusBarDisabled ( ) : boolean {
220+ // If k8s extension's Namespace Picker is eenabled - do not show the OS Tools's one
221+ if ( workspace . getConfiguration ( 'vs-kubernetes' ) . get ( 'vs-kubernetes.disable-namespace-info-status-bar' ) === false ) {
222+ return true ;
223+ }
224+
225+ return workspace . getConfiguration ( 'openshiftToolkit' ) . get [ 'openshiftToolkit.disable-namespace-info-status-bar' ] ;
226+ }
227+
228+ // if true will disable displaying the context from the status bar
229+ function isContextInfoStatusBarDisabled ( ) : boolean {
230+ // If k8s extension's Namespace Picker is eenabled - do not show the OS Tools's one
231+ if ( workspace . getConfiguration ( 'vs-kubernetes' ) . get ( 'vs-kubernetes.disable-context-info-status-bar' ) === false ) {
232+ return true ;
233+ }
234+
235+ return workspace . getConfiguration ( 'openshiftToolkit' ) . get [ 'openshiftToolkit.disable-context-info-status-bar' ] ;
236+ }
237+
238+ function updateContextStatusBarItem ( statusBarItem : StatusBarItem , iconId : string , text : string , tooltip : string , show : boolean ) : void {
239+ statusBarItem . text = `$(${ iconId } ) ${ text } ` ;
240+ statusBarItem . tooltip = tooltip ;
241+ if ( show && text ) {
242+ statusBarItem . show ( ) ;
243+ } else {
244+ statusBarItem . hide ( ) ;
245+ }
246+ }
247+
248+ OpenShiftExplorer . getInstance ( ) . onDidChangeContextEmitter . event ( ( context ) => {
249+ void Oc . Instance . getActiveProject ( ) . then ( ( namespace ) =>
250+ updateContextStatusBarItem ( activeNamespaceStatusBarItem , 'project-node' , namespace , `Current namespace: ${ namespace } ` ,
251+ ! isNamespaceInfoStatusBarDisabled ( ) ) ) ;
252+
253+ const kcu : KubeConfigUtils = new KubeConfigUtils ( ) ;
254+ const currentContext : KcuContext = kcu . findContext ( context ) ;
255+ updateContextStatusBarItem ( activeContextStatusBarItem , 'current-context' , currentContext ?. name , `${ currentContext ?. name } \nCluster: ${ currentContext ?. cluster } ` ,
256+ ! isContextInfoStatusBarDisabled ( ) ) ;
257+ } ) ;
258+
259+ const kcu : KubeConfigUtils = new KubeConfigUtils ( ) ;
260+ const currentContext : KcuContext = kcu . findContext ( kcu . currentContext ) ;
261+ updateContextStatusBarItem ( activeNamespaceStatusBarItem , 'project-node' , null , 'Current namespace' ,
262+ ! isNamespaceInfoStatusBarDisabled ( ) ) ;
263+ updateContextStatusBarItem ( activeContextStatusBarItem , 'current-context' , currentContext ?. name , `${ currentContext ?. name } \nCluster: ${ currentContext ?. cluster } ` ,
264+ ! isContextInfoStatusBarDisabled ( ) ) ;
265+
204266 updateStatusBarItem ( crcStatusItem , 'Stop CRC' ) ;
205267 void extendClusterExplorer ( ) ;
206268
0 commit comments