Skip to content

Commit 8d1cfbc

Browse files
authored
fix: update workspace cleanup flag names for template cmds (#10805)
1 parent 51b58cf commit 8d1cfbc

8 files changed

+245
-65
lines changed

cli/templatecreate.go

+27-18
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
3131
disableEveryone bool
3232
requireActiveVersion bool
3333

34-
defaultTTL time.Duration
35-
failureTTL time.Duration
36-
inactivityTTL time.Duration
37-
maxTTL time.Duration
34+
defaultTTL time.Duration
35+
failureTTL time.Duration
36+
dormancyThreshold time.Duration
37+
dormancyAutoDeletion time.Duration
38+
maxTTL time.Duration
3839

3940
uploadFlags templateUploadFlags
4041
)
@@ -47,18 +48,18 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
4748
r.InitClient(client),
4849
),
4950
Handler: func(inv *clibase.Invocation) error {
50-
isTemplateSchedulingOptionsSet := failureTTL != 0 || inactivityTTL != 0 || maxTTL != 0
51+
isTemplateSchedulingOptionsSet := failureTTL != 0 || dormancyThreshold != 0 || dormancyAutoDeletion != 0 || maxTTL != 0
5152

5253
if isTemplateSchedulingOptionsSet || requireActiveVersion {
53-
if failureTTL != 0 || inactivityTTL != 0 {
54+
if failureTTL != 0 || dormancyThreshold != 0 || dormancyAutoDeletion != 0 {
5455
// This call can be removed when workspace_actions is no longer experimental
5556
experiments, exErr := client.Experiments(inv.Context())
5657
if exErr != nil {
5758
return xerrors.Errorf("get experiments: %w", exErr)
5859
}
5960

6061
if !experiments.Enabled(codersdk.ExperimentWorkspaceActions) {
61-
return xerrors.Errorf("--failure-ttl and --inactivity-ttl are experimental features. Use the workspace_actions CODER_EXPERIMENTS flag to set these configuration values.")
62+
return xerrors.Errorf("--failure-ttl, --dormancy-threshold, and --dormancy-auto-deletion are experimental features. Use the workspace_actions CODER_EXPERIMENTS flag to set these configuration values.")
6263
}
6364
}
6465

@@ -153,14 +154,15 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
153154
}
154155

155156
createReq := codersdk.CreateTemplateRequest{
156-
Name: templateName,
157-
VersionID: job.ID,
158-
DefaultTTLMillis: ptr.Ref(defaultTTL.Milliseconds()),
159-
FailureTTLMillis: ptr.Ref(failureTTL.Milliseconds()),
160-
MaxTTLMillis: ptr.Ref(maxTTL.Milliseconds()),
161-
TimeTilDormantMillis: ptr.Ref(inactivityTTL.Milliseconds()),
162-
DisableEveryoneGroupAccess: disableEveryone,
163-
RequireActiveVersion: requireActiveVersion,
157+
Name: templateName,
158+
VersionID: job.ID,
159+
DefaultTTLMillis: ptr.Ref(defaultTTL.Milliseconds()),
160+
FailureTTLMillis: ptr.Ref(failureTTL.Milliseconds()),
161+
MaxTTLMillis: ptr.Ref(maxTTL.Milliseconds()),
162+
TimeTilDormantMillis: ptr.Ref(dormancyThreshold.Milliseconds()),
163+
TimeTilDormantAutoDeleteMillis: ptr.Ref(dormancyAutoDeletion.Milliseconds()),
164+
DisableEveryoneGroupAccess: disableEveryone,
165+
RequireActiveVersion: requireActiveVersion,
164166
}
165167

166168
_, err = client.CreateTemplate(inv.Context(), organization.ID, createReq)
@@ -220,11 +222,18 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
220222
Value: clibase.DurationOf(&failureTTL),
221223
},
222224
{
223-
Flag: "inactivity-ttl",
224-
Description: "Specify an inactivity TTL for workspaces created from this template. It is the amount of time the workspace is not used before it is be stopped and auto-locked. This includes across multiple builds (e.g. auto-starts and stops). This licensed feature's default is 0h (off). Maps to \"Dormancy threshold\" in the UI.",
225+
Flag: "dormancy-threshold",
226+
Description: "Specify a duration workspaces may be inactive prior to being moved to the dormant state. This licensed feature's default is 0h (off). Maps to \"Dormancy threshold\" in the UI.",
225227
Default: "0h",
226-
Value: clibase.DurationOf(&inactivityTTL),
228+
Value: clibase.DurationOf(&dormancyThreshold),
227229
},
230+
{
231+
Flag: "dormancy-auto-deletion",
232+
Description: "Specify a duration workspaces may be in the dormant state prior to being deleted. This licensed feature's default is 0h (off). Maps to \"Dormancy Auto-Deletion\" in the UI.",
233+
Default: "0h",
234+
Value: clibase.DurationOf(&dormancyAutoDeletion),
235+
},
236+
228237
{
229238
Flag: "max-ttl",
230239
Description: "Edit the template maximum time before shutdown - workspaces created from this template must shutdown within the given duration after starting. This is an enterprise-only feature.",

cli/templateedit.go

+32-14
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
2828
autostopRequirementWeeks int64
2929
autostartRequirementDaysOfWeek []string
3030
failureTTL time.Duration
31-
inactivityTTL time.Duration
31+
dormancyThreshold time.Duration
32+
dormancyAutoDeletion time.Duration
3233
allowUserCancelWorkspaceJobs bool
3334
allowUserAutostart bool
3435
allowUserAutostop bool
@@ -46,14 +47,14 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
4647
Short: "Edit the metadata of a template by name.",
4748
Handler: func(inv *clibase.Invocation) error {
4849
// This clause can be removed when workspace_actions is no longer experimental
49-
if failureTTL != 0 || inactivityTTL != 0 {
50+
if failureTTL != 0 || dormancyThreshold != 0 || dormancyAutoDeletion != 0 {
5051
experiments, exErr := client.Experiments(inv.Context())
5152
if exErr != nil {
5253
return xerrors.Errorf("get experiments: %w", exErr)
5354
}
5455

5556
if !experiments.Enabled(codersdk.ExperimentWorkspaceActions) {
56-
return xerrors.Errorf("--failure-ttl and --inactivity-ttl are experimental features. Use the workspace_actions CODER_EXPERIMENTS flag to set these configuration values.")
57+
return xerrors.Errorf("--failure-ttl, --dormancy-threshold, and --dormancy-auto-deletion are experimental features. Use the workspace_actions CODER_EXPERIMENTS flag to set these configuration values.")
5758
}
5859
}
5960

@@ -64,7 +65,8 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
6465
!allowUserAutostop ||
6566
maxTTL != 0 ||
6667
failureTTL != 0 ||
67-
inactivityTTL != 0 ||
68+
dormancyThreshold != 0 ||
69+
dormancyAutoDeletion != 0 ||
6870
len(autostartRequirementDaysOfWeek) > 0
6971

7072
requiresEntitlement := requiresScheduling || requireActiveVersion
@@ -119,6 +121,15 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
119121
if unsetAutostopRequirementDaysOfWeek {
120122
autostopRequirementDaysOfWeek = []string{}
121123
}
124+
if failureTTL == 0 {
125+
failureTTL = time.Duration(template.FailureTTLMillis) * time.Millisecond
126+
}
127+
if dormancyThreshold == 0 {
128+
dormancyThreshold = time.Duration(template.TimeTilDormantMillis) * time.Millisecond
129+
}
130+
if dormancyAutoDeletion == 0 {
131+
dormancyAutoDeletion = time.Duration(template.TimeTilDormantAutoDeleteMillis) * time.Millisecond
132+
}
122133

123134
// Default values
124135
if !userSetOption(inv, "description") {
@@ -152,13 +163,14 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
152163
AutostartRequirement: &codersdk.TemplateAutostartRequirement{
153164
DaysOfWeek: autostartRequirementDaysOfWeek,
154165
},
155-
FailureTTLMillis: failureTTL.Milliseconds(),
156-
TimeTilDormantMillis: inactivityTTL.Milliseconds(),
157-
AllowUserCancelWorkspaceJobs: allowUserCancelWorkspaceJobs,
158-
AllowUserAutostart: allowUserAutostart,
159-
AllowUserAutostop: allowUserAutostop,
160-
RequireActiveVersion: requireActiveVersion,
161-
DeprecationMessage: deprecated,
166+
FailureTTLMillis: failureTTL.Milliseconds(),
167+
TimeTilDormantMillis: dormancyThreshold.Milliseconds(),
168+
TimeTilDormantAutoDeleteMillis: dormancyAutoDeletion.Milliseconds(),
169+
AllowUserCancelWorkspaceJobs: allowUserCancelWorkspaceJobs,
170+
AllowUserAutostart: allowUserAutostart,
171+
AllowUserAutostop: allowUserAutostop,
172+
RequireActiveVersion: requireActiveVersion,
173+
DeprecationMessage: deprecated,
162174
}
163175

164176
_, err = client.UpdateTemplateMeta(inv.Context(), template.ID, req)
@@ -254,10 +266,16 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
254266
Value: clibase.DurationOf(&failureTTL),
255267
},
256268
{
257-
Flag: "inactivity-ttl",
258-
Description: "Specify an inactivity TTL for workspaces created from this template. It is the amount of time the workspace is not used before it is be stopped and auto-locked. This includes across multiple builds (e.g. auto-starts and stops). This licensed feature's default is 0h (off). Maps to \"Dormancy threshold\" in the UI.",
269+
Flag: "dormancy-threshold",
270+
Description: "Specify a duration workspaces may be inactive prior to being moved to the dormant state. This licensed feature's default is 0h (off). Maps to \"Dormancy threshold\" in the UI.",
271+
Default: "0h",
272+
Value: clibase.DurationOf(&dormancyThreshold),
273+
},
274+
{
275+
Flag: "dormancy-auto-deletion",
276+
Description: "Specify a duration workspaces may be in the dormant state prior to being deleted. This licensed feature's default is 0h (off). Maps to \"Dormancy Auto-Deletion\" in the UI.",
259277
Default: "0h",
260-
Value: clibase.DurationOf(&inactivityTTL),
278+
Value: clibase.DurationOf(&dormancyAutoDeletion),
261279
},
262280
{
263281
Flag: "allow-user-cancel-workspace-jobs",

cli/testdata/coder_templates_create_--help.golden

+10-7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ OPTIONS:
1414
-d, --directory string (default: .)
1515
Specify the directory to create from, use '-' to read tar from stdin.
1616

17+
--dormancy-auto-deletion duration (default: 0h)
18+
Specify a duration workspaces may be in the dormant state prior to
19+
being deleted. This licensed feature's default is 0h (off). Maps to
20+
"Dormancy Auto-Deletion" in the UI.
21+
22+
--dormancy-threshold duration (default: 0h)
23+
Specify a duration workspaces may be inactive prior to being moved to
24+
the dormant state. This licensed feature's default is 0h (off). Maps
25+
to "Dormancy threshold" in the UI.
26+
1727
--failure-ttl duration (default: 0h)
1828
Specify a failure TTL for workspaces created from this template. It is
1929
the amount of time after a failed "start" build before coder
@@ -24,13 +34,6 @@ OPTIONS:
2434
Ignore warnings about not having a .terraform.lock.hcl file present in
2535
the template.
2636

27-
--inactivity-ttl duration (default: 0h)
28-
Specify an inactivity TTL for workspaces created from this template.
29-
It is the amount of time the workspace is not used before it is be
30-
stopped and auto-locked. This includes across multiple builds (e.g.
31-
auto-starts and stops). This licensed feature's default is 0h (off).
32-
Maps to "Dormancy threshold" in the UI.
33-
3437
--max-ttl duration
3538
Edit the template maximum time before shutdown - workspaces created
3639
from this template must shutdown within the given duration after

cli/testdata/coder_templates_edit_--help.golden

+10-7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ OPTIONS:
3838
--display-name string
3939
Edit the template display name.
4040

41+
--dormancy-auto-deletion duration (default: 0h)
42+
Specify a duration workspaces may be in the dormant state prior to
43+
being deleted. This licensed feature's default is 0h (off). Maps to
44+
"Dormancy Auto-Deletion" in the UI.
45+
46+
--dormancy-threshold duration (default: 0h)
47+
Specify a duration workspaces may be inactive prior to being moved to
48+
the dormant state. This licensed feature's default is 0h (off). Maps
49+
to "Dormancy threshold" in the UI.
50+
4151
--failure-ttl duration (default: 0h)
4252
Specify a failure TTL for workspaces created from this template. It is
4353
the amount of time after a failed "start" build before coder
@@ -47,13 +57,6 @@ OPTIONS:
4757
--icon string
4858
Edit the template icon path.
4959

50-
--inactivity-ttl duration (default: 0h)
51-
Specify an inactivity TTL for workspaces created from this template.
52-
It is the amount of time the workspace is not used before it is be
53-
stopped and auto-locked. This includes across multiple builds (e.g.
54-
auto-starts and stops). This licensed feature's default is 0h (off).
55-
Maps to "Dormancy threshold" in the UI.
56-
5760
--max-ttl duration
5861
Edit the template maximum time before shutdown - workspaces created
5962
from this template must shutdown within the given duration after

docs/cli/templates_create.md

+18-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/cli/templates_edit.md

+18-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)