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

Add a new workspace creation URL parameter #1037

Merged
merged 3 commits into from
Jan 18, 2024
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
1 change: 1 addition & 0 deletions .deps/EXCLUDED/prod.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ This file lists dependencies that do not need CQs or auto-detection does not wor
| Packages | Resolved CQs |
| --- | --- |
| `@fastify/[email protected]` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@fastify/cors/8.4.1) |
| `@fastify/reply-from@^9.6.0` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@fastify/reply-from/9.6.0) |
| `@patternfly/[email protected]` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@patternfly/react-core/4.278.0) |
| `@patternfly/[email protected]` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@patternfly/react-table/4.113.6) |
| `@patternfly/[email protected]` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@patternfly/react-icons/4.93.7) |
Expand Down
4 changes: 2 additions & 2 deletions .deps/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@
| [`[email protected]`](git+https://github.com/ljharb/safe-regex-test.git) | MIT | clearlydefined |
| [`[email protected]`](https://github.com/lddubeau/saxes.git) | ISC | clearlydefined |
| [`[email protected]`](https://github.com/webpack/schema-utils.git) | MIT | #8986 |
| [`[email protected]`](git+https://github.com/yahoo/serialize-javascript.git) | BSD-3-Clause | clearlydefined |
| [`[email protected]`](git+https://github.com/yahoo/serialize-javascript.git) | BSD-3-Clause | #12680 |
| [`[email protected]`](git+https://github.com/yargs/set-blocking.git) | ISC | #5899 |
| [`[email protected]`](git+https://github.com/ljharb/set-function-name.git) | MIT | #10590 |
| [`[email protected]`](https://github.com/jonschlinkert/shallow-clone.git) | MIT | clearlydefined |
Expand Down Expand Up @@ -852,7 +852,7 @@
| [`[email protected]`](https://github.com/sindresorhus/strip-final-newline.git) | MIT | clearlydefined |
| [`[email protected]`](https://github.com/sindresorhus/strip-indent.git) | MIT | clearlydefined |
| [`[email protected]`](git://github.com/strongloop/strong-log-transformer) | Apache-2.0 | #1138 |
| [`[email protected]`](https://github.com/webpack-contrib/style-loader.git) | MIT | clearlydefined |
| [`[email protected]`](https://github.com/webpack-contrib/style-loader.git) | MIT | #12669 |
| [`[email protected]`](git+https://github.com/davidtheclark/style-search.git) | ISC | clearlydefined |
| [`[email protected]`](https://github.com/cssnano/cssnano.git) | MIT | clearlydefined |
| [`[email protected]`](https://github.com/kutsan/stylelint-config-clean-order.git) | MIT | clearlydefined |
Expand Down
10 changes: 5 additions & 5 deletions .deps/prod.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
| [`@devfile/[email protected]`](https://github.com/devfile/api.git) | EPL-2.0 | clearlydefined |
| `@eclipse-che/[email protected]` | EPL-2.0 | ecd.che |
| [`@eclipse-che/[email protected]`](git+https://github.com/eclipse-che/che-devfile-registry.git) | EPL-2.0 | ecd.che |
| [`@eclipse-che/common@7.79.0-next`](https://github.com/eclipse-che/che-dashboard) | EPL-2.0 | ecd.che |
| [`@eclipse-che/dashboard-backend@7.79.0-next`](https://github.com/eclipse-che/che-dashboard) | EPL-2.0 | ecd.che |
| [`@eclipse-che/dashboard-frontend@7.79.0-next`](git://github.com/eclipse/che-dashboard.git) | EPL-2.0 | ecd.che |
| [`@eclipse-che/common@7.81.0-next`](https://github.com/eclipse-che/che-dashboard) | EPL-2.0 | ecd.che |
| [`@eclipse-che/dashboard-backend@7.81.0-next`](https://github.com/eclipse-che/che-dashboard) | EPL-2.0 | ecd.che |
| [`@eclipse-che/dashboard-frontend@7.81.0-next`](git://github.com/eclipse/che-dashboard.git) | EPL-2.0 | ecd.che |
| [`@eclipse-che/[email protected]`](git+https://github.com/che-incubator/devfile-converter.git) | EPL-2.0 | ecd.che |
| [`@fastify/[email protected]`](git+https://github.com/fastify/accept-negotiator.git) | MIT | clearlydefined |
| [`@fastify/[email protected]`](git+https://github.com/fastify/ajv-compiler.git) | MIT | clearlydefined |
Expand All @@ -20,7 +20,7 @@
| [`@fastify/[email protected]`](git+https://github.com/fastify/fast-json-stringify-compiler.git) | MIT | clearlydefined |
| [`@fastify/[email protected]`](git+https://github.com/fastify/fastify-http-proxy.git) | MIT | clearlydefined |
| [`@fastify/[email protected]`](git+https://github.com/fastify/fastify-oauth2.git) | MIT | clearlydefined |
| [`@fastify/reply-from@9.4.0`](git+https://github.com/fastify/fastify-reply-from.git) | MIT | clearlydefined |
| [`@fastify/reply-from@9.6.0`](git+https://github.com/fastify/fastify-reply-from.git) | MIT | clearlydefined |
| [`@fastify/[email protected]`](git+https://github.com/fastify/send.git) | MIT | clearlydefined |
| [`@fastify/[email protected]`](https://github.com/fastify/fastify-static.git) | MIT | clearlydefined |
| [`@fastify/[email protected]`](git+https://github.com/fastify/fastify-swagger-ui.git) | MIT | clearlydefined |
Expand Down Expand Up @@ -170,7 +170,7 @@
| [`[email protected]`](https://github.com/react-dropzone/file-selector.git) | MIT | [CQ22350](https://dev.eclipse.org/ipzilla/show_bug.cgi?id=22350) |
| [`[email protected]`](git+https://github.com/delvedor/find-my-way.git) | MIT | clearlydefined |
| [`[email protected]`](git+https://github.com/focus-trap/focus-trap.git) | MIT | clearlydefined |
| [`[email protected].3`]([email protected]:follow-redirects/follow-redirects.git) | MIT | #10782 |
| [`[email protected].4`]([email protected]:follow-redirects/follow-redirects.git) | MIT | #10782 |
| [`[email protected]`](https://github.com/mikeal/forever-agent) | Apache-2.0 | clearlydefined |
| [`[email protected]`](git://github.com/form-data/form-data.git) | MIT | clearlydefined |
| [`[email protected]`](https://github.com/jshttp/forwarded.git) | MIT | clearlydefined |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class CreatingStepApplyResources extends ProgressStep<Props, State> {
return false;
}

await this.props.createWorkspaceFromResources(...resources, cheEditor);
await this.props.createWorkspaceFromResources(...resources, factoryParams, cheEditor);

// wait for the workspace creation to complete
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ describe('test buildFactoryLoaderPath()', () => {
);
});

test('editor-image parameter', () => {
const result = buildFactoryLoaderPath(
'[email protected]:eclipse-che/che-dashboard.git?editor-image=quay.io/mloriedo/che-code:copilot-builtin',
);
expect(result).toEqual(
'/f?editor-image=quay.io%2Fmloriedo%2Fche-code%3Acopilot-builtin&url=git%40github.com%3Aeclipse-che%2Fche-dashboard.git',
);
});

test('devfilePath parameter', () => {
const result = buildFactoryLoaderPath(
'[email protected]:eclipse-che/che-dashboard.git?devfilePath=devfilev2.yaml',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const POLICIES_CREATE_ATTR = 'policies.create';
export const STORAGE_TYPE_ATTR = 'storageType';
export const REMOTES_ATTR = 'remotes';
export const IMAGE_ATTR = 'image';
export const EDITOR_IMAGE_ATTR = 'editor-image';
export const USE_DEFAULT_DEVFILE = 'useDefaultDevfile';
export const DEBUG_WORKSPACE_START = 'debugWorkspaceStart';
export const PROPAGATE_FACTORY_ATTRS = [
Expand All @@ -30,6 +31,7 @@ export const PROPAGATE_FACTORY_ATTRS = [
STORAGE_TYPE_ATTR,
REMOTES_ATTR,
IMAGE_ATTR,
EDITOR_IMAGE_ATTR,
];
export const OVERRIDE_ATTR_PREFIX = 'override.';
export const DEFAULT_POLICIES_CREATE = 'peruser';
Expand All @@ -44,6 +46,7 @@ export type FactoryParams = {
errorCode: ErrorCode | undefined;
storageType: che.WorkspaceStorageType | undefined;
cheEditor: string | undefined;
editorImage: string | undefined;
remotes: string | undefined;
image: string | undefined;
useDefaultDevfile: boolean;
Expand All @@ -57,6 +60,7 @@ export type ErrorCode = 'invalid_request' | 'access_denied';
export function buildFactoryParams(searchParams: URLSearchParams): FactoryParams {
return {
cheEditor: getEditorId(searchParams),
editorImage: getEditorImage(searchParams),
errorCode: getErrorCode(searchParams),
factoryId: buildFactoryId(searchParams),
factoryUrl: getFactoryUrl(searchParams),
Expand Down Expand Up @@ -106,6 +110,10 @@ function getEditorId(searchParams: URLSearchParams): string | undefined {
return searchParams.get(EDITOR_ATTR) || undefined;
}

function getEditorImage(searchParams: URLSearchParams): string | undefined {
return searchParams.get(EDITOR_IMAGE_ATTR) || undefined;
}

function getErrorCode(searchParams: URLSearchParams): ErrorCode | undefined {
return (searchParams.get(ERROR_CODE_ATTR) as ErrorCode) || undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,11 @@ describe('DevWorkspace store, actions', () => {
mockOnStart.mockResolvedValueOnce(undefined);

await store.dispatch(
testStore.actionCreators.createWorkspaceFromResources(devWorkspace, devWorkspaceTemplate),
testStore.actionCreators.createWorkspaceFromResources(
devWorkspace,
devWorkspaceTemplate,
{},
),
);

const actions = store.getActions();
Expand Down Expand Up @@ -843,7 +847,11 @@ describe('DevWorkspace store, actions', () => {

try {
await store.dispatch(
testStore.actionCreators.createWorkspaceFromResources(devWorkspace, devWorkspaceTemplate),
testStore.actionCreators.createWorkspaceFromResources(
devWorkspace,
devWorkspaceTemplate,
{},
),
);
} catch (e) {
// no-op
Expand Down Expand Up @@ -891,7 +899,11 @@ describe('DevWorkspace store, actions', () => {

it('should provide default editor id when creating a new workspace from resources', async () => {
await store.dispatch(
testStore.actionCreators.createWorkspaceFromResources(devWorkspace, devWorkspaceTemplate),
testStore.actionCreators.createWorkspaceFromResources(
devWorkspace,
devWorkspaceTemplate,
{},
),
);

expect(mockCreateDevWorkspace).toHaveBeenCalledWith(
Expand All @@ -906,6 +918,7 @@ describe('DevWorkspace store, actions', () => {
testStore.actionCreators.createWorkspaceFromResources(
devWorkspace,
devWorkspaceTemplate,
{},
'editorid',
),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/*
* Copyright (c) 2018-2024 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/

import common from '@eclipse-che/common';
import fs from 'fs';
import { dump, load } from 'js-yaml';

import devfileApi from '@/services/devfileApi';
import { DevWorkspaceBuilder } from '@/store/__mocks__/devWorkspaceBuilder';
import {
getEditorImage,
updateDevWorkspaceTemplate,
updateEditorDevfile,
} from '@/store/Workspaces/devWorkspaces/editorImage';

describe('Update editor image', () => {
describe('devfile source annotation', () => {
it('should return undefined without devfile-source', () => {
const devWorkspace = new DevWorkspaceBuilder()
.withTemplateAttributes({
'dw.metadata.annotations': {},
})
.build();

const editorImageParam = getEditorImage(devWorkspace);

expect(editorImageParam).toBeUndefined();
});

it('should return undefined without factory params', () => {
const devWorkspace = new DevWorkspaceBuilder()
.withTemplateAttributes({
'dw.metadata.annotations': {
'che.eclipse.org/devfile-source': dump({
factory: {},
}),
},
})
.build();

const editorImageParam = getEditorImage(devWorkspace);

expect(editorImageParam).toBeUndefined();
});

it('should return the editor image param', () => {
const devWorkspace = new DevWorkspaceBuilder()
.withTemplateAttributes({
'dw.metadata.annotations': {
'che.eclipse.org/devfile-source': dump({
factory: {
params:
'editor-image=test-images/che-code:tag&url=https://github.com/eclipse-che/che-dashboard',
},
}),
},
})
.build();

const editorImageParam = getEditorImage(devWorkspace);

expect(editorImageParam).toStrictEqual('test-images/che-code:tag');
});
});

describe('editor devfile', () => {
it('should throw an error if editorContent is not defined', () => {
const customEditorImage = 'test-images/che-code:tag';

const editorContent = '';

let errorMessage: string | undefined;
try {
updateEditorDevfile(editorContent, customEditorImage);
} catch (err) {
errorMessage = common.helpers.errors.getMessage(err);
}

expect(errorMessage).toEqual('Editor content is empty.');
});

it('should throw an error if editor components are not defined', () => {
const customEditorImage = 'test-images/che-code:tag';

const editorContent = fs.readFileSync(
__dirname + '/fixtures/test-devfile-without-components.yaml',
'utf-8',
);

let errorMessage: string | undefined;
try {
updateEditorDevfile(editorContent, customEditorImage);
} catch (err) {
errorMessage = common.helpers.errors.getMessage(err);
}

expect(errorMessage).toEqual(
'Failed to update editor image. Editor components is not defined.',
);
});

it('should update the target image', () => {
const customEditorImage = 'test-images/che-code:tag';

const editorContent = fs.readFileSync(
__dirname + '/fixtures/test-editor-devfile.yaml',
'utf-8',
);

const customEditorContent = updateEditorDevfile(editorContent, customEditorImage);

const output = fs.readFileSync(
__dirname + '/fixtures/test-editor-devfile-with-custom-image.yaml',
'utf-8',
);

expect(customEditorContent).toStrictEqual(output);
});
});

describe('devWorkspace template', () => {
it('should throw an error if editor components are not defined', () => {
const customEditorImage = 'test-images/che-code:tag';

const devWorkspaceTemplate = load(
fs.readFileSync(
__dirname + '/fixtures/test-devworkspace-template-without-components.yaml',
'utf-8',
),
) as devfileApi.DevWorkspaceTemplate;

let errorMessage: string | undefined;
try {
updateDevWorkspaceTemplate(devWorkspaceTemplate, customEditorImage);
} catch (err) {
errorMessage = common.helpers.errors.getMessage(err);
}

expect(errorMessage).toEqual(
'Failed to update editor image. Editor components is not defined.',
);
});

it('should update the target image', () => {
const customEditorImage = 'test-images/che-code:tag';

const devWorkspaceTemplate = load(
fs.readFileSync(__dirname + '/fixtures/test-devworkspace-template.yaml', 'utf-8'),
) as devfileApi.DevWorkspaceTemplate;

const customEditorContent = updateDevWorkspaceTemplate(
devWorkspaceTemplate,
customEditorImage,
);

const output = load(
fs.readFileSync(
__dirname + '/fixtures/test-devworkspace-template-with-custom-image.yaml',
'utf-8',
),
);

expect(customEditorContent).toStrictEqual(output);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
schemaVersion: 2.2.0
metadata:
name: che-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: workspace.devfile.io/v1alpha2
kind: DevWorkspaceTemplate
metadata:
annotations:
che.eclipse.org/components-update-policy: manual
name: che-code
spec:
components:
- attributes:
controller.devfile.io/container-contribution: true
container:
image: test-images/che-code:tag
name: che-code-runtime-description
- name: checode
volume: {}
- container:
image: quay.io/che-incubator/che-code:next
name: che-code-injector
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: workspace.devfile.io/v1alpha2
kind: DevWorkspaceTemplate
metadata:
annotations:
che.eclipse.org/components-update-policy: managed
name: che-code
spec: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: workspace.devfile.io/v1alpha2
kind: DevWorkspaceTemplate
metadata:
annotations:
che.eclipse.org/components-update-policy: managed
name: che-code
spec:
components:
- attributes:
controller.devfile.io/container-contribution: true
container:
image: quay.io/devfile/universal-developer-image:next
name: che-code-runtime-description
- name: checode
volume: {}
- container:
image: quay.io/che-incubator/che-code:next
name: che-code-injector
Loading
Loading