Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provides OpenVSX CheCluster URL to user containers #609

Merged
merged 4 commits into from
Aug 23, 2022
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
17 changes: 17 additions & 0 deletions packages/common/src/dto/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* Red Hat, Inc. - initial API and implementation
*/

import { V220DevfileComponents } from '@devfile/api';

export interface IPatch {
op: string;
path: string;
Expand All @@ -25,3 +27,18 @@ export interface IWorkspacesDefaultPlugins {
editor: string;
plugins: string[];
}

export interface IServerConfig {
defaults: {
editor: string | undefined;
components: V220DevfileComponents[];
plugins: IWorkspacesDefaultPlugins[];
};
pluginRegistry: {
openVSXURL: string;
};
timeouts: {
inactivityTimeout: number;
runTimeout: number;
};
}
10 changes: 9 additions & 1 deletion packages/dashboard-backend/src/api/serverConfigApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { FastifyInstance } from 'fastify';
import { baseApiPath } from '../constants/config';
import { getDevWorkspaceClient, getServiceAccountToken } from './helper';
import { getSchema } from '../services/helpers';
import { api } from '@eclipse-che/common';

const tags = ['Server Config'];

Expand All @@ -28,7 +29,9 @@ export function registerServerConfigApi(server: FastifyInstance) {
const components = serverConfigApi.getDefaultComponents(cheCustomResource);
const inactivityTimeout = serverConfigApi.getWorkspaceInactivityTimeout(cheCustomResource);
const runTimeout = serverConfigApi.getWorkspaceRunTimeout(cheCustomResource);
return {
const openVSXURL = serverConfigApi.getOpenVSXURL(cheCustomResource);

const serverConfig: api.IServerConfig = {
defaults: {
editor,
plugins,
Expand All @@ -38,6 +41,11 @@ export function registerServerConfigApi(server: FastifyInstance) {
inactivityTimeout,
runTimeout,
},
pluginRegistry: {
openVSXURL,
},
};

return serverConfig;
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export class ServerConfigApi implements IServerConfigApi {
return cheCustomResource.spec.devEnvironments.defaultComponents || [];
}

getOpenVSXURL(cheCustomResource: { [key: string]: any }): string {
return cheCustomResource.spec.components.pluginRegistry?.openVSXURL || '';
}

getDashboardWarning(cheCustomResource: { [key: string]: any }): string | undefined {
if (!cheCustomResource.spec.components.dashboard.headerMessage?.show) {
return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,16 @@ 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;
/**
* 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;

Expand All @@ -134,7 +138,7 @@ export interface IServerConfigApi {

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
7 changes: 5 additions & 2 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 { buildDetailsLocation, buildIdeLoaderLocation } from '../helpers/location';
import { Workspace } from '../workspace-adapter';
import { WorkspaceRunningError, WorkspaceStoppedDetector } from './workspaceStoppedDetector';
import { selectOpenVSXUrl } from '../../store/ServerConfig/selectors';

/**
* This class executes a few initial instructions
Expand Down Expand Up @@ -216,14 +217,16 @@ export default class Bootstrap {
selectDwEditorsPluginsList(state.dwPlugins.defaultEditorName)(state).forEach(dwEditor => {
pluginsByUrl[dwEditor.url] = dwEditor.devfile;
});
const openVSXUrl = selectOpenVSXUrl(state);
const settings = this.store.getState().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 @@ -11,10 +11,8 @@
*/

import axios from 'axios';
import common from '@eclipse-che/common';
import common, { api } from '@eclipse-che/common';
import { prefix } from './const';
import { api } from '@eclipse-che/common';
import { V220DevfileComponents } from '@devfile/api';

/**
* Returns an array of default plug-ins per editor
Expand All @@ -23,17 +21,7 @@ import { V220DevfileComponents } from '@devfile/api';
* 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;
};
timeouts: {
inactivityTimeout: number;
runTimeout: number;
};
}> {
export async function getServerConfig(): Promise<api.IServerConfig> {
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 @@ -138,6 +138,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 @@ -157,6 +158,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 @@ -255,8 +257,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 @@ -277,7 +280,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 @@ -294,6 +302,7 @@ export class DevWorkspaceClient extends WorkspaceClient {
devworkspaceTemplate.spec?.components,
pluginRegistryUrl,
pluginRegistryInternalUrl,
openVSXUrl,
);

await DwtApi.createTemplate(devworkspaceTemplate);
Expand All @@ -318,6 +327,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 @@ -490,8 +500,9 @@ export class DevWorkspaceClient extends WorkspaceClient {
];
this.addEnvVarsToContainers(
template.spec?.components,
pluginRegistryUrl || '',
pluginRegistryInternalUrl || '',
pluginRegistryUrl,
pluginRegistryInternalUrl,
openVSXUrl,
);

const pluginDWT = await DwtApi.createTemplate(<devfileApi.DevWorkspaceTemplate>template);
Expand All @@ -501,8 +512,9 @@ export class DevWorkspaceClient extends WorkspaceClient {

this.addEnvVarsToContainers(
createdWorkspace.spec.template.components,
pluginRegistryUrl || '',
pluginRegistryInternalUrl || '',
pluginRegistryUrl,
pluginRegistryInternalUrl,
openVSXUrl,
);

const patch = [
Expand All @@ -524,13 +536,16 @@ 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;
if (container === undefined) {
Expand All @@ -540,22 +555,31 @@ 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(
{
name: this.dashboardUrlEnvName,
value: window.location.origin,
},
{
envs.push({
name: this.dashboardUrlEnvName,
value: dashboardUrl,
});
if (pluginRegistryUrl !== undefined) {
envs.push({
name: this.pluginRegistryUrlEnvName,
value: pluginRegistryUrl,
},
{
});
}
if (pluginRegistryInternalUrl !== undefined) {
envs.push({
name: this.pluginRegistryInternalUrlEnvName,
value: pluginRegistryInternalUrl,
},
);
});
}
if (openVSXUrl !== undefined) {
envs.push({
name: this.openVSXUrlEnvName,
value: openVSXUrl,
});
}
container.env = envs;
}
}
Expand Down Expand Up @@ -938,8 +962,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 @@ -975,6 +1000,7 @@ export class DevWorkspaceClient extends WorkspaceClient {
spec.components,
pluginRegistryUrl,
pluginRegistryInternalUrl,
openVSXUrl,
);
} else {
spec[key] = plugin[key];
Expand Down
Loading