Skip to content

Commit

Permalink
feat: provides OpenVSX CheCluster URL to user containers
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <oorel@redhat.com>
  • Loading branch information
olexii4 committed Aug 19, 2022
1 parent 6b5a487 commit 33ac2a3
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 41 deletions.
2 changes: 2 additions & 0 deletions packages/dashboard-backend/src/api/serverConfigApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ export function registerServerConfigApi(server: FastifyInstance) {
const plugins = serverConfigApi.getDefaultPlugins(cheCustomResource);
const editor = serverConfigApi.getDefaultEditor(cheCustomResource);
const components = serverConfigApi.getDefaultComponents(cheCustomResource);
const openVSXURL = serverConfigApi.getOpenVSXURL(cheCustomResource);

return {
defaults: {
editor,
plugins,
components,
},
openVSXURL,
};
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export class ServerConfigApi implements IServerConfigApi {
return cheCustomResource.spec.server.workspaceDefaultComponents || [];
}

getOpenVSXURL(cheCustomResource: { [key: string]: any }): string | undefined {
return cheCustomResource.spec.components.devWorkspace.cheServer.pluginRegistry.OpenVSXURL;
}

getDashboardWarning(cheCustomResource: { [key: string]: any }): string | undefined {
return cheCustomResource.spec.dashboard?.warning;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,23 @@ export interface IServerConfigApi {
*/
getDefaultComponents(cheCustomResource: { [key: string]: any }): V220DevfileComponents[];
/**
* Returns a maintenance warning
* Returns the openVSX URL if it is defined.
*/
getOpenVSXURL(cheCustomResource: { [key: string]: any }): string | undefined;
/**
* Returns a maintenance warning.
*/
getDashboardWarning(cheCustomResource: { [key: string]: any }): string | undefined;

/**
* Returns limit of running workspaces per user
* Returns limit of running workspaces per user.
*/
getRunningWorkspacesLimit(cheCustomResource: { [key: string]: any }): number;
}

export interface IKubeConfigApi {
/**
* Inject the kubeconfig into all containers with the given devworkspaceId in a namespace
* Inject the kubeconfig into all containers with the given devworkspaceId in a namespace.
*/
injectKubeConfig(namespace: string, devworkspaceId: string): Promise<void>;
}
Expand Down
9 changes: 6 additions & 3 deletions packages/dashboard-frontend/src/services/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { AlertVariant } from '@patternfly/react-core';
import SessionStorageService, { SessionStorageKey } from '../session-storage';
import { buildDetailsLocation, buildIdeLoaderLocation } from '../helpers/location';
import { selectAllWorkspaces } from '../../store/Workspaces/selectors';
import { selectOpenVSXUrl } from '../../store/ServerConfig/selectors';

/**
* This class executes a few initial instructions
Expand Down Expand Up @@ -218,14 +219,16 @@ export default class Bootstrap {
selectDwEditorsPluginsList(state.dwPlugins.defaultEditorName)(state).forEach(dwEditor => {
pluginsByUrl[dwEditor.url] = dwEditor.devfile;
});
const settings = this.store.getState().workspacesSettings.settings;
const openVSXUrl = selectOpenVSXUrl(state);
const settings = state.workspacesSettings.settings;
const pluginRegistryUrl = settings['cheWorkspacePluginRegistryUrl'];
const pluginRegistryInternalUrl = settings['cheWorkspacePluginRegistryInternalUrl'];
const updates = await this.devWorkspaceClient.checkForTemplatesUpdate(
defaultNamespace,
pluginsByUrl,
pluginRegistryUrl || '',
pluginRegistryInternalUrl || '',
pluginRegistryUrl,
pluginRegistryInternalUrl,
openVSXUrl,
);
if (Object.keys(updates).length > 0) {
await this.devWorkspaceClient.updateTemplates(defaultNamespace, updates);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@ import { prefix } from './const';
import { api } from '@eclipse-che/common';
import { V220DevfileComponents } from '@devfile/api';

export interface ServerConfig {
defaults: {
editor: string | undefined;
components: V220DevfileComponents[];
plugins: api.IWorkspacesDefaultPlugins[];
};
openVSXURL: string | undefined;
}

/**
* Returns an array of default plug-ins per editor
*
* @returns Promise resolving with the object with includes
* default plug-ins for the specified editor,
* default editor and default components
*/
export async function getServerConfig(): Promise<{
defaults: {
plugins: api.IWorkspacesDefaultPlugins[];
components: V220DevfileComponents[];
editor: string | undefined;
};
}> {
export async function getServerConfig(): Promise<ServerConfig> {
const url = `${prefix}/server-config`;
try {
const response = await axios.get(url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describe('DevWorkspace client, create', () => {
undefined,
undefined,
undefined,
undefined,
{},
);

Expand All @@ -100,6 +101,7 @@ describe('DevWorkspace client, create', () => {
[],
undefined,
undefined,
undefined,
'eclipse/theia/next',
{},
);
Expand Down Expand Up @@ -188,6 +190,7 @@ describe('DevWorkspace client, create', () => {
undefined,
undefined,
undefined,
undefined,
);

expect(spyCreateWorkspace).toBeCalledWith(
Expand All @@ -209,6 +212,7 @@ describe('DevWorkspace client, create', () => {
undefined,
'http://plugin.registry.url',
'http://internal.plugin.registry.url',
undefined,
);

expect(spyCreateWorkspaceTemplate).toBeCalledWith(
Expand Down Expand Up @@ -243,6 +247,7 @@ describe('DevWorkspace client, create', () => {
undefined,
undefined,
undefined,
undefined,
);

expect(spyCreateWorkspaceTemplate).toBeCalledWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('DevWorkspace client editor update', () => {
},
pluginRegistryUrl,
pluginRegistryInternalUrl,
undefined,
);

expect(mockPatch.mock.calls).toEqual([
Expand Down Expand Up @@ -84,6 +85,7 @@ describe('DevWorkspace client editor update', () => {
},
pluginRegistryUrl,
pluginRegistryInternalUrl,
undefined,
);

expect(mockPatch.mock.calls).toEqual([
Expand Down Expand Up @@ -113,6 +115,7 @@ describe('DevWorkspace client editor update', () => {
{},
pluginRegistryUrl,
pluginRegistryInternalUrl,
undefined,
);

expect(mockPatch.mock.calls).toEqual([
Expand Down Expand Up @@ -149,6 +152,7 @@ describe('DevWorkspace client editor update', () => {
{},
pluginRegistryUrl,
pluginRegistryInternalUrl,
undefined,
);

expect(mockPatch.mock.calls).toEqual([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export class DevWorkspaceClient extends WorkspaceClient {
private readonly maxStatusAttempts: number;
private readonly pluginRegistryUrlEnvName: string;
private readonly pluginRegistryInternalUrlEnvName: string;
private readonly openVSXUrlEnvName: string;
private readonly dashboardUrlEnvName: string;
private readonly websocketClient: WebsocketClient;
private webSocketEventEmitter: EventEmitter;
Expand All @@ -154,6 +155,7 @@ export class DevWorkspaceClient extends WorkspaceClient {
this.maxStatusAttempts = 10;
this.pluginRegistryUrlEnvName = 'CHE_PLUGIN_REGISTRY_URL';
this.pluginRegistryInternalUrlEnvName = 'CHE_PLUGIN_REGISTRY_INTERNAL_URL';
this.openVSXUrlEnvName = 'OPENVSX_REGISTRY_URL';
this.dashboardUrlEnvName = 'CHE_DASHBOARD_URL';
this.webSocketEventEmitter = new EventEmitter();
this.webSocketEventName = 'websocketClose';
Expand Down Expand Up @@ -252,8 +254,9 @@ export class DevWorkspaceClient extends WorkspaceClient {
devworkspace: devfileApi.DevWorkspace,
devworkspaceTemplate: devfileApi.DevWorkspaceTemplate,
editorId: string | undefined,
pluginRegistryUrl = '',
pluginRegistryInternalUrl = '',
pluginRegistryUrl: string | undefined,
pluginRegistryInternalUrl: string | undefined,
openVSXUrl: string | undefined,
): Promise<any> {
// create DW
devworkspace.spec.routingClass = 'che';
Expand All @@ -274,7 +277,12 @@ export class DevWorkspaceClient extends WorkspaceClient {
devworkspace.spec.started = false;
const createdWorkspace = await DwApi.createWorkspace(devworkspace);

this.addEnvVarsToContainers(components, pluginRegistryUrl, pluginRegistryInternalUrl);
this.addEnvVarsToContainers(
components,
pluginRegistryUrl,
pluginRegistryInternalUrl,
openVSXUrl,
);

// create DWT
devworkspaceTemplate.metadata.namespace = defaultNamespace;
Expand All @@ -291,6 +299,7 @@ export class DevWorkspaceClient extends WorkspaceClient {
devworkspaceTemplate.spec?.components,
pluginRegistryUrl,
pluginRegistryInternalUrl,
openVSXUrl,
);

await DwtApi.createTemplate(devworkspaceTemplate);
Expand All @@ -315,6 +324,7 @@ export class DevWorkspaceClient extends WorkspaceClient {
dwEditorsPlugins: { devfile: devfileApi.Devfile; url: string }[],
pluginRegistryUrl: string | undefined,
pluginRegistryInternalUrl: string | undefined,
openVSXUrl: string | undefined,
editorId: string | undefined,
optionalFilesContent: { [fileName: string]: string },
): Promise<devfileApi.DevWorkspace> {
Expand Down Expand Up @@ -489,6 +499,7 @@ export class DevWorkspaceClient extends WorkspaceClient {
template.spec?.components,
pluginRegistryUrl || '',
pluginRegistryInternalUrl || '',
openVSXUrl,
);

const pluginDWT = await DwtApi.createTemplate(<devfileApi.DevWorkspaceTemplate>template);
Expand All @@ -500,6 +511,7 @@ export class DevWorkspaceClient extends WorkspaceClient {
createdWorkspace.spec.template.components,
pluginRegistryUrl || '',
pluginRegistryInternalUrl || '',
openVSXUrl,
);

const patch = [
Expand All @@ -521,12 +533,14 @@ export class DevWorkspaceClient extends WorkspaceClient {
| V1alpha2DevWorkspaceSpecTemplateComponents[]
| V1alpha2DevWorkspaceTemplateSpecComponents[]
| undefined,
pluginRegistryUrl: string,
pluginRegistryInternalUrl: string,
pluginRegistryUrl: string | undefined,
pluginRegistryInternalUrl: string | undefined,
openVSXUrl: string | undefined,
): void {
if (components === undefined) {
return;
}
const dashboardUrl = window.location.origin;

for (const component of components) {
const container = component.container;
Expand All @@ -537,22 +551,33 @@ export class DevWorkspaceClient extends WorkspaceClient {
env =>
env.name !== this.dashboardUrlEnvName &&
env.name !== this.pluginRegistryUrlEnvName &&
env.name !== this.pluginRegistryInternalUrlEnvName,
env.name !== this.pluginRegistryInternalUrlEnvName &&
env.name !== this.openVSXUrlEnvName,
);
envs.push(
{
if (dashboardUrl) {
envs.push({
name: this.dashboardUrlEnvName,
value: window.location.origin,
},
{
value: dashboardUrl,
});
}
if (pluginRegistryUrl) {
envs.push({
name: this.pluginRegistryUrlEnvName,
value: pluginRegistryUrl,
},
{
});
}
if (pluginRegistryInternalUrl) {
envs.push({
name: this.pluginRegistryInternalUrlEnvName,
value: pluginRegistryInternalUrl,
},
);
});
}
if (openVSXUrl) {
envs.push({
name: this.openVSXUrlEnvName,
value: openVSXUrl,
});
}
container.env = envs;
}
}
Expand Down Expand Up @@ -932,8 +957,9 @@ export class DevWorkspaceClient extends WorkspaceClient {
async checkForTemplatesUpdate(
namespace: string,
pluginsByUrl: { [url: string]: devfileApi.Devfile } = {},
pluginRegistryUrl = '',
pluginRegistryInternalUrl = '',
pluginRegistryUrl: string | undefined,
pluginRegistryInternalUrl: string | undefined,
openVSXUrl: string | undefined,
): Promise<{ [templateName: string]: api.IPatch[] }> {
const templates = await DwtApi.getTemplates(namespace);
const managedTemplates = templates.filter(
Expand Down Expand Up @@ -969,6 +995,7 @@ export class DevWorkspaceClient extends WorkspaceClient {
spec.components,
pluginRegistryUrl,
pluginRegistryInternalUrl,
openVSXUrl,
);
} else {
spec[key] = plugin[key];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ describe('dwPlugins store', () => {
},
],
},
openVSXURL: undefined,
})
.build() as MockStoreEnhanced<
AppState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ describe('dwPlugins store', () => {
},
],
},
openVSXURL: undefined,
},
},
];
Expand Down
13 changes: 3 additions & 10 deletions packages/dashboard-frontend/src/store/ServerConfig/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,11 @@
*/

import { Action, Reducer } from 'redux';
import common, { api } from '@eclipse-che/common';
import common from '@eclipse-che/common';
import { AppThunk } from '../';
import { createObject } from '../helpers';
import * as ServerConfigApi from '../../services/dashboard-backend-client/serverConfigApi';
import { V220DevfileComponents } from '@devfile/api';

export interface ServerConfig {
defaults: {
editor: string | undefined;
components: V220DevfileComponents[];
plugins: api.IWorkspacesDefaultPlugins[];
};
}
import { ServerConfig } from '../../services/dashboard-backend-client/serverConfigApi';

export interface State {
isLoading: boolean;
Expand Down Expand Up @@ -80,6 +72,7 @@ export const actionCreators: ActionCreators = {
const unloadedState: State = {
isLoading: false,
config: {
openVSXURL: undefined,
defaults: {
editor: undefined,
components: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ export const selectDefaultPlugins = createSelector(
state => state.config.defaults?.plugins || [],
);

export const selectOpenVSXUrl = createSelector(selectState, state => state.config.openVSXURL);

export const selectServerConfigError = createSelector(selectState, state => state.error);
Loading

0 comments on commit 33ac2a3

Please sign in to comment.