Skip to content

[ws-manager-mk2] Ensure prebuilds can start and stop #16479

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
Feb 27, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func NewWorkspaceOperations(config content.Config, store *session.Store, reg pro
func (wso *WorkspaceOperations) InitWorkspaceContent(ctx context.Context, options InitContentOptions) (bool, string, error) {
res, err := wso.store.NewWorkspace(
ctx, options.Meta.InstanceId, filepath.Join(wso.store.Location, options.Meta.InstanceId),
wso.creator(options.Meta.Owner, options.Meta.WorkspaceId, options.Meta.InstanceId, options.Initializer, options.Headless))
wso.creator(options.Meta.Owner, options.Meta.WorkspaceId, options.Meta.InstanceId, options.Initializer, false))
if errors.Is(err, storage.ErrNotFound) {
return false, "", nil
}
Expand Down
4 changes: 4 additions & 0 deletions components/ws-manager-mk2/controllers/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ func updateWorkspaceStatus(ctx context.Context, workspace *workspacev1.Workspace
case workspace.IsHeadless() && (pod.Status.Phase == corev1.PodSucceeded || pod.Status.Phase == corev1.PodFailed):
workspace.Status.Phase = workspacev1.WorkspacePhaseStopping

if isDisposalFinished(workspace) {
workspace.Status.Phase = workspacev1.WorkspacePhaseStopped
}

case pod.Status.Phase == corev1.PodUnknown:
workspace.Status.Phase = workspacev1.WorkspacePhaseUnknown

Expand Down
10 changes: 10 additions & 0 deletions components/ws-manager-mk2/controllers/workspace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,16 @@ func (r *WorkspaceReconciler) actOnStatus(ctx context.Context, workspace *worksp
return ctrl.Result{Requeue: true}, err
}

case workspace.Status.Headless && workspace.Status.Phase == workspacev1.WorkspacePhaseStopped && !isPodBeingDeleted(pod):
// Workspace was requested to be deleted, propagate by deleting the Pod.
// The Pod deletion will then trigger workspace disposal steps.
err := r.Client.Delete(ctx, pod)
if errors.IsNotFound(err) {
// pod is gone - nothing to do here
} else {
return ctrl.Result{Requeue: true}, err
}

// we've disposed already - try to remove the finalizer and call it a day
case workspace.Status.Phase == workspacev1.WorkspacePhaseStopped:
hadFinalizer := controllerutil.ContainsFinalizer(pod, workspacev1.GitpodFinalizerName)
Expand Down