Skip to content

Commit

Permalink
fix: keep devworkspace attributes when restarting from local devfile (#…
Browse files Browse the repository at this point in the history
…465)

Signed-off-by: vitaliy-guliy <[email protected]>
  • Loading branch information
vitaliy-guliy authored Dec 9, 2024
1 parent 889077c commit 311493a
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions code/extensions/che-remote/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,34 @@ async function updateDevfile(cheApi: any): Promise<boolean> {
return false;
}

// if a new Devfile does not contain projects, copy them from flattened Devfile
let flattenedDevfile: any;

try {
const flattenedDevfileContent = await fs.readFile(process.env.DEVWORKSPACE_FLATTENED_DEVFILE!, 'utf8');
flattenedDevfile = jsYaml.load(flattenedDevfileContent) as any;
} catch (error) {
await vscode.window.showErrorMessage(`Failed to read Devfile. ${error}`);
return false;
}

try {
// if a new Devfile does not contain projects, copy them from flattened Devfile
let projects: V1alpha2DevWorkspaceSpecTemplateProjects[] | undefined = devfileContext.devWorkspace.spec!.template!.projects;
if (!projects || projects.length === 0) {
const flattenedDevfileContent = await fs.readFile(process.env.DEVWORKSPACE_FLATTENED_DEVFILE!, 'utf8');
const flattenedDevfile = jsYaml.load(flattenedDevfileContent) as any;
if (flattenedDevfile.projects) {
devfileContext.devWorkspace.spec!.template!.projects = flattenedDevfile.projects;
}
if ((!projects || projects.length === 0) && flattenedDevfile.projects) {
devfileContext.devWorkspace.spec!.template!.projects = flattenedDevfile.projects;
}
} catch (error) {
await vscode.window.showErrorMessage(`Failed to read Devfile. ${error}`);
await vscode.window.showErrorMessage(`Failed to update DevWorkspace projects. ${error}`);
return false;
}

try {
// keep spec.template.attributes
if (!devfileContext.devWorkspace.spec!.template!.attributes) {
devfileContext.devWorkspace.spec!.template!.attributes = flattenedDevfile.attributes;
}
} catch (error) {
await vscode.window.showErrorMessage(`Failed to update DevWorkspace attributes. ${error}`);
return false;
}

Expand Down

0 comments on commit 311493a

Please sign in to comment.