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
56 changes: 49 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
"onCommand:openshift.explorer.refresh",
"onCommand:openshift.componentTypesView.refresh",
"onCommand:openshift.project.create",
"onCommand:openshift.project.set",
"onCommand:openshift.project.delete",
"onCommand:openshift.project.delete.palette",
"onCommand:openshift.component.openCreateComponent",
Expand Down Expand Up @@ -250,6 +251,22 @@
"onWalkthrough:serverlessFunctionWalkthrough"
],
"contributes": {
"configurationDefaults": {
"vs-kubernetes": {
"vs-kubernetes.disable-context-info-status-bar": true,
"vs-kubernetes.disable-namespace-info-status-bar": true
}
},
"icons": {
"current-context": {
"description": "context",
"default":"selection"
},
"project-node": {
"description": "project node",
"default":"project"
}
},
"commands": [
{
"command": "openshift.about",
Expand Down Expand Up @@ -1632,7 +1649,12 @@
{
"command": "openshift.project.create",
"when": "view == openshiftProjectExplorer && viewItem == openshift.k8sContext && canCreateNamespace",
"group": "c1"
"group": "c1@1"
},
{
"command": "openshift.project.set",
"when": "view == openshiftProjectExplorer && viewItem == openshift.k8sContext && canCreateNamespace",
"group": "c1@2"
},
{
"command": "openshift.explorer.logout",
Expand All @@ -1654,10 +1676,20 @@
"when": "view == openshiftProjectExplorer && viewItem =~ /openshift.project.*/i && isLoggedIn",
"group": "p2"
},
{
"command": "openshift.project.set",
"when": "view == openshiftProjectExplorer && viewItem =~ /openshift.project.*/i && canCreateNamespace",
"group": "p3@1"
},
{
"command": "openshift.project.delete",
"when": "view == openshiftProjectExplorer && viewItem =~ /openshift.project.*.can-delete/i",
"group": "p3"
"group": "p3@2"
},
{
"command": "openshift.project.set",
"when": "view == openshiftProjectExplorer && viewItem =~ /openshift.project.*/i && canCreateNamespace",
"group": "inline"
},
{
"command": "openshift.component.describe",
Expand Down Expand Up @@ -1775,11 +1807,6 @@
"when": "view == openshiftProjectExplorer && viewItem == openshift.openConfigFile",
"group": "inline"
},
{
"command": "openshift.project.set",
"when": "view == openshiftProjectExplorer && (viewItem == openshift.k8sContext || viewItem =~ /openshift.project.*/i) && canCreateNamespace",
"group": "inline"
},
{
"command": "openshift.component.revealInExplorer",
"when": "view == openshiftComponentsView && viewItem =~ /openshift\\.component.*/",
Expand Down Expand Up @@ -2087,6 +2114,21 @@
"order": 1,
"title": "OpenShift Toolkit",
"properties": {
"openshiftToolkit": {
"type": "object",
"title": "Additional settings",
"description": "OpenShift Toolkit configuration",
"properties": {
"openshiftToolkit.disable-context-info-status-bar": {
"type": "boolean",
"description": "Disable displaying the current Kubernetes context in VS Code's status bar."
},
"openshiftToolkit.disable-namespace-info-status-bar": {
"type": "boolean",
"description": "Disable displaying the active namespace in VS Code's status bar."
}
}
},
"openshiftToolkit.showWelcomePage": {
"type": "boolean",
"default": true,
Expand Down
4 changes: 4 additions & 0 deletions src/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
readonly onDidChangeTreeData: Event<ExplorerItem | undefined> = this
.eventEmitter.event;

public onDidChangeContextEmitter = new EventEmitter<string>();

private constructor() {
try {
this.kubeConfig = new KubeConfigUtils();
Expand All @@ -100,6 +102,7 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
|| this.kubeContext.user !== newCtx.user
|| this.kubeContext.namespace !== newCtx.namespace)) {
this.refresh();
this.onDidChangeContextEmitter.fire(newCtx.name);
}
this.kubeContext = newCtx;
this.kubeConfig = ku2;
Expand Down Expand Up @@ -234,6 +237,7 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
} catch (err) {
// ignore because ether server is not accessible or user is logged out
}
OpenShiftExplorer.getInstance().onDidChangeContextEmitter.fire(new KubeConfigUtils().currentContext);
} else if ('name' in element) { // we are dealing with context here
// user is logged into cluster from current context
// and project should be show as child node of current context
Expand Down
66 changes: 64 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import { ServerlessFunctionView } from './serverlessFunction/view';
import { startTelemetry } from './telemetry';
import { ToolsConfig } from './tools';
import { TokenStore } from './util/credentialManager';
import { setKubeConfig } from './util/kubeUtils';
import { KubeConfigUtils, setKubeConfig } from './util/kubeUtils';
import { Context as KcuContext } from '@kubernetes/client-node/dist/config_types';
import { Platform } from './util/platform';
import { setupWorkspaceDevfileContext } from './util/workspace';
import { registerCommands } from './vscommand';
Expand All @@ -34,6 +35,7 @@ import { WelcomePage } from './welcomePage';
import { registerYamlHandlers } from './yaml/yamlDocumentFeatures';

import fsx = require('fs-extra');
import { Oc } from './oc/ocWrapper';

// eslint-disable-next-line @typescript-eslint/no-empty-function
// this method is called when your extension is deactivated
Expand Down Expand Up @@ -79,6 +81,13 @@ export async function activate(extensionContext: ExtensionContext): Promise<unkn

const crcStatusItem = window.createStatusBarItem(StatusBarAlignment.Left);
crcStatusItem.command = 'openshift.explorer.stopCluster';

const activeNamespaceStatusBarItem = window.createStatusBarItem(StatusBarAlignment.Left, 1);
activeNamespaceStatusBarItem.command = 'openshift.project.set';

const activeContextStatusBarItem = window.createStatusBarItem(StatusBarAlignment.Left, 2);
activeContextStatusBarItem.command = 'openshift.explorer.switchContext';

const disposable = [
...(await registerCommands(
'./k8s/route',
Expand All @@ -99,6 +108,8 @@ export async function activate(extensionContext: ExtensionContext): Promise<unkn
commands.executeCommand('extension.vsKubernetesUseNamespace', context),
),
crcStatusItem,
activeNamespaceStatusBarItem,
activeContextStatusBarItem,
OpenShiftExplorer.getInstance(),
new DebugSessionsView().createTreeView('openshiftDebugView'),
...Component.init(),
Expand Down Expand Up @@ -182,7 +193,7 @@ export async function activate(extensionContext: ExtensionContext): Promise<unkn
}

function createStatusBarItem(context: ExtensionContext) {
const item = window.createStatusBarItem(StatusBarAlignment.Left, 1);
const item = window.createStatusBarItem(StatusBarAlignment.Left, 3);
item.command = 'openshift.openStatusBar';
context.subscriptions.push(item);
context.subscriptions.push(statusBarFunctions());
Expand All @@ -201,6 +212,57 @@ export async function activate(extensionContext: ExtensionContext): Promise<unkn
statusBarItem.show();
}

// Disable the k8s extension displaying its context/namespace status bar items...
// ...and setup our own context and namespace status bar informer/picker items

// if true will disable displaying the namespace from the status bar
function isNamespaceInfoStatusBarDisabled(): boolean {
// If k8s extension's Namespace Picker is eenabled - do not show the OS Tools's one
if (workspace.getConfiguration('vs-kubernetes').get('vs-kubernetes.disable-namespace-info-status-bar') === false) {
return true;
}

return workspace.getConfiguration('openshiftToolkit').get['openshiftToolkit.disable-namespace-info-status-bar'];
}

// if true will disable displaying the context from the status bar
function isContextInfoStatusBarDisabled(): boolean {
// If k8s extension's Namespace Picker is eenabled - do not show the OS Tools's one
if (workspace.getConfiguration('vs-kubernetes').get('vs-kubernetes.disable-context-info-status-bar') === false) {
return true;
}

return workspace.getConfiguration('openshiftToolkit').get['openshiftToolkit.disable-context-info-status-bar'];
}

function updateContextStatusBarItem(statusBarItem: StatusBarItem, iconId: string, text: string, tooltip: string, show: boolean): void {
statusBarItem.text = `$(${iconId}) ${text}`;
statusBarItem.tooltip = tooltip;
if (show && text) {
statusBarItem.show();
} else {
statusBarItem.hide();
}
}

OpenShiftExplorer.getInstance().onDidChangeContextEmitter.event((context) => {
void Oc.Instance.getActiveProject().then((namespace) =>
updateContextStatusBarItem(activeNamespaceStatusBarItem, 'project-node', namespace, `Current namespace: ${namespace}`,
!isNamespaceInfoStatusBarDisabled()));

const kcu: KubeConfigUtils = new KubeConfigUtils();
const currentContext: KcuContext = kcu.findContext(context);
updateContextStatusBarItem(activeContextStatusBarItem, 'current-context', currentContext?.name, `${currentContext?.name}\nCluster: ${currentContext?.cluster}`,
!isContextInfoStatusBarDisabled());
});

const kcu: KubeConfigUtils = new KubeConfigUtils();
const currentContext: KcuContext = kcu.findContext(kcu.currentContext);
updateContextStatusBarItem(activeNamespaceStatusBarItem, 'project-node', null, 'Current namespace',
!isNamespaceInfoStatusBarDisabled());
updateContextStatusBarItem(activeContextStatusBarItem, 'current-context', currentContext?.name, `${currentContext?.name}\nCluster: ${currentContext?.cluster}`,
!isContextInfoStatusBarDisabled());

updateStatusBarItem(crcStatusItem, 'Stop CRC');
void extendClusterExplorer();

Expand Down