From 311493a2a4e0e27af78669f6a41cfbd94d4d7752 Mon Sep 17 00:00:00 2001 From: Vitaliy Gulyy Date: Mon, 9 Dec 2024 18:53:28 +0200 Subject: [PATCH] fix: keep devworkspace attributes when restarting from local devfile (#465) Signed-off-by: vitaliy-guliy --- code/extensions/che-remote/src/extension.ts | 32 +++++++++++++++------ 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/code/extensions/che-remote/src/extension.ts b/code/extensions/che-remote/src/extension.ts index 55bc1c235a1..4a273260b98 100644 --- a/code/extensions/che-remote/src/extension.ts +++ b/code/extensions/che-remote/src/extension.ts @@ -209,18 +209,34 @@ async function updateDevfile(cheApi: any): Promise { 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; }