Skip to content

Commit d277e28

Browse files
authored
feat: change template max_ttl to default_ttl (#4843)
1 parent ffc24dc commit d277e28

26 files changed

+317
-517
lines changed

cli/templatecreate.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ import (
2424

2525
func templateCreate() *cobra.Command {
2626
var (
27-
directory string
28-
provisioner string
29-
parameterFile string
30-
maxTTL time.Duration
31-
minAutostartInterval time.Duration
27+
directory string
28+
provisioner string
29+
parameterFile string
30+
defaultTTL time.Duration
3231
)
3332
cmd := &cobra.Command{
3433
Use: "create [name]",
@@ -108,10 +107,9 @@ func templateCreate() *cobra.Command {
108107
}
109108

110109
createReq := codersdk.CreateTemplateRequest{
111-
Name: templateName,
112-
VersionID: job.ID,
113-
MaxTTLMillis: ptr.Ref(maxTTL.Milliseconds()),
114-
MinAutostartIntervalMillis: ptr.Ref(minAutostartInterval.Milliseconds()),
110+
Name: templateName,
111+
VersionID: job.ID,
112+
DefaultTTLMillis: ptr.Ref(defaultTTL.Milliseconds()),
115113
}
116114

117115
_, err = client.CreateTemplate(cmd.Context(), organization.ID, createReq)
@@ -133,8 +131,7 @@ func templateCreate() *cobra.Command {
133131
cmd.Flags().StringVarP(&directory, "directory", "d", currentDirectory, "Specify the directory to create from")
134132
cmd.Flags().StringVarP(&provisioner, "test.provisioner", "", "terraform", "Customize the provisioner backend")
135133
cmd.Flags().StringVarP(&parameterFile, "parameter-file", "", "", "Specify a file path with parameter values.")
136-
cmd.Flags().DurationVarP(&maxTTL, "max-ttl", "", 24*time.Hour, "Specify a maximum TTL for workspaces created from this template.")
137-
cmd.Flags().DurationVarP(&minAutostartInterval, "min-autostart-interval", "", time.Hour, "Specify a minimum autostart interval for workspaces created from this template.")
134+
cmd.Flags().DurationVarP(&defaultTTL, "default-ttl", "", 24*time.Hour, "Specify a default TTL for workspaces created from this template.")
138135
// This is for testing!
139136
err := cmd.Flags().MarkHidden("test.provisioner")
140137
if err != nil {

cli/templatecreate_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ func TestTemplateCreate(t *testing.T) {
5252
"my-template",
5353
"--directory", source,
5454
"--test.provisioner", string(database.ProvisionerTypeEcho),
55-
"--max-ttl", "24h",
56-
"--min-autostart-interval", "2h",
55+
"--default-ttl", "24h",
5756
}
5857
cmd, root := clitest.New(t, args...)
5958
clitest.SetupConfig(t, client, root)

cli/templateedit.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ import (
1313

1414
func templateEdit() *cobra.Command {
1515
var (
16-
name string
17-
description string
18-
icon string
19-
maxTTL time.Duration
20-
minAutostartInterval time.Duration
16+
name string
17+
description string
18+
icon string
19+
defaultTTL time.Duration
2120
)
2221

2322
cmd := &cobra.Command{
@@ -40,11 +39,10 @@ func templateEdit() *cobra.Command {
4039

4140
// NOTE: coderd will ignore empty fields.
4241
req := codersdk.UpdateTemplateMeta{
43-
Name: name,
44-
Description: description,
45-
Icon: icon,
46-
MaxTTLMillis: maxTTL.Milliseconds(),
47-
MinAutostartIntervalMillis: minAutostartInterval.Milliseconds(),
42+
Name: name,
43+
Description: description,
44+
Icon: icon,
45+
DefaultTTLMillis: defaultTTL.Milliseconds(),
4846
}
4947

5048
_, err = client.UpdateTemplateMeta(cmd.Context(), template.ID, req)
@@ -59,8 +57,7 @@ func templateEdit() *cobra.Command {
5957
cmd.Flags().StringVarP(&name, "name", "", "", "Edit the template name")
6058
cmd.Flags().StringVarP(&description, "description", "", "", "Edit the template description")
6159
cmd.Flags().StringVarP(&icon, "icon", "", "", "Edit the template icon path")
62-
cmd.Flags().DurationVarP(&maxTTL, "max-ttl", "", 0, "Edit the template maximum time before shutdown - workspaces created from this template cannot stay running longer than this.")
63-
cmd.Flags().DurationVarP(&minAutostartInterval, "min-autostart-interval", "", 0, "Edit the template minimum autostart interval - workspaces created from this template must wait at least this long between autostarts.")
60+
cmd.Flags().DurationVarP(&defaultTTL, "default-ttl", "", 0, "Edit the template default time before shutdown - workspaces created from this template to this value.")
6461
cliui.AllowSkipPrompt(cmd)
6562

6663
return cmd

cli/templateedit_test.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,22 @@ func TestTemplateEdit(t *testing.T) {
2626
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID, func(ctr *codersdk.CreateTemplateRequest) {
2727
ctr.Description = "original description"
2828
ctr.Icon = "/icons/default-icon.png"
29-
ctr.MaxTTLMillis = ptr.Ref(24 * time.Hour.Milliseconds())
30-
ctr.MinAutostartIntervalMillis = ptr.Ref(time.Hour.Milliseconds())
29+
ctr.DefaultTTLMillis = ptr.Ref(24 * time.Hour.Milliseconds())
3130
})
3231

3332
// Test the cli command.
3433
name := "new-template-name"
3534
desc := "lorem ipsum dolor sit amet et cetera"
3635
icon := "/icons/new-icon.png"
37-
maxTTL := 12 * time.Hour
38-
minAutostartInterval := time.Minute
36+
defaultTTL := 12 * time.Hour
3937
cmdArgs := []string{
4038
"templates",
4139
"edit",
4240
template.Name,
4341
"--name", name,
4442
"--description", desc,
4543
"--icon", icon,
46-
"--max-ttl", maxTTL.String(),
47-
"--min-autostart-interval", minAutostartInterval.String(),
44+
"--default-ttl", defaultTTL.String(),
4845
}
4946
cmd, root := clitest.New(t, cmdArgs...)
5047
clitest.SetupConfig(t, client, root)
@@ -59,8 +56,7 @@ func TestTemplateEdit(t *testing.T) {
5956
assert.Equal(t, name, updated.Name)
6057
assert.Equal(t, desc, updated.Description)
6158
assert.Equal(t, icon, updated.Icon)
62-
assert.Equal(t, maxTTL.Milliseconds(), updated.MaxTTLMillis)
63-
assert.Equal(t, minAutostartInterval.Milliseconds(), updated.MinAutostartIntervalMillis)
59+
assert.Equal(t, defaultTTL.Milliseconds(), updated.DefaultTTLMillis)
6460
})
6561

6662
t.Run("NotModified", func(t *testing.T) {
@@ -72,8 +68,7 @@ func TestTemplateEdit(t *testing.T) {
7268
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID, func(ctr *codersdk.CreateTemplateRequest) {
7369
ctr.Description = "original description"
7470
ctr.Icon = "/icons/default-icon.png"
75-
ctr.MaxTTLMillis = ptr.Ref(24 * time.Hour.Milliseconds())
76-
ctr.MinAutostartIntervalMillis = ptr.Ref(time.Hour.Milliseconds())
71+
ctr.DefaultTTLMillis = ptr.Ref(24 * time.Hour.Milliseconds())
7772
})
7873

7974
// Test the cli command.
@@ -84,8 +79,7 @@ func TestTemplateEdit(t *testing.T) {
8479
"--name", template.Name,
8580
"--description", template.Description,
8681
"--icon", template.Icon,
87-
"--max-ttl", (time.Duration(template.MaxTTLMillis) * time.Millisecond).String(),
88-
"--min-autostart-interval", (time.Duration(template.MinAutostartIntervalMillis) * time.Millisecond).String(),
82+
"--default-ttl", (time.Duration(template.DefaultTTLMillis) * time.Millisecond).String(),
8983
}
9084
cmd, root := clitest.New(t, cmdArgs...)
9185
clitest.SetupConfig(t, client, root)
@@ -100,7 +94,6 @@ func TestTemplateEdit(t *testing.T) {
10094
assert.Equal(t, template.Name, updated.Name)
10195
assert.Equal(t, template.Description, updated.Description)
10296
assert.Equal(t, template.Icon, updated.Icon)
103-
assert.Equal(t, template.MaxTTLMillis, updated.MaxTTLMillis)
104-
assert.Equal(t, template.MinAutostartIntervalMillis, updated.MinAutostartIntervalMillis)
97+
assert.Equal(t, template.DefaultTTLMillis, updated.DefaultTTLMillis)
10598
})
10699
}

cli/templates.go

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,14 @@ func templates() *cobra.Command {
5050
}
5151

5252
type templateTableRow struct {
53-
Name string `table:"name"`
54-
CreatedAt string `table:"created at"`
55-
LastUpdated string `table:"last updated"`
56-
OrganizationID uuid.UUID `table:"organization id"`
57-
Provisioner codersdk.ProvisionerType `table:"provisioner"`
58-
ActiveVersionID uuid.UUID `table:"active version id"`
59-
UsedBy string `table:"used by"`
60-
MaxTTL time.Duration `table:"max ttl"`
61-
MinAutostartInterval time.Duration `table:"min autostart"`
53+
Name string `table:"name"`
54+
CreatedAt string `table:"created at"`
55+
LastUpdated string `table:"last updated"`
56+
OrganizationID uuid.UUID `table:"organization id"`
57+
Provisioner codersdk.ProvisionerType `table:"provisioner"`
58+
ActiveVersionID uuid.UUID `table:"active version id"`
59+
UsedBy string `table:"used by"`
60+
DefaultTTL time.Duration `table:"default ttl"`
6261
}
6362

6463
// displayTemplates will return a table displaying all templates passed in.
@@ -68,15 +67,14 @@ func displayTemplates(filterColumns []string, templates ...codersdk.Template) (s
6867
rows := make([]templateTableRow, len(templates))
6968
for i, template := range templates {
7069
rows[i] = templateTableRow{
71-
Name: template.Name,
72-
CreatedAt: template.CreatedAt.Format("January 2, 2006"),
73-
LastUpdated: template.UpdatedAt.Format("January 2, 2006"),
74-
OrganizationID: template.OrganizationID,
75-
Provisioner: template.Provisioner,
76-
ActiveVersionID: template.ActiveVersionID,
77-
UsedBy: cliui.Styles.Fuchsia.Render(formatActiveDevelopers(template.ActiveUserCount)),
78-
MaxTTL: (time.Duration(template.MaxTTLMillis) * time.Millisecond),
79-
MinAutostartInterval: (time.Duration(template.MinAutostartIntervalMillis) * time.Millisecond),
70+
Name: template.Name,
71+
CreatedAt: template.CreatedAt.Format("January 2, 2006"),
72+
LastUpdated: template.UpdatedAt.Format("January 2, 2006"),
73+
OrganizationID: template.OrganizationID,
74+
Provisioner: template.Provisioner,
75+
ActiveVersionID: template.ActiveVersionID,
76+
UsedBy: cliui.Styles.Fuchsia.Render(formatActiveDevelopers(template.ActiveUserCount)),
77+
DefaultTTL: (time.Duration(template.DefaultTTLMillis) * time.Millisecond),
8078
}
8179
}
8280

coderd/database/databasefake/databasefake.go

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,8 +1455,7 @@ func (q *fakeQuerier) UpdateTemplateMetaByID(_ context.Context, arg database.Upd
14551455
tpl.Name = arg.Name
14561456
tpl.Description = arg.Description
14571457
tpl.Icon = arg.Icon
1458-
tpl.MaxTtl = arg.MaxTtl
1459-
tpl.MinAutostartInterval = arg.MinAutostartInterval
1458+
tpl.DefaultTtl = arg.DefaultTtl
14601459
q.templates[idx] = tpl
14611460
return tpl, nil
14621461
}
@@ -2227,25 +2226,20 @@ func (q *fakeQuerier) InsertTemplate(_ context.Context, arg database.InsertTempl
22272226
q.mutex.Lock()
22282227
defer q.mutex.Unlock()
22292228

2230-
if arg.MinAutostartInterval == 0 {
2231-
arg.MinAutostartInterval = int64(time.Hour)
2232-
}
2233-
22342229
//nolint:gosimple
22352230
template := database.Template{
2236-
ID: arg.ID,
2237-
CreatedAt: arg.CreatedAt,
2238-
UpdatedAt: arg.UpdatedAt,
2239-
OrganizationID: arg.OrganizationID,
2240-
Name: arg.Name,
2241-
Provisioner: arg.Provisioner,
2242-
ActiveVersionID: arg.ActiveVersionID,
2243-
Description: arg.Description,
2244-
MaxTtl: arg.MaxTtl,
2245-
MinAutostartInterval: arg.MinAutostartInterval,
2246-
CreatedBy: arg.CreatedBy,
2247-
UserACL: arg.UserACL,
2248-
GroupACL: arg.GroupACL,
2231+
ID: arg.ID,
2232+
CreatedAt: arg.CreatedAt,
2233+
UpdatedAt: arg.UpdatedAt,
2234+
OrganizationID: arg.OrganizationID,
2235+
Name: arg.Name,
2236+
Provisioner: arg.Provisioner,
2237+
ActiveVersionID: arg.ActiveVersionID,
2238+
Description: arg.Description,
2239+
DefaultTtl: arg.DefaultTtl,
2240+
CreatedBy: arg.CreatedBy,
2241+
UserACL: arg.UserACL,
2242+
GroupACL: arg.GroupACL,
22492243
}
22502244
q.templates = append(q.templates, template)
22512245
return template, nil

coderd/database/dump.sql

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- add "slug" min_autostart_interval to "templates" table
2+
ALTER TABLE "templates" ADD COLUMN "min_autostart_interval" int DEFAULT 0;
3+
4+
-- rename "default_ttl" to "max_ttl" on "templates" table
5+
ALTER TABLE "templates" RENAME COLUMN "default_ttl" TO "max_ttl";
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- drop "min_autostart_interval" column from "templates" table
2+
ALTER TABLE "templates" DROP COLUMN "min_autostart_interval";
3+
4+
-- rename "max_ttl" to "default_ttl" on "templates" table
5+
ALTER TABLE "templates" RENAME COLUMN "max_ttl" TO "default_ttl";
6+
COMMENT ON COLUMN templates.default_ttl IS 'The default duration for auto-stop for workspaces created from this template.';

coderd/database/models.go

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy