Skip to content

Commit 377f00c

Browse files
iQQBotWVerlaek
authored andcommitted
[ws-manager] Add custom closed timeout
Co-authored-by: Wouter Verlaek <[email protected]>
1 parent 172c58c commit 377f00c

File tree

8 files changed

+714
-457
lines changed

8 files changed

+714
-457
lines changed

components/ws-manager-api/core.proto

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,20 @@ message MarkActiveRequest {
171171
// MarkActiveResponse is the answer to a mark workspace active request
172172
message MarkActiveResponse {}
173173

174+
enum TimeoutType {
175+
WORKSPACE_TIMEOUT = 0;
176+
CLOSED_TIMEOUT = 1;
177+
}
178+
174179
// SetTimeoutRequest configures the timeout of a workspace
175180
message SetTimeoutRequest {
176181
// id is the ID of the workspace
177182
string id = 1;
178183

179184
// duration is the new timeout duration. Must be a valid Go duration (see https://golang.org/pkg/time/#ParseDuration)
180185
string duration = 2;
186+
187+
TimeoutType type = 3;
181188
}
182189

183190
// SetTimeoutResponse is the answer to a set timeout request
@@ -361,6 +368,9 @@ message WorkspaceSpec {
361368
// ide_image_layers are contains the images needed for the ide to run,
362369
// including ide-desktop, desktop-plugin and so on
363370
repeated string ide_image_layers = 10;
371+
372+
// The timeout for closed ide.
373+
string closed_timeout = 11;
364374
}
365375

366376
// PortSpec describes a networking port exposed on a workspace
@@ -584,6 +594,9 @@ message StartWorkspaceSpec {
584594
// ide_image_layers are contains the images needed for the ide to run,
585595
// including ide-desktop, desktop-plugin and so on
586596
repeated string ide_image_layers = 17;
597+
598+
// timeout optionally sets a custom closed timeout
599+
string closed_timeout = 18;
587600
}
588601

589602
// WorkspaceFeatureFlag enable non-standard behaviour in workspaces

components/ws-manager-api/go/core.pb.go

Lines changed: 535 additions & 450 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/ws-manager-api/typescript/src/core_pb.d.ts

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/ws-manager-api/typescript/src/core_pb.js

Lines changed: 102 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ const (
5959
// This is handy if you want to prevent a workspace from timing out during lunch break.
6060
customTimeoutAnnotation = "gitpod/customTimeout"
6161

62+
// customClosedTimeoutAnnotation configures the closed timeout of a workspace, i.e. close web ide, disconnect ssh connection
63+
customClosedTimeoutAnnotation = "gitpod/customClosedTimeout"
64+
6265
// firstUserActivityAnnotation marks a workspace woth the timestamp of first user activity in it
6366
firstUserActivityAnnotation = "gitpod/firstUserActivity"
6467

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,13 @@ func (m *Manager) createDefiniteWorkspacePod(startContext *startWorkspaceContext
393393
}
394394
annotations[customTimeoutAnnotation] = req.Spec.Timeout
395395
}
396+
if req.Spec.ClosedTimeout != "" {
397+
_, err := time.ParseDuration(req.Spec.ClosedTimeout)
398+
if err != nil {
399+
return nil, xerrors.Errorf("invalid closed timeout \"%s\": %w", req.Spec.ClosedTimeout, err)
400+
}
401+
annotations[customClosedTimeoutAnnotation] = req.Spec.ClosedTimeout
402+
}
396403

397404
for k, v := range req.Metadata.Annotations {
398405
annotations[workspaceAnnotationPrefix+k] = v

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,20 @@ func (m *Manager) SetTimeout(ctx context.Context, req *api.SetTimeoutRequest) (r
134134
return nil, xerrors.Errorf("invalid duration \"%s\": %w", req.Duration, err)
135135
}
136136

137-
err = m.markWorkspace(ctx, req.Id, addMark(customTimeoutAnnotation, req.Duration))
138-
if err != nil {
139-
return nil, xerrors.Errorf("cannot set workspace timeout: %w", err)
137+
if req.Type == api.TimeoutType_WORKSPACE_TIMEOUT {
138+
err = m.markWorkspace(ctx, req.Id, addMark(customTimeoutAnnotation, req.Duration))
139+
if err != nil {
140+
return nil, xerrors.Errorf("cannot set workspace timeout: %w", err)
141+
}
142+
err = m.markWorkspace(ctx, req.Id, addMark(customClosedTimeoutAnnotation, "0"))
143+
if err != nil {
144+
return nil, xerrors.Errorf("cannot set closed timeout: %w", err)
145+
}
146+
} else if req.Type == api.TimeoutType_CLOSED_TIMEOUT {
147+
err = m.markWorkspace(ctx, req.Id, addMark(customClosedTimeoutAnnotation, req.Duration))
148+
if err != nil {
149+
return nil, xerrors.Errorf("cannot set closed timeout: %w", err)
150+
}
140151
}
141152

142153
return &api.SetTimeoutResponse{}, nil

0 commit comments

Comments
 (0)