Skip to content

Commit

Permalink
fix: externalPluginRegistries attribute from CR
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <[email protected]>
  • Loading branch information
olexii4 committed Oct 13, 2023
1 parent bc51275 commit 902bbb3
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 32 deletions.
10 changes: 7 additions & 3 deletions packages/common/src/dto/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ export interface IServerConfig {
disableInternalRegistry: boolean;
externalDevfileRegistries: IExternalDevfileRegistry[];
};
pluginRegistry: {
openVSXURL: string;
};
pluginRegistry: IPluginRegistry;
timeouts: {
inactivityTimeout: number;
runTimeout: number;
Expand All @@ -109,6 +107,12 @@ export interface IServerConfig {
dashboardLogo?: { base64data: string; mediatype: string };
}

export interface IPluginRegistry {
disableInternalRegistry?: boolean;
externalPluginRegistries?: { url: string }[];
openVSXURL: string;
}

export interface IUserProfile {
email: string;
username: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ describe('Server Config API Service', () => {
expect(res).toEqual([{ container: { image: 'component-image' }, name: 'component-name' }]);
});

test('getting openVSXURL', () => {
const res = serverConfigService.getOpenVSXURL(buildCustomResource());
expect(res).toEqual('https://open-vsx.org');
test('getting pluginRegistry', () => {
const res = serverConfigService.getPluginRegistry(buildCustomResource());
expect(res).toEqual({ openVSXURL: 'https://open-vsx.org' });
});

test('getting PVC strategy', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,25 @@ export class ServerConfigApiService implements IServerConfigApi {
return [];
}

getOpenVSXURL(cheCustomResource: CustomResourceDefinition): string {
getPluginRegistry(cheCustomResource: CustomResourceDefinition): api.IPluginRegistry {
// Undefined and empty value are treated in a different ways:
// - empty value forces to use embedded registry
// - undefined value means that the default value should be used
if (cheCustomResource.spec.components?.pluginRegistry?.openVSXURL !== undefined) {
return cheCustomResource.spec.components.pluginRegistry.openVSXURL;

const pluginRegistry = cheCustomResource.spec.components?.pluginRegistry
? cheCustomResource.spec.components.pluginRegistry
: ({ openVSXURL: '' } as api.IPluginRegistry);

const openVSXURL =
cheCustomResource.spec.components?.pluginRegistry?.openVSXURL !== undefined
? pluginRegistry.openVSXURL
: process.env['CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL'];

if (openVSXURL) {
pluginRegistry.openVSXURL = openVSXURL;
}

return process.env['CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL'] || '';
return pluginRegistry;
}

getPvcStrategy(cheCustomResource: CustomResourceDefinition): string | undefined {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ export type CustomResourceDefinitionSpecComponents = {
devWorkspace?: {
runningLimit?: number;
};
pluginRegistry?: {
openVSXURL?: string;
};
pluginRegistry?: api.IPluginRegistry;
devfileRegistry: {
disableInternalRegistry?: boolean;
externalDevfileRegistries?: api.IExternalDevfileRegistry[];
Expand Down Expand Up @@ -205,9 +203,9 @@ export interface IServerConfigApi {
*/
getDefaultComponents(cheCustomResource: CustomResourceDefinition): V221DevfileComponents[];
/**
* Returns the openVSX URL.
* Returns the plugin registry.
*/
getOpenVSXURL(cheCustomResource: CustomResourceDefinition): string;
getPluginRegistry(cheCustomResource: CustomResourceDefinition): api.IPluginRegistry;
/**
* Returns the internal registry disable status.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const stubDashboardWarning = 'Dashboard warning';
export const stubDefaultComponents: V221DevfileComponents[] = [];
export const stubDefaultEditor = undefined;
export const stubDefaultPlugins: api.IWorkspacesDefaultPlugins[] = [];
export const stubOpenVSXURL = 'openvsx-url';
export const stubPluginRegistry = { openVSXURL: 'openvsx-url' };
export const stubPvcStrategy = '';
export const stubRunningWorkspacesLimit = 2;
export const stubAllWorkspacesLimit = 1;
Expand Down Expand Up @@ -122,7 +122,7 @@ export function getDevWorkspaceClient(
getDefaultComponents: _cheCustomResource => stubDefaultComponents,
getDefaultEditor: _cheCustomResource => stubDefaultEditor,
getDefaultPlugins: _cheCustomResource => stubDefaultPlugins,
getOpenVSXURL: _cheCustomResource => stubOpenVSXURL,
getPluginRegistry: _cheCustomResource => stubPluginRegistry,
getPvcStrategy: _cheCustomResource => stubPvcStrategy,
getRunningWorkspacesLimit: _cheCustomResource => stubRunningWorkspacesLimit,
getAllWorkspacesLimit: _cheCustomResource => stubAllWorkspacesLimit,
Expand Down
6 changes: 2 additions & 4 deletions packages/dashboard-backend/src/routes/api/serverConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function registerServerConfigRoute(instance: FastifyInstance) {
const inactivityTimeout = serverConfigApi.getWorkspaceInactivityTimeout(cheCustomResource);
const runTimeout = serverConfigApi.getWorkspaceRunTimeout(cheCustomResource);
const startTimeout = serverConfigApi.getWorkspaceStartTimeout(cheCustomResource);
const openVSXURL = serverConfigApi.getOpenVSXURL(cheCustomResource);
const pluginRegistry = serverConfigApi.getPluginRegistry(cheCustomResource);
const pvcStrategy = serverConfigApi.getPvcStrategy(cheCustomResource);
const pluginRegistryURL = serverConfigApi.getDefaultPluginRegistryUrl(cheCustomResource);
const devfileRegistryURL = serverConfigApi.getDefaultDevfileRegistryUrl(cheCustomResource);
Expand All @@ -66,9 +66,7 @@ export function registerServerConfigRoute(instance: FastifyInstance) {
disableInternalRegistry,
externalDevfileRegistries,
},
pluginRegistry: {
openVSXURL,
},
pluginRegistry,
cheNamespace,
pluginRegistryURL,
pluginRegistryInternalURL,
Expand Down
7 changes: 4 additions & 3 deletions packages/dashboard-frontend/src/services/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import * as PodsStore from '@/store/Pods';
import { selectPodsResourceVersion } from '@/store/Pods/selectors';
import * as SanityCheckStore from '@/store/SanityCheck';
import * as ServerConfigStore from '@/store/ServerConfig';
import { selectOpenVSXUrl } from '@/store/ServerConfig/selectors';
import { selectOpenVSXUrl, selectPluginRegistryUrl } from '@/store/ServerConfig/selectors';
import * as UserProfileStore from '@/store/User/Profile';
import * as WorkspacesStore from '@/store/Workspaces';
import * as DevWorkspacesStore from '@/store/Workspaces/devWorkspaces';
Expand Down Expand Up @@ -271,7 +271,8 @@ export default class Bootstrap {

private async fetchPlugins(): Promise<void> {
const { requestPlugins } = PluginsStore.actionCreators;
const pluginRegistryURL = this.store.getState().dwServerConfig.config.pluginRegistryURL;
const state = this.store.getState();
const pluginRegistryURL = selectPluginRegistryUrl(state);
await requestPlugins(pluginRegistryURL)(this.store.dispatch, this.store.getState, undefined);
}

Expand Down Expand Up @@ -307,7 +308,7 @@ export default class Bootstrap {
pluginsByUrl[dwEditor.url] = dwEditor.devfile;
});
const openVSXUrl = selectOpenVSXUrl(state);
const pluginRegistryUrl = state.dwServerConfig.config.pluginRegistryURL;
const pluginRegistryUrl = selectPluginRegistryUrl(state);
const pluginRegistryInternalUrl = state.dwServerConfig.config.pluginRegistryInternalURL;
const clusterConsole = selectApplications(state).find(
app => app.id === ApplicationId.CLUSTER_CONSOLE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ export class DevWorkspaceClient {
}
}

const openVSXURL = config.pluginRegistry.openVSXURL;
const openVSXURL = config.pluginRegistry?.openVSXURL || '';
const components = cloneDeep(workspace.spec.template.components);
if (components) {
let shouldUpdate = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { fetchData } from '@/services/registry/fetchData';
import { AppThunk } from '@/store';
import { createObject } from '@/store/helpers';
import { AUTHORIZED, SanityCheckAction } from '@/store/sanityCheckMiddleware';
import { selectPluginRegistryUrl } from '@/store/ServerConfig/selectors';

export interface PluginDefinition {
plugin?: devfileApi.Devfile;
Expand Down Expand Up @@ -161,7 +162,7 @@ export const actionCreators: ActionCreators = {
if (editorName.startsWith('https://')) {
editorUrl = editorName;
} else {
const pluginRegistryUrl = getState().dwServerConfig.config.pluginRegistryURL;
const pluginRegistryUrl = selectPluginRegistryUrl(getState());
editorUrl = `${pluginRegistryUrl}/plugins/${editorName}/devfile.yaml`;

if (!pluginRegistryUrl) {
Expand Down Expand Up @@ -224,9 +225,10 @@ export const actionCreators: ActionCreators = {
throw errorMessage;
}

const pluginRegistryURL = selectPluginRegistryUrl(getState());
const defaultEditorUrl = (defaultEditor as string).startsWith('https://')
? defaultEditor
: `${config.pluginRegistryURL}/plugins/${defaultEditor}/devfile.yaml`;
: `${pluginRegistryURL}/plugins/${defaultEditor}/devfile.yaml`;

// request default editor
await dispatch(actionCreators.requestDwEditor(defaultEditor));
Expand Down
10 changes: 6 additions & 4 deletions packages/dashboard-frontend/src/store/ServerConfig/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ export const selectDefaultPlugins = createSelector(
state => state.config.defaults?.plugins || [],
);

export const selectPluginRegistryUrl = createSelector(
selectState,
state => state.config.pluginRegistryURL,
);
export const selectPluginRegistryUrl = createSelector(selectState, state => {
const pluginRegistryUrl = !state.config.pluginRegistry.disableInternalRegistry
? state.config.pluginRegistryURL
: state.config.pluginRegistry.externalPluginRegistries?.[0]?.url;
return pluginRegistryUrl || '';
});

export const selectPluginRegistryInternalUrl = createSelector(
selectState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ export const actionCreators: ActionCreators = {
): AppThunk<KnownAction, Promise<void>> =>
async (dispatch, getState): Promise<void> => {
const state = getState();
const pluginRegistryUrl = state.dwServerConfig.config.pluginRegistryURL;
const pluginRegistryUrl = selectPluginRegistryUrl(state);
let devWorkspaceResource: devfileApi.DevWorkspace;
let devWorkspaceTemplateResource: devfileApi.DevWorkspaceTemplate;
let editorContent: string | undefined;
Expand Down

0 comments on commit 902bbb3

Please sign in to comment.