Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 68f1e4e

Browse files
authored
fix(resource-monitor): get DW Namespace name from ENV variable (#1269)
* chore: get DW namespace name from env Signed-off-by: svor <vsvydenk@redhat.com> * chore: get namespace name from workspace service Signed-off-by: svor <vsvydenk@redhat.com>
1 parent ad0da3e commit 68f1e4e

File tree

10 files changed

+26
-22
lines changed

10 files changed

+26
-22
lines changed

extensions/eclipse-che-theia-plugin-ext/src/browser/che-workspace-main.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export class CheWorkspaceMainImpl implements CheWorkspaceMain {
4141
);
4242
}
4343

44+
$getCurrentNamespace(): Promise<string> {
45+
return this.workspaceService.getCurrentNamespace();
46+
}
47+
4448
async $getById(workspaceId: string): Promise<cheApi.workspace.Workspace> {
4549
return this.workspaceService.getWorkspaceById(workspaceId).then(
4650
workspace => workspace,

extensions/eclipse-che-theia-plugin-ext/src/common/che-protocol.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export interface CheWorkspace {
3535

3636
export interface CheWorkspaceMain {
3737
$getCurrentWorkspace(): Promise<cheApi.workspace.Workspace>;
38+
$getCurrentNamespace(): Promise<string>;
3839
// getAll(): Promise<Workspace[]>;
3940
// getAllByNamespace(namespace: string): Promise<Workspace[]>;
4041
$getById(workspaceId: string): Promise<cheApi.workspace.Workspace>;

extensions/eclipse-che-theia-plugin-ext/src/plugin/che-api.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ export function createAPIFactory(rpc: RPCProtocol): CheApiFactory {
6666
getCurrentWorkspace(): Promise<cheApi.workspace.Workspace> {
6767
return cheWorkspaceImpl.getCurrentWorkspace();
6868
},
69+
getCurrentNamespace(): Promise<string> {
70+
return cheWorkspaceImpl.getCurrentNamespace();
71+
},
6972
getAll(): Promise<cheApi.workspace.Workspace[]> {
7073
return cheWorkspaceImpl.getAll();
7174
},

extensions/eclipse-che-theia-plugin-ext/src/plugin/che-workspace.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ export class CheWorkspaceImpl implements CheWorkspace {
6464
throw new Error('Method not implemented.');
6565
}
6666

67+
getCurrentNamespace(): Promise<string> {
68+
return this.workspaceMain.$getCurrentNamespace();
69+
}
70+
6771
getAll(): Promise<cheApi.workspace.Workspace[]> {
6872
throw new Error('Method not implemented.');
6973
}

extensions/eclipse-che-theia-plugin/src/che-proposed.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ declare module '@eclipse-che/plugin' {
2929

3030
export namespace workspace {
3131
export function getCurrentWorkspace(): Promise<cheApi.workspace.Workspace>;
32+
export function getCurrentNamespace(): Promise<string>;
3233
export function getAll(): Promise<cheApi.workspace.Workspace[]>;
3334
export function getAllByNamespace(namespace: string): Promise<cheApi.workspace.Workspace[]>;
3435
export function getById(workspaceId: string): Promise<cheApi.workspace.Workspace>;

extensions/eclipse-che-theia-remote-api/src/common/workspace-service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export interface WorkspaceSettings {
5555

5656
export const WorkspaceService = Symbol('WorkspaceService');
5757
export interface WorkspaceService {
58+
getCurrentNamespace(): Promise<string>;
5859
getCurrentWorkspaceId(): Promise<string>;
5960
currentWorkspace(): Promise<Workspace>;
6061
getWorkspaceById(workspaceId: string): Promise<Workspace>;

extensions/eclipse-che-theia-remote-impl-che-server/src/node/che-server-workspace-service-impl.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export class CheServerWorkspaceServiceImpl implements WorkspaceService {
2323
@inject(CheServerRemoteApiImpl)
2424
private cheServerRemoteApiImpl: CheServerRemoteApiImpl;
2525

26+
private INFRASTRUCTURE_NAMESPACE = 'infrastructureNamespace';
27+
2628
/**
2729
* Workspace client based variables.
2830
*
@@ -52,6 +54,11 @@ export class CheServerWorkspaceServiceImpl implements WorkspaceService {
5254
return this.workspaceId;
5355
}
5456

57+
public async getCurrentNamespace(): Promise<string> {
58+
const workspace = await this.currentWorkspace();
59+
return workspace.attributes?.[this.INFRASTRUCTURE_NAMESPACE] || workspace.namespace || '';
60+
}
61+
5562
public async currentWorkspace(): Promise<Workspace> {
5663
return this.cheServerRemoteApiImpl.getAPI().getById<Workspace>(this.workspaceId);
5764
}

plugins/resource-monitor-plugin/__mocks__/@eclipse-che/plugin.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* @author Valerii Svydenko
1717
*/
1818
const che: any = {};
19-
che.devfile = {};
20-
che.devfile.metadata = {};
19+
che.workspace = {};
2120
che.k8s = {};
2221
module.exports = che;

plugins/resource-monitor-plugin/src/plugin.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,5 @@ export async function start(context: theia.PluginContext): Promise<void> {
2727
}
2828

2929
export async function getNamespace(): Promise<string> {
30-
// get namespace from devfile service
31-
const devfile = await che.devfile.get();
32-
return devfile.metadata?.attributes ? devfile.metadata.attributes.infrastructureNamespace : '';
30+
return await che.workspace.getCurrentNamespace();
3331
}

plugins/resource-monitor-plugin/tests/plugin.spec.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,14 @@ const context: theia.PluginContext = {
6969

7070
describe('Test Plugin', () => {
7171
jest.mock('../src/inversify-binding');
72-
const devfileMock = jest.fn();
72+
const getCurrentNamespace = jest.fn();
7373
let oldBindings: any;
7474
let initBindings: jest.Mock;
7575

7676
beforeEach(() => {
7777
// Prepare Namespace
78-
che.devfile.get = devfileMock;
79-
const attributes = { infrastructureNamespace: 'che-namespace' };
80-
const devfile = {
81-
metadata: {
82-
attributes,
83-
},
84-
};
85-
devfileMock.mockReturnValue(devfile);
78+
che.workspace.getCurrentNamespace = getCurrentNamespace;
79+
getCurrentNamespace.mockReturnValue('che-namespace');
8680
oldBindings = InversifyBinding.prototype.initBindings;
8781
initBindings = jest.fn();
8882
InversifyBinding.prototype.initBindings = initBindings;
@@ -107,13 +101,5 @@ describe('Test Plugin', () => {
107101
const namespace = await plugin.getNamespace();
108102
expect(namespace).toBe('che-namespace');
109103
});
110-
test('read che namespace from workspace service if no infrastructureNamespace attribute in devile metadata', async () => {
111-
const devfile = {
112-
metadata: {},
113-
};
114-
devfileMock.mockReturnValue(devfile);
115-
const namespace = await plugin.getNamespace();
116-
expect(namespace).toBe('');
117-
});
118104
});
119105
});

0 commit comments

Comments
 (0)