Skip to content

feat: add template max_ttl #6114

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 32 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5509824
feat: add template max_ttl
deansheather Feb 8, 2023
4c6a501
chore: split enterprise code for max_ttl into interface
deansheather Feb 15, 2023
7892c5a
Merge branch 'main' into dean/schedule-max-ttl
deansheather Feb 20, 2023
9e37cc7
feat: add API for setting template max_ttl
deansheather Feb 20, 2023
ad64806
working API and dashboard
deansheather Feb 20, 2023
96fd840
working CLI
deansheather Feb 20, 2023
bc39570
Merge branch 'main' into dean/schedule-max-ttl
deansheather Feb 23, 2023
4e1d948
fixup! Merge branch 'main' into dean/schedule-max-ttl
deansheather Feb 23, 2023
69035a6
feat: block disabling auto off if template has max ttl
deansheather Feb 23, 2023
ce7ec39
Merge branch 'main' into dean/schedule-max-ttl
deansheather Mar 1, 2023
89ccfc8
fixup! Merge branch 'main' into dean/schedule-max-ttl
deansheather Mar 1, 2023
feb7b3c
feat: apply template max TTL to workspace TTL on update
deansheather Mar 1, 2023
d54d798
chore: fix tests and differences between sql and memory db
deansheather Mar 1, 2023
6caeb00
Few refactorings for ttl fields
BrunoQuaresma Mar 1, 2023
49a2ec7
Merge branch 'main' into dean/schedule-max-ttl
deansheather Mar 1, 2023
e28e32e
fixup! Merge branch 'main' into dean/schedule-max-ttl
deansheather Mar 1, 2023
651149b
fixup! Merge branch 'main' into dean/schedule-max-ttl
deansheather Mar 1, 2023
25f7d2c
chore: add test for activitybump max_ttl
deansheather Mar 2, 2023
e3d8557
chore: add tests for updating max_ttl on template
deansheather Mar 2, 2023
f62ba67
Merge branch 'main' into dean/schedule-max-ttl
deansheather Mar 2, 2023
2b029d8
fixup! Merge branch 'main' into dean/schedule-max-ttl
deansheather Mar 2, 2023
e60919e
chore: fix security.yaml not having protoc
deansheather Mar 2, 2023
ef3bebf
Merge branch 'main' into dean/schedule-max-ttl
deansheather Mar 2, 2023
351b708
fixup! Merge branch 'main' into dean/schedule-max-ttl
deansheather Mar 2, 2023
847bc4c
chore: move schedule code to new package
deansheather Mar 2, 2023
0611794
fixup! chore: move schedule code to new package
deansheather Mar 2, 2023
e44f589
chore: add alpha label to max_ttl
deansheather Mar 6, 2023
6bb65ac
Merge branch 'main' into dean/schedule-max-ttl
deansheather Mar 6, 2023
a972c57
Merge branch 'main' into dean/schedule-max-ttl
BrunoQuaresma Mar 6, 2023
3ce2bc3
Fix test
BrunoQuaresma Mar 6, 2023
4beff52
fixup! Fix test
deansheather Mar 6, 2023
5e97e96
Fix storybook
BrunoQuaresma Mar 7, 2023
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
Prev Previous commit
Next Next commit
chore: fix tests and differences between sql and memory db
  • Loading branch information
deansheather committed Mar 1, 2023
commit d54d7983e4c2439c48eaa7117f9ee06cdfe19ab7
7 changes: 5 additions & 2 deletions cli/schedule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,16 @@ func TestScheduleOverride(t *testing.T) {
user = coderdtest.CreateFirstUser(t, client)
version = coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
project = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
workspace = coderdtest.CreateWorkspace(t, client, user.OrganizationID, project.ID, func(cwr *codersdk.CreateWorkspaceRequest) {
template = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
workspace = coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID, func(cwr *codersdk.CreateWorkspaceRequest) {
cwr.TTLMillis = nil
})
cmdArgs = []string{"schedule", "override-stop", workspace.Name, "1h"}
stdoutBuf = &bytes.Buffer{}
)
require.Zero(t, template.DefaultTTLMillis)
require.Zero(t, template.MaxTTLMillis)

// Unset the workspace TTL
err = client.UpdateWorkspaceTTL(ctx, workspace.ID, codersdk.UpdateWorkspaceTTLRequest{TTLMillis: nil})
require.NoError(t, err)
Expand Down
3 changes: 0 additions & 3 deletions coderd/provisionerdserver/provisionerdserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -917,9 +917,6 @@ func (server *Server) CompleteJob(ctx context.Context, completed *proto.Complete
// The user is not permitted to set their own TTL.
deadline = time.Time{}
}
if deadline.IsZero() && templateSchedule.DefaultTTL > 0 {
deadline = now.Add(templateSchedule.DefaultTTL)
}
if templateSchedule.MaxTTL > 0 {
maxDeadline = now.Add(templateSchedule.MaxTTL)

Expand Down
4 changes: 2 additions & 2 deletions coderd/provisionerdserver/provisionerdserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,12 +836,12 @@ func TestCompleteJob(t *testing.T) {
expectedMaxTTL: 0,
},
{
name: "TemplateDefaultTTL",
name: "TemplateDefaultTTLIgnored",
templateDefaultTTL: time.Hour,
templateMaxTTL: 0,
workspaceTTL: 0,
transition: database.WorkspaceTransitionStart,
expectedTTL: time.Hour,
expectedTTL: 0,
expectedMaxTTL: 0,
},
{
Expand Down
16 changes: 7 additions & 9 deletions coderd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,13 @@ func (api *API) postTemplateByOrganization(rw http.ResponseWriter, r *http.Reque
return xerrors.Errorf("insert template: %s", err)
}

if defaultTTL != 0 || maxTTL != 0 {
dbTemplate, err = (*api.TemplateScheduleStore.Load()).SetTemplateScheduleOptions(ctx, tx, dbTemplate, provisionerdserver.TemplateScheduleOptions{
UserSchedulingEnabled: true,
DefaultTTL: defaultTTL,
MaxTTL: maxTTL,
})
if err != nil {
return xerrors.Errorf("set template schedule options: %s", err)
}
dbTemplate, err = (*api.TemplateScheduleStore.Load()).SetTemplateScheduleOptions(ctx, tx, dbTemplate, provisionerdserver.TemplateScheduleOptions{
UserSchedulingEnabled: true,
DefaultTTL: defaultTTL,
MaxTTL: maxTTL,
})
if err != nil {
return xerrors.Errorf("set template schedule options: %s", err)
}

templateAudit.New = dbTemplate
Expand Down
10 changes: 6 additions & 4 deletions enterprise/coderd/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ func TestTemplates(t *testing.T) {
workspace2 := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID, func(cwr *codersdk.CreateWorkspaceRequest) {
cwr.TTLMillis = &workspace2TTL
})
workspace3 := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID, func(cwr *codersdk.CreateWorkspaceRequest) {
cwr.TTLMillis = nil
})

workspace3 := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
// To unset TTL you have to update, as setting a nil TTL on create
// copies the template default TTL.
ctx, _ := testutil.Context(t)
err := client.UpdateWorkspaceTTL(ctx, workspace3.ID, codersdk.UpdateWorkspaceTTLRequest{
TTLMillis: nil,
})

updated, err := client.UpdateTemplateMeta(ctx, template.ID, codersdk.UpdateTemplateMeta{
Name: template.Name,
Expand Down