Skip to content
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

Add maximum lifetime constraint for a workspace #8307

Merged
merged 1 commit into from
Feb 22, 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
1 change: 1 addition & 0 deletions chart/templates/ws-manager-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ data:
"headlessWorkspace": "60m",
"initialization": "30m",
"regularWorkspace": "30m",
"maxLifetime": "36h",
"startup": "60m",
"contentFinalization": "60m",
"stopping": "60m",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
HeadlessWorkspace: util.Duration(1 * time.Hour),
Initialization: util.Duration(30 * time.Minute),
RegularWorkspace: util.Duration(30 * time.Minute),
MaxLifetime: util.Duration(36 * time.Hour),
TotalStartup: util.Duration(1 * time.Hour),
ContentFinalization: util.Duration(1 * time.Hour),
Stopping: util.Duration(1 * time.Hour),
Expand Down
3 changes: 3 additions & 0 deletions components/ws-manager-api/go/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ type WorkspaceTimeoutConfiguration struct {
Initialization util.Duration `json:"initialization"`
// RegularWorkspace is the time a regular workspace can be without activity before it's shutdown
RegularWorkspace util.Duration `json:"regularWorkspace"`
// MaxLifetime is the maximum lifetime of a regular workspace
MaxLifetime util.Duration `json:"maxLifetime"`
// HeadlessWorkspace is the maximum runtime a headless workspace can have (including startup)
HeadlessWorkspace util.Duration `json:"headlessWorkspace"`
// AfterClose is the time a workspace lives after it has been marked closed
Expand Down Expand Up @@ -188,6 +190,7 @@ func (c *Configuration) Validate() error {
validation.Field(&c.Timeouts.HeadlessWorkspace, validation.Required),
validation.Field(&c.Timeouts.Initialization, validation.Required),
validation.Field(&c.Timeouts.RegularWorkspace, validation.Required),
validation.Field(&c.Timeouts.MaxLifetime, validation.Required),
validation.Field(&c.Timeouts.TotalStartup, validation.Required),
validation.Field(&c.Timeouts.ContentFinalization, validation.Required),
validation.Field(&c.Timeouts.Stopping, validation.Required),
Expand Down
4 changes: 4 additions & 0 deletions components/ws-manager/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
"startup",
"initialization",
"regularWorkspace",
"maxLifetime",
"headlessWorkspace",
"afterClose",
"stopping",
Expand All @@ -194,6 +195,9 @@
"regularWorkspace": {
"type": "string"
},
"maxLifetime": {
"type": "string"
},
"startup": {
"type": "string"
},
Expand Down
1 change: 1 addition & 0 deletions components/ws-manager/example-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"headlessWorkspace": "60m",
"initialization": "30m",
"regularWorkspace": "30m",
"maxLifetime": "36h",
"startup": "30m"
},
"eventTraceLog": "-",
Expand Down
1 change: 1 addition & 0 deletions components/ws-manager/pkg/manager/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func forIntegrationTestGetManager(t *testing.T) *Manager {
Initialization: util.Duration(30 * time.Minute),
TotalStartup: util.Duration(45 * time.Minute),
RegularWorkspace: util.Duration(60 * time.Minute),
MaxLifetime: util.Duration(36 * time.Hour),
HeadlessWorkspace: util.Duration(90 * time.Minute),
Stopping: util.Duration(60 * time.Minute),
ContentFinalization: util.Duration(15 * time.Minute),
Expand Down
2 changes: 1 addition & 1 deletion components/ws-manager/pkg/manager/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb
}
}

// markTimedoutWorkspaces finds workspaces which haven't been active recently and marks them as timed out
// markTimedoutWorkspaces finds workspaces which can be timeout due to inactivity or max lifetime allowed
func (m *Monitor) markTimedoutWorkspaces(ctx context.Context) (err error) {
span, ctx := tracing.FromContext(ctx, "markTimedoutWorkspaces")
defer tracing.FinishSpan(span, &err)
Expand Down
6 changes: 6 additions & 0 deletions components/ws-manager/pkg/manager/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ const (
activityPullingImages activity = "pulling images"
activityRunningHeadless activity = "running the headless workspace"
activityNone activity = "period of inactivity"
activityMaxLifetime activity = "maximum lifetime"
activityClosed activity = "after being closed"
activityInterrupted activity = "workspace interruption"
activityStopping activity = "stopping"
Expand Down Expand Up @@ -716,6 +717,11 @@ func (m *Manager) isWorkspaceTimedOut(wso workspaceObjects) (reason string, err
return decide(start, m.Config.Timeouts.TotalStartup, activity)

case api.WorkspacePhase_RUNNING:
// First check is always for the max lifetime
if msg, err := decide(start, m.Config.Timeouts.MaxLifetime, activityMaxLifetime); msg != "" {
return msg, err
}

timeout := m.Config.Timeouts.RegularWorkspace
activity := activityNone
if wso.IsWorkspaceHeadless() {
Expand Down
1 change: 1 addition & 0 deletions components/ws-manager/pkg/manager/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func TestIsWorkspaceTimedout(t *testing.T) {
Initialization: util.Duration(30 * time.Minute),
TotalStartup: util.Duration(45 * time.Minute),
RegularWorkspace: util.Duration(60 * time.Minute),
MaxLifetime: util.Duration(36 * time.Hour),
HeadlessWorkspace: util.Duration(90 * time.Minute),
Stopping: util.Duration(60 * time.Minute),
ContentFinalization: util.Duration(55 * time.Minute),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"reason": "workspace timed out after maximum lifetime (36h10m) took longer than 36h00m"
}
Loading