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

fix: keep devworkspace attributes when restarting from local devfile #465

Merged
merged 2 commits into from
Dec 9, 2024
Merged
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
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
Loading