Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd789a60

Browse files
authored
chore: remove max_ttl from templates (#12644)
* chore: remove max_ttl from templatesCompletely removing max_ttl as a feature on template scheduling. Must use other template scheduling features to achieve autostop.
1 parentd82e201 commitd789a60

File tree

51 files changed

+150
-1303
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+150
-1303
lines changed

‎cli/templatecreate.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ func (r *RootCmd) templateCreate() *serpent.Command {
2929
failureTTL time.Duration
3030
dormancyThreshold time.Duration
3131
dormancyAutoDeletion time.Duration
32-
maxTTL time.Duration
3332

3433
uploadFlagstemplateUploadFlags
3534
)
@@ -46,7 +45,7 @@ func (r *RootCmd) templateCreate() *serpent.Command {
4645
r.InitClient(client),
4746
),
4847
Handler:func(inv*serpent.Invocation)error {
49-
isTemplateSchedulingOptionsSet:=failureTTL!=0||dormancyThreshold!=0||dormancyAutoDeletion!=0||maxTTL!=0
48+
isTemplateSchedulingOptionsSet:=failureTTL!=0||dormancyThreshold!=0||dormancyAutoDeletion!=0
5049

5150
ifisTemplateSchedulingOptionsSet||requireActiveVersion {
5251
entitlements,err:=client.Entitlements(inv.Context())
@@ -58,7 +57,7 @@ func (r *RootCmd) templateCreate() *serpent.Command {
5857

5958
ifisTemplateSchedulingOptionsSet {
6059
if!entitlements.Features[codersdk.FeatureAdvancedTemplateScheduling].Enabled {
61-
returnxerrors.Errorf("your license is not entitled to use advanced template scheduling, so you cannot set --failure-ttl,--inactivity-ttl,or --max-ttl")
60+
returnxerrors.Errorf("your license is not entitled to use advanced template scheduling, so you cannot set --failure-ttl, or --inactivity-ttl")
6261
}
6362
}
6463

@@ -154,7 +153,6 @@ func (r *RootCmd) templateCreate() *serpent.Command {
154153
VersionID:job.ID,
155154
DefaultTTLMillis:ptr.Ref(defaultTTL.Milliseconds()),
156155
FailureTTLMillis:ptr.Ref(failureTTL.Milliseconds()),
157-
MaxTTLMillis:ptr.Ref(maxTTL.Milliseconds()),
158156
TimeTilDormantMillis:ptr.Ref(dormancyThreshold.Milliseconds()),
159157
TimeTilDormantAutoDeleteMillis:ptr.Ref(dormancyAutoDeletion.Milliseconds()),
160158
DisableEveryoneGroupAccess:disableEveryone,
@@ -229,12 +227,6 @@ func (r *RootCmd) templateCreate() *serpent.Command {
229227
Default:"0h",
230228
Value:serpent.DurationOf(&dormancyAutoDeletion),
231229
},
232-
233-
{
234-
Flag:"max-ttl",
235-
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.",
236-
Value:serpent.DurationOf(&maxTTL),
237-
},
238230
{
239231
Flag:"test.provisioner",
240232
Description:"Customize the provisioner backend.",

‎cli/templateedit.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ func (r *RootCmd) templateEdit() *serpent.Command {
2424
iconstring
2525
defaultTTL time.Duration
2626
activityBump time.Duration
27-
maxTTL time.Duration
2827
autostopRequirementDaysOfWeek []string
2928
autostopRequirementWeeksint64
3029
autostartRequirementDaysOfWeek []string
@@ -53,7 +52,6 @@ func (r *RootCmd) templateEdit() *serpent.Command {
5352
autostopRequirementWeeks>0||
5453
!allowUserAutostart||
5554
!allowUserAutostop||
56-
maxTTL!=0||
5755
failureTTL!=0||
5856
dormancyThreshold!=0||
5957
dormancyAutoDeletion!=0||
@@ -69,7 +67,7 @@ func (r *RootCmd) templateEdit() *serpent.Command {
6967
}
7068

7169
ifrequiresScheduling&&!entitlements.Features[codersdk.FeatureAdvancedTemplateScheduling].Enabled {
72-
returnxerrors.Errorf("your license is not entitled to use advanced template scheduling, so you cannot set --max-ttl, --failure-ttl, --inactivityTTL, --allow-user-autostart=false or --allow-user-autostop=false")
70+
returnxerrors.Errorf("your license is not entitled to use advanced template scheduling, so you cannot set --failure-ttl, --inactivityTTL, --allow-user-autostart=false or --allow-user-autostop=false")
7371
}
7472

7573
ifrequireActiveVersion {
@@ -101,10 +99,6 @@ func (r *RootCmd) templateEdit() *serpent.Command {
10199
displayName=template.DisplayName
102100
}
103101

104-
if!userSetOption(inv,"max-ttl") {
105-
maxTTL=time.Duration(template.MaxTTLMillis)*time.Millisecond
106-
}
107-
108102
if!userSetOption(inv,"default-ttl") {
109103
defaultTTL=time.Duration(template.DefaultTTLMillis)*time.Millisecond
110104
}
@@ -179,7 +173,6 @@ func (r *RootCmd) templateEdit() *serpent.Command {
179173
Icon:icon,
180174
DefaultTTLMillis:defaultTTL.Milliseconds(),
181175
ActivityBumpMillis:activityBump.Milliseconds(),
182-
MaxTTLMillis:maxTTL.Milliseconds(),
183176
AutostopRequirement:&codersdk.TemplateAutostopRequirement{
184177
DaysOfWeek:autostopRequirementDaysOfWeek,
185178
Weeks:autostopRequirementWeeks,
@@ -244,11 +237,6 @@ func (r *RootCmd) templateEdit() *serpent.Command {
244237
Description:"Edit the template activity bump - workspaces created from this template will have their shutdown time bumped by this value when activity is detected. Maps to\"Activity bump\" in the UI.",
245238
Value:serpent.DurationOf(&activityBump),
246239
},
247-
{
248-
Flag:"max-ttl",
249-
Description:"Edit the template maximum time before shutdown - workspaces created from this template must shutdown within the given duration after starting, regardless of user activity. This is an enterprise-only feature. Maps to\"Max lifetime\" in the UI.",
250-
Value:serpent.DurationOf(&maxTTL),
251-
},
252240
{
253241
Flag:"autostart-requirement-weekdays",
254242
// workspaces created from this template must be restarted on the given weekdays. To unset this value for the template (and disable the autostop requirement for the template), pass 'none'.
@@ -268,8 +256,6 @@ func (r *RootCmd) templateEdit() *serpent.Command {
268256
{
269257
Flag:"autostop-requirement-weekdays",
270258
Description:"Edit the template autostop requirement weekdays - workspaces created from this template must be restarted on the given weekdays. To unset this value for the template (and disable the autostop requirement for the template), pass 'none'.",
271-
// TODO(@dean): unhide when we delete max_ttl
272-
Hidden:true,
273259
Value:serpent.Validate(serpent.StringArrayOf(&autostopRequirementDaysOfWeek),func(value*serpent.StringArray)error {
274260
v:=value.GetSlice()
275261
iflen(v)==1&&v[0]=="none" {
@@ -285,9 +271,7 @@ func (r *RootCmd) templateEdit() *serpent.Command {
285271
{
286272
Flag:"autostop-requirement-weeks",
287273
Description:"Edit the template autostop requirement weeks - workspaces created from this template must be restarted on an n-weekly basis.",
288-
// TODO(@dean): unhide when we delete max_ttl
289-
Hidden:true,
290-
Value:serpent.Int64Of(&autostopRequirementWeeks),
274+
Value:serpent.Int64Of(&autostopRequirementWeeks),
291275
},
292276
{
293277
Flag:"failure-ttl",

‎cli/templateedit_test.go

Lines changed: 0 additions & 213 deletions
Original file line numberDiff line numberDiff line change
@@ -552,220 +552,7 @@ func TestTemplateEdit(t *testing.T) {
552552
assert.Equal(t,template.AutostartRequirement.DaysOfWeek,updated.AutostartRequirement.DaysOfWeek)
553553
})
554554
})
555-
// TODO(@dean): remove this test when we remove max_ttl
556-
t.Run("MaxTTL",func(t*testing.T) {
557-
t.Parallel()
558-
t.Run("BlockedAGPL",func(t*testing.T) {
559-
t.Parallel()
560-
client:=coderdtest.New(t,&coderdtest.Options{IncludeProvisionerDaemon:true})
561-
owner:=coderdtest.CreateFirstUser(t,client)
562-
templateAdmin,_:=coderdtest.CreateAnotherUser(t,client,owner.OrganizationID,rbac.RoleTemplateAdmin())
563-
version:=coderdtest.CreateTemplateVersion(t,client,owner.OrganizationID,nil)
564-
_=coderdtest.AwaitTemplateVersionJobCompleted(t,client,version.ID)
565-
template:=coderdtest.CreateTemplate(t,client,owner.OrganizationID,version.ID,func(ctr*codersdk.CreateTemplateRequest) {
566-
ctr.DefaultTTLMillis=nil
567-
ctr.MaxTTLMillis=nil
568-
})
569-
570-
// Test the cli command.
571-
cmdArgs:= []string{
572-
"templates",
573-
"edit",
574-
template.Name,
575-
"--max-ttl","1h",
576-
}
577-
inv,root:=clitest.New(t,cmdArgs...)
578-
clitest.SetupConfig(t,templateAdmin,root)
579555

580-
ctx:=testutil.Context(t,testutil.WaitLong)
581-
err:=inv.WithContext(ctx).Run()
582-
require.Error(t,err)
583-
require.ErrorContains(t,err,"appears to be an AGPL deployment")
584-
585-
// Assert that the template metadata did not change.
586-
updated,err:=client.Template(context.Background(),template.ID)
587-
require.NoError(t,err)
588-
assert.Equal(t,template.Name,updated.Name)
589-
assert.Equal(t,template.Description,updated.Description)
590-
assert.Equal(t,template.Icon,updated.Icon)
591-
assert.Equal(t,template.DisplayName,updated.DisplayName)
592-
assert.Equal(t,template.DefaultTTLMillis,updated.DefaultTTLMillis)
593-
assert.Equal(t,template.MaxTTLMillis,updated.MaxTTLMillis)
594-
})
595-
596-
t.Run("BlockedNotEntitled",func(t*testing.T) {
597-
t.Parallel()
598-
client:=coderdtest.New(t,&coderdtest.Options{IncludeProvisionerDaemon:true})
599-
owner:=coderdtest.CreateFirstUser(t,client)
600-
templateAdmin,_:=coderdtest.CreateAnotherUser(t,client,owner.OrganizationID,rbac.RoleTemplateAdmin())
601-
version:=coderdtest.CreateTemplateVersion(t,client,owner.OrganizationID,nil)
602-
_=coderdtest.AwaitTemplateVersionJobCompleted(t,client,version.ID)
603-
template:=coderdtest.CreateTemplate(t,client,owner.OrganizationID,version.ID,func(ctr*codersdk.CreateTemplateRequest) {
604-
ctr.DefaultTTLMillis=nil
605-
ctr.MaxTTLMillis=nil
606-
})
607-
608-
// Make a proxy server that will return a valid entitlements
609-
// response, but without advanced scheduling entitlement.
610-
proxy:=httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter,r*http.Request) {
611-
ifr.URL.Path=="/api/v2/entitlements" {
612-
res:= codersdk.Entitlements{
613-
Features:map[codersdk.FeatureName]codersdk.Feature{},
614-
Warnings: []string{},
615-
Errors: []string{},
616-
HasLicense:true,
617-
Trial:true,
618-
RequireTelemetry:false,
619-
}
620-
for_,feature:=rangecodersdk.FeatureNames {
621-
res.Features[feature]= codersdk.Feature{
622-
Entitlement:codersdk.EntitlementNotEntitled,
623-
Enabled:false,
624-
Limit:nil,
625-
Actual:nil,
626-
}
627-
}
628-
httpapi.Write(r.Context(),w,http.StatusOK,res)
629-
return
630-
}
631-
632-
// Otherwise, proxy the request to the real API server.
633-
rp:=httputil.NewSingleHostReverseProxy(client.URL)
634-
tp:=&http.Transport{}
635-
defertp.CloseIdleConnections()
636-
rp.Transport=tp
637-
rp.ServeHTTP(w,r)
638-
}))
639-
deferproxy.Close()
640-
641-
// Create a new client that uses the proxy server.
642-
proxyURL,err:=url.Parse(proxy.URL)
643-
require.NoError(t,err)
644-
proxyClient:=codersdk.New(proxyURL)
645-
proxyClient.SetSessionToken(templateAdmin.SessionToken())
646-
t.Cleanup(proxyClient.HTTPClient.CloseIdleConnections)
647-
648-
// Test the cli command.
649-
cmdArgs:= []string{
650-
"templates",
651-
"edit",
652-
template.Name,
653-
"--max-ttl","1h",
654-
}
655-
inv,root:=clitest.New(t,cmdArgs...)
656-
clitest.SetupConfig(t,proxyClient,root)
657-
658-
ctx:=testutil.Context(t,testutil.WaitLong)
659-
err=inv.WithContext(ctx).Run()
660-
require.Error(t,err)
661-
require.ErrorContains(t,err,"license is not entitled")
662-
663-
// Assert that the template metadata did not change.
664-
updated,err:=client.Template(context.Background(),template.ID)
665-
require.NoError(t,err)
666-
assert.Equal(t,template.Name,updated.Name)
667-
assert.Equal(t,template.Description,updated.Description)
668-
assert.Equal(t,template.Icon,updated.Icon)
669-
assert.Equal(t,template.DisplayName,updated.DisplayName)
670-
assert.Equal(t,template.DefaultTTLMillis,updated.DefaultTTLMillis)
671-
assert.Equal(t,template.MaxTTLMillis,updated.MaxTTLMillis)
672-
})
673-
t.Run("Entitled",func(t*testing.T) {
674-
t.Parallel()
675-
client:=coderdtest.New(t,&coderdtest.Options{IncludeProvisionerDaemon:true})
676-
owner:=coderdtest.CreateFirstUser(t,client)
677-
templateAdmin,_:=coderdtest.CreateAnotherUser(t,client,owner.OrganizationID,rbac.RoleTemplateAdmin())
678-
version:=coderdtest.CreateTemplateVersion(t,client,owner.OrganizationID,nil)
679-
_=coderdtest.AwaitTemplateVersionJobCompleted(t,client,version.ID)
680-
template:=coderdtest.CreateTemplate(t,client,owner.OrganizationID,version.ID,func(ctr*codersdk.CreateTemplateRequest) {
681-
ctr.DefaultTTLMillis=nil
682-
ctr.MaxTTLMillis=nil
683-
})
684-
685-
// Make a proxy server that will return a valid entitlements
686-
// response, including a valid advanced scheduling entitlement.
687-
varupdateTemplateCalledint64
688-
proxy:=httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter,r*http.Request) {
689-
ifr.URL.Path=="/api/v2/entitlements" {
690-
res:= codersdk.Entitlements{
691-
Features:map[codersdk.FeatureName]codersdk.Feature{},
692-
Warnings: []string{},
693-
Errors: []string{},
694-
HasLicense:true,
695-
Trial:true,
696-
RequireTelemetry:false,
697-
}
698-
for_,feature:=rangecodersdk.FeatureNames {
699-
varoneint64=1
700-
res.Features[feature]= codersdk.Feature{
701-
Entitlement:codersdk.EntitlementNotEntitled,
702-
Enabled:true,
703-
Limit:&one,
704-
Actual:&one,
705-
}
706-
}
707-
httpapi.Write(r.Context(),w,http.StatusOK,res)
708-
return
709-
}
710-
ifstrings.HasPrefix(r.URL.Path,"/api/v2/templates/") {
711-
body,err:=io.ReadAll(r.Body)
712-
require.NoError(t,err)
713-
_=r.Body.Close()
714-
715-
varreq codersdk.UpdateTemplateMeta
716-
err=json.Unmarshal(body,&req)
717-
require.NoError(t,err)
718-
assert.Equal(t,time.Hour.Milliseconds(),req.MaxTTLMillis)
719-
720-
r.Body=io.NopCloser(bytes.NewReader(body))
721-
atomic.AddInt64(&updateTemplateCalled,1)
722-
// We still want to call the real route.
723-
}
724-
725-
// Otherwise, proxy the request to the real API server.
726-
rp:=httputil.NewSingleHostReverseProxy(client.URL)
727-
tp:=&http.Transport{}
728-
defertp.CloseIdleConnections()
729-
rp.Transport=tp
730-
rp.ServeHTTP(w,r)
731-
}))
732-
deferproxy.Close()
733-
734-
// Create a new client that uses the proxy server.
735-
proxyURL,err:=url.Parse(proxy.URL)
736-
require.NoError(t,err)
737-
proxyClient:=codersdk.New(proxyURL)
738-
proxyClient.SetSessionToken(templateAdmin.SessionToken())
739-
t.Cleanup(proxyClient.HTTPClient.CloseIdleConnections)
740-
741-
// Test the cli command.
742-
cmdArgs:= []string{
743-
"templates",
744-
"edit",
745-
template.Name,
746-
"--max-ttl","1h",
747-
}
748-
inv,root:=clitest.New(t,cmdArgs...)
749-
clitest.SetupConfig(t,proxyClient,root)
750-
751-
ctx:=testutil.Context(t,testutil.WaitLong)
752-
err=inv.WithContext(ctx).Run()
753-
require.NoError(t,err)
754-
755-
require.EqualValues(t,1,atomic.LoadInt64(&updateTemplateCalled))
756-
757-
// Assert that the template metadata did not change. We verify the
758-
// correct request gets sent to the server already.
759-
updated,err:=client.Template(context.Background(),template.ID)
760-
require.NoError(t,err)
761-
assert.Equal(t,template.Name,updated.Name)
762-
assert.Equal(t,template.Description,updated.Description)
763-
assert.Equal(t,template.Icon,updated.Icon)
764-
assert.Equal(t,template.DisplayName,updated.DisplayName)
765-
assert.Equal(t,template.DefaultTTLMillis,updated.DefaultTTLMillis)
766-
assert.Equal(t,template.MaxTTLMillis,updated.MaxTTLMillis)
767-
})
768-
})
769556
t.Run("AllowUserScheduling",func(t*testing.T) {
770557
t.Parallel()
771558
t.Run("BlockedAGPL",func(t*testing.T) {

‎cli/testdata/coder_server_--help.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ telemetrywhen required by your organization's security policy.
467467

468468
USER QUIET HOURS SCHEDULE OPTIONS:
469469
Allow users to set quiet hours schedules each day for workspaces to avoid
470-
workspaces stopping during the day due to templatemax TTL.
470+
workspaces stopping during the day due to templatescheduling.
471471

472472
--allow-custom-quiet-hours bool, $CODER_ALLOW_CUSTOM_QUIET_HOURS (default: true)
473473
Allow users to set their own quiet hours schedule for workspaces to

‎cli/testdata/coder_templates_create_--help.golden

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ OPTIONS:
3535
Ignore warnings about not having a .terraform.lock.hcl file present in
3636
the template.
3737

38-
--max-ttl duration
39-
Edit the template maximum time before shutdown - workspaces created
40-
from this template must shutdown within the given duration after
41-
starting. This is an enterprise-only feature.
42-
4338
-m, --message string
4439
Specify a message describing the changes in this version of the
4540
template. Messages longer than 72 characters will be displayed as

‎cli/testdata/coder_templates_edit_--help.golden

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ OPTIONS:
2828
this value for the template (and allow autostart on all days), pass
2929
'all'.
3030

31+
--autostop-requirement-weekdays string-array
32+
Edit the template autostop requirement weekdays - workspaces created
33+
from this template must be restarted on the given weekdays. To unset
34+
this value for the template (and disable the autostop requirement for
35+
the template), pass 'none'.
36+
37+
--autostop-requirement-weeks int
38+
Edit the template autostop requirement weeks - workspaces created from
39+
this template must be restarted on an n-weekly basis.
40+
3141
--default-ttl duration
3242
Edit the template default time before shutdown - workspaces created
3343
from this template default to this value. Maps to "Default autostop"
@@ -62,12 +72,6 @@ OPTIONS:
6272
--icon string
6373
Edit the template icon path.
6474

65-
--max-ttl duration
66-
Edit the template maximum time before shutdown - workspaces created
67-
from this template must shutdown within the given duration after
68-
starting, regardless of user activity. This is an enterprise-only
69-
feature. Maps to "Max lifetime" in the UI.
70-
7175
--name string
7276
Edit the template name.
7377

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp