Skip to content

Commit cc3fd54

Browse files
committed
ws-manager: remove PVC object if the worksapce disposal is finished
Signed-off-by: JenTing Hsiao <[email protected]>
1 parent 449bcc2 commit cc3fd54

File tree

1 file changed

+45
-30
lines changed

1 file changed

+45
-30
lines changed

components/ws-manager/pkg/manager/monitor.go

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -440,43 +440,58 @@ func actOnPodEvent(ctx context.Context, m actingManager, manager *Manager, statu
440440
}
441441

442442
span.LogKV("disposalStatusAnnotation", ds)
443-
if terminated && !ds.Status.IsDisposed() {
444-
if wso.Pod.Annotations[workspaceFailedBeforeStoppingAnnotation] == util.BooleanTrueString && wso.Pod.Annotations[workspaceNeverReadyAnnotation] == util.BooleanTrueString {
445-
span.LogKV("event", "failed before stopping and never ready")
446-
// The workspace is never ready, so there is no need for a finalizer.
447-
if _, ok := pod.Annotations[workspaceExplicitFailAnnotation]; !ok {
448-
failMessage := status.Conditions.Failed
449-
if failMessage == "" {
450-
failMessage = "workspace failed to start."
451-
}
452-
err := m.markWorkspace(ctx, workspaceID, addMark(workspaceExplicitFailAnnotation, failMessage))
453-
if err != nil {
454-
log.WithError(err).Error("was unable to mark workspace as failed")
455-
}
456-
}
443+
if !terminated {
444+
return nil
445+
}
457446

458-
// delete PVC because the workspace pod is never ready
459-
if err = manager.deleteWorkspacePVC(ctx, pod.Name); err != nil {
460-
log.Error(err)
461-
return err
447+
if ds.Status.IsDisposed() {
448+
if err = manager.deleteWorkspacePVC(ctx, pod.Name); err != nil {
449+
log.Error(err)
450+
return err
451+
}
452+
}
453+
454+
if wso.Pod.Annotations[workspaceFailedBeforeStoppingAnnotation] == util.BooleanTrueString && wso.Pod.Annotations[workspaceNeverReadyAnnotation] == util.BooleanTrueString {
455+
span.LogKV("event", "failed before stopping and never ready")
456+
// The workspace is never ready, so there is no need for a finalizer.
457+
if _, ok := pod.Annotations[workspaceExplicitFailAnnotation]; !ok {
458+
failMessage := status.Conditions.Failed
459+
if failMessage == "" {
460+
failMessage = "workspace failed to start."
462461
}
463-
return m.modifyFinalizer(ctx, workspaceID, gitpodFinalizerName, false)
464-
} else if wso.Pod.Annotations[abortRequestAnnotation] == util.BooleanTrueString {
465-
span.LogKV("event", "workspace was aborted")
466-
// The workspace is aborted, so there is no need to finalize content
467-
if err = manager.deleteWorkspacePVC(ctx, pod.Name); err != nil {
468-
log.Error(err)
469-
return err
462+
err := m.markWorkspace(ctx, workspaceID, addMark(workspaceExplicitFailAnnotation, failMessage))
463+
if err != nil {
464+
log.WithError(err).Error("was unable to mark workspace as failed")
470465
}
471-
return m.modifyFinalizer(ctx, workspaceID, gitpodFinalizerName, false)
472-
} else {
473-
// We start finalizing the workspace content only after the container is gone. This way we ensure there's
474-
// no process modifying the workspace content as we create the backup.
475-
go m.finalizeWorkspaceContent(ctx, wso)
476466
}
467+
468+
// delete PVC because the workspace pod is never ready
469+
if err = manager.deleteWorkspacePVC(ctx, pod.Name); err != nil {
470+
log.Error(err)
471+
return err
472+
}
473+
return m.modifyFinalizer(ctx, workspaceID, gitpodFinalizerName, false)
474+
} else if wso.Pod.Annotations[abortRequestAnnotation] == util.BooleanTrueString {
475+
span.LogKV("event", "workspace was aborted")
476+
// The workspace is aborted, so there is no need to finalize content
477+
if err = manager.deleteWorkspacePVC(ctx, pod.Name); err != nil {
478+
log.Error(err)
479+
return err
480+
}
481+
return m.modifyFinalizer(ctx, workspaceID, gitpodFinalizerName, false)
482+
} else {
483+
// We start finalizing the workspace content only after the container is gone. This way we ensure there's
484+
// no process modifying the workspace content as we create the backup.
485+
go m.finalizeWorkspaceContent(ctx, wso)
477486
}
478487

479488
case api.WorkspacePhase_STOPPED:
489+
// delete PVC because the workspace pod is stopped
490+
if err = manager.deleteWorkspacePVC(ctx, pod.Name); err != nil {
491+
log.Error(err)
492+
return err
493+
}
494+
480495
// we've disposed already - try to remove the finalizer and call it a day
481496
return m.modifyFinalizer(ctx, workspaceID, gitpodFinalizerName, false)
482497
}

0 commit comments

Comments
 (0)