Skip to content

Commit

Permalink
handle cheEditor component in addition to chePlugin (eclipse-che#1084)
Browse files Browse the repository at this point in the history
Signed-off-by: svor <vsvydenk@redhat.com>
  • Loading branch information
svor committed Apr 22, 2021
1 parent adee6ba commit 1683b85
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class CheServerDevfileServiceImpl implements DevfileService {
const devfileV1Component: cheApi.workspace.devfile.Component = {};

if (componentV2.plugin) {
devfileV1Component.type = 'chePlugin';
devfileV1Component.type = componentV2.attributes?.['source-origin'] || 'chePlugin';

if (componentV2.plugin.memoryLimit) {
devfileV1Component.memoryLimit = componentV2.plugin.memoryLimit;
Expand Down Expand Up @@ -290,8 +290,13 @@ export class CheServerDevfileServiceImpl implements DevfileService {
devfileV2Component.container.env = this.componentEnvV1toComponentEnvV2(componentV1.env);
devfileV2Component.container.volumeMounts = this.componentVolumeV1toComponentVolumeV2(componentV1.volumes);
devfileV2Component.container.endpoints = this.componentEndpointV1toComponentEndpointV2(componentV1.endpoints);
} else if (componentV1.type === 'chePlugin') {
} else if (componentV1.type === 'chePlugin' || componentV1.type === 'cheEditor') {
devfileV2Component.plugin = {};
if (!devfileV2Component.attributes) {
devfileV2Component.attributes = {};
}
devfileV2Component.attributes['source-origin'] = componentV1.type;

if (componentV1.id) {
devfileV2Component.plugin.id = componentV1.id;
}
Expand Down Expand Up @@ -655,10 +660,7 @@ export class CheServerDevfileServiceImpl implements DevfileService {
const workspace = await this.workspaceService.currentWorkspace();

// convert devfile v2 to devfile v1
const devfileV1 = {
projects: (devfile.projects || []).map(project => this.projectV2toProjectV1(project)),
components: [],
};
const devfileV1 = this.devfileV2toDevfileV1(devfile);

workspace.devfile = devfileV1;
await this.workspaceService.updateWorkspace(workspace.id!, workspace);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
apiVersion: "1.0.0",
metadata: { generateName: "hello" },
projects:
[
{
name: "my-project",
source:
{
type: "git",
location: "https://github.com/this-is-a-test",
branch: "myBranch",
},
},
],
components: [{ type: "cheEditor", reference: "https://reference" }],
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,16 @@ describe('Test CheServerDevfileServiceImpl', () => {
expect(convertedDevfileV1).toEqual(devfileV1);
});

test('convert v1/v2 custom editor devfile.yaml', async () => {
const cheTheiaDevfileYamlPath = path.resolve(__dirname, '..', '_data', 'devfile-custom-editor.yaml');
const devfileContent = await fs.readFile(cheTheiaDevfileYamlPath, 'utf-8');
const devfileV1 = jsYaml.safeLoad(devfileContent);

const convertedDevfileV2 = cheServerDevfileServiceImpl.devfileV1toDevfileV2(devfileV1);
const convertedDevfileV1 = cheServerDevfileServiceImpl.devfileV2toDevfileV1(convertedDevfileV2);
expect(convertedDevfileV1).toEqual(devfileV1);
});

test('getComponentStatus', async () => {
const workspaceJsonPath = path.resolve(__dirname, '..', '_data', 'workspace-status-runtime.json');
const workspaceJsonContent = await fs.readFile(workspaceJsonPath, 'utf-8');
Expand Down

0 comments on commit 1683b85

Please sign in to comment.