Skip to content

[server] Restart PVC workspace from latest valid backup #14053

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

Merged
merged 1 commit into from
Oct 24, 2022
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
14 changes: 7 additions & 7 deletions components/server/src/workspace/workspace-starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,14 @@ export class WorkspaceStarter {

// check if there has been an instance before, i.e. if this is a restart
const pastInstances = await this.workspaceDb.trace({ span }).findInstances(workspace.id);
const hasValidBackup = pastInstances.some(
(i) => !!i.status && !!i.status.conditions && !i.status.conditions.failed,
);
let lastValidWorkspaceInstance: WorkspaceInstance | undefined;
if (hasValidBackup) {
lastValidWorkspaceInstance = pastInstances.reduce((previousValue, currentValue) =>
currentValue.creationTime > previousValue.creationTime ? currentValue : previousValue,
);
// Sorted from latest to oldest
for (const i of pastInstances.sort((a, b) => (a.creationTime > b.creationTime ? -1 : 1))) {
// We're trying to figure out whether there was a successful backup or not, and if yes for which instance
if (!!i.status.conditions && !i.status.conditions.failed) {
lastValidWorkspaceInstance = i;
break;
}
}

const ideConfig = await this.ideService.getIDEConfig();
Expand Down