Skip to content

add support for aborting workspaces #12284

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
Aug 23, 2022
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
4 changes: 4 additions & 0 deletions components/ws-manager-api/core.proto
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ message StopWorkspaceRequest {
enum StopWorkspacePolicy {
NORMALLY = 0;
IMMEDIATELY = 1;
ABORT = 2;
}

// StopWorkspaceResponse is the answer to a stop workspace request
Expand Down Expand Up @@ -423,6 +424,9 @@ message WorkspaceConditions {

// volume_snapshot contains info about volume snapshot that was used to save persistent volume
VolumeSnapshotInfo volume_snapshot = 12;

// aborted is true if StopWorkspace was called with StopWorkspacePolicy set to ABORT
WorkspaceConditionBool aborted = 13;
}

// WorkspaceConditionBool is a trinary bool: true/false/empty
Expand Down
563 changes: 290 additions & 273 deletions components/ws-manager-api/go/core.pb.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components/ws-manager-api/typescript/src/core_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,8 @@ export class WorkspaceConditions extends jspb.Message {
clearVolumeSnapshot(): void;
getVolumeSnapshot(): VolumeSnapshotInfo | undefined;
setVolumeSnapshot(value?: VolumeSnapshotInfo): WorkspaceConditions;
getAborted(): WorkspaceConditionBool;
setAborted(value: WorkspaceConditionBool): WorkspaceConditions;

serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): WorkspaceConditions.AsObject;
Expand All @@ -864,6 +866,7 @@ export namespace WorkspaceConditions {
headlessTaskFailed: string,
stoppedByRequest: WorkspaceConditionBool,
volumeSnapshot?: VolumeSnapshotInfo.AsObject,
aborted: WorkspaceConditionBool,
}
}

Expand Down Expand Up @@ -1227,6 +1230,7 @@ export namespace WorkspaceClass {
export enum StopWorkspacePolicy {
NORMALLY = 0,
IMMEDIATELY = 1,
ABORT = 2,
}

export enum AdmissionLevel {
Expand Down
35 changes: 33 additions & 2 deletions components/ws-manager-api/typescript/src/core_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -6666,7 +6666,8 @@ proto.wsman.WorkspaceConditions.toObject = function(includeInstance, msg) {
firstUserActivity: (f = msg.getFirstUserActivity()) && google_protobuf_timestamp_pb.Timestamp.toObject(includeInstance, f),
headlessTaskFailed: jspb.Message.getFieldWithDefault(msg, 10, ""),
stoppedByRequest: jspb.Message.getFieldWithDefault(msg, 11, 0),
volumeSnapshot: (f = msg.getVolumeSnapshot()) && proto.wsman.VolumeSnapshotInfo.toObject(includeInstance, f)
volumeSnapshot: (f = msg.getVolumeSnapshot()) && proto.wsman.VolumeSnapshotInfo.toObject(includeInstance, f),
aborted: jspb.Message.getFieldWithDefault(msg, 13, 0)
};

if (includeInstance) {
Expand Down Expand Up @@ -6749,6 +6750,10 @@ proto.wsman.WorkspaceConditions.deserializeBinaryFromReader = function(msg, read
reader.readMessage(value,proto.wsman.VolumeSnapshotInfo.deserializeBinaryFromReader);
msg.setVolumeSnapshot(value);
break;
case 13:
var value = /** @type {!proto.wsman.WorkspaceConditionBool} */ (reader.readEnum());
msg.setAborted(value);
break;
default:
reader.skipField();
break;
Expand Down Expand Up @@ -6857,6 +6862,13 @@ proto.wsman.WorkspaceConditions.serializeBinaryToWriter = function(message, writ
proto.wsman.VolumeSnapshotInfo.serializeBinaryToWriter
);
}
f = message.getAborted();
if (f !== 0.0) {
writer.writeEnum(
13,
f
);
}
};


Expand Down Expand Up @@ -7096,6 +7108,24 @@ proto.wsman.WorkspaceConditions.prototype.hasVolumeSnapshot = function() {
};


/**
* optional WorkspaceConditionBool aborted = 13;
* @return {!proto.wsman.WorkspaceConditionBool}
*/
proto.wsman.WorkspaceConditions.prototype.getAborted = function() {
return /** @type {!proto.wsman.WorkspaceConditionBool} */ (jspb.Message.getFieldWithDefault(this, 13, 0));
};


/**
* @param {!proto.wsman.WorkspaceConditionBool} value
* @return {!proto.wsman.WorkspaceConditions} returns this
*/
proto.wsman.WorkspaceConditions.prototype.setAborted = function(value) {
return jspb.Message.setProto3EnumField(this, 13, value);
};





Expand Down Expand Up @@ -9756,7 +9786,8 @@ proto.wsman.WorkspaceClass.prototype.setDisplayname = function(value) {
*/
proto.wsman.StopWorkspacePolicy = {
NORMALLY: 0,
IMMEDIATELY: 1
IMMEDIATELY: 1,
ABORT: 2
};

/**
Expand Down
3 changes: 3 additions & 0 deletions components/ws-manager/pkg/manager/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ const (
// stoppedByRequestAnnotation is set on a pod when it was requested to stop using a StopWorkspace call
stoppedByRequestAnnotation = "gitpod.io/stoppedByRequest"

// abortRequestAnnotation is set if StopWorkspace was called with ABORT StopWorkspacePolicy
abortRequestAnnotation = "gitpod.io/abortRequest"

// attemptingToCreatePodAnnotation is set when ws-manager is trying to create pod and is removed when pod is successfully scheduled on the node
attemptingToCreatePodAnnotation = "gitpod.io/attemptingToCreate"
)
Expand Down
7 changes: 7 additions & 0 deletions components/ws-manager/pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
wsk8s "github.com/gitpod-io/gitpod/common-go/kubernetes"
"github.com/gitpod-io/gitpod/common-go/log"
"github.com/gitpod-io/gitpod/common-go/tracing"
"github.com/gitpod-io/gitpod/common-go/util"
csapi "github.com/gitpod-io/gitpod/content-service/api"
"github.com/gitpod-io/gitpod/content-service/pkg/layer"
regapi "github.com/gitpod-io/gitpod/registry-facade/api"
Expand Down Expand Up @@ -733,6 +734,12 @@ func (m *Manager) StopWorkspace(ctx context.Context, req *api.StopWorkspaceReque
gracePeriod := stopWorkspaceNormallyGracePeriod
if req.Policy == api.StopWorkspacePolicy_IMMEDIATELY {
gracePeriod = stopWorkspaceImmediatelyGracePeriod
} else if req.Policy == api.StopWorkspacePolicy_ABORT {
gracePeriod = stopWorkspaceImmediatelyGracePeriod
err = m.markWorkspace(ctx, req.Id, addMark(abortRequestAnnotation, util.BooleanTrueString))
if err != nil {
clog.WithError(err).Error("failed to mark workspace for abort")
}
}

err = m.markWorkspace(ctx, req.Id, addMark(stoppedByRequestAnnotation, gracePeriod.String()))
Expand Down
2 changes: 2 additions & 0 deletions components/ws-manager/pkg/manager/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ func (m *metrics) OnChange(status *api.WorkspaceStatus) {
reason = "tab-closed"
} else if strings.Contains(status.Message, "workspace timed out") {
reason = "timeout"
} else if status.Conditions.Aborted == api.WorkspaceConditionBool_TRUE {
reason = "aborted"
} else if status.Conditions.Failed != "" {
reason = "failed"
} else {
Expand Down
9 changes: 9 additions & 0 deletions components/ws-manager/pkg/manager/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ func actOnPodEvent(ctx context.Context, m actingManager, manager *Manager, statu
span.LogKV("disposalStatusAnnotation", ds)
if terminated && !ds.Status.IsDisposed() {
if wso.Pod.Annotations[workspaceFailedBeforeStoppingAnnotation] == util.BooleanTrueString && wso.Pod.Annotations[workspaceNeverReadyAnnotation] == util.BooleanTrueString {
span.LogKV("event", "failed before stopping and never ready")
// The workspace is never ready, so there is no need for a finalizer.
if _, ok := pod.Annotations[workspaceExplicitFailAnnotation]; !ok {
failMessage := status.Conditions.Failed
Expand All @@ -511,6 +512,14 @@ func actOnPodEvent(ctx context.Context, m actingManager, manager *Manager, statu
return err
}
return m.modifyFinalizer(ctx, workspaceID, gitpodFinalizerName, false)
} else if wso.Pod.Annotations[abortRequestAnnotation] == util.BooleanTrueString {
span.LogKV("event", "workspace was aborted")
// The workspace is aborted, so there is no need to finalize content
if err = manager.deleteWorkspacePVC(ctx, pod.Name); err != nil {
log.Error(err)
return err
}
return m.modifyFinalizer(ctx, workspaceID, gitpodFinalizerName, false)
} else {
// We start finalizing the workspace content only after the container is gone. This way we ensure there's
// no process modifying the workspace content as we create the backup.
Expand Down
3 changes: 3 additions & 0 deletions components/ws-manager/pkg/manager/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ func (m *Manager) extractStatusFromPod(result *api.WorkspaceStatus, wso workspac
if _, sbr := pod.Annotations[stoppedByRequestAnnotation]; sbr {
result.Conditions.StoppedByRequest = api.WorkspaceConditionBool_TRUE
}
if _, abr := pod.Annotations[abortRequestAnnotation]; abr {
result.Conditions.Aborted = api.WorkspaceConditionBool_TRUE
}
if wso.IsWorkspaceHeadless() {
for _, cs := range pod.Status.ContainerStatuses {
if cs.State.Terminated != nil && cs.State.Terminated.Message != "" {
Expand Down