chore: remove max_ttl from templates (#12644)

* chore: remove max_ttl from templates

Completely removing max_ttl as a feature on template scheduling. Must use other template scheduling features to achieve autostop.
This commit is contained in:
Steven Masley
2024-03-20 10:37:57 -05:00
committed by GitHub
parent d82e20152b
commit d789a60d47
51 changed files with 151 additions and 1304 deletions
+3 -30
View File
@@ -480,13 +480,7 @@ func (api *API) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Req
return
}
maxTTL := templateSchedule.MaxTTL
if !templateSchedule.UseMaxTTL {
// If we're using autostop requirements, there isn't a max TTL.
maxTTL = 0
}
dbTTL, err := validWorkspaceTTLMillis(createWorkspace.TTLMillis, templateSchedule.DefaultTTL, maxTTL)
dbTTL, err := validWorkspaceTTLMillis(createWorkspace.TTLMillis, templateSchedule.DefaultTTL)
if err != nil {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: "Invalid Workspace Time to Shutdown.",
@@ -857,16 +851,10 @@ func (api *API) putWorkspaceTTL(rw http.ResponseWriter, r *http.Request) {
return codersdk.ValidationError{Field: "ttl_ms", Detail: "Custom autostop TTL is not allowed for workspaces using this template."}
}
maxTTL := templateSchedule.MaxTTL
if !templateSchedule.UseMaxTTL {
// If we're using autostop requirements, there isn't a max TTL.
maxTTL = 0
}
// don't override 0 ttl with template default here because it indicates
// disabled autostop
var validityErr error
dbTTL, validityErr = validWorkspaceTTLMillis(req.TTLMillis, 0, maxTTL)
dbTTL, validityErr = validWorkspaceTTLMillis(req.TTLMillis, 0)
if validityErr != nil {
return codersdk.ValidationError{Field: "ttl_ms", Detail: validityErr.Error()}
}
@@ -1685,20 +1673,9 @@ func convertWorkspaceTTLMillis(i sql.NullInt64) *int64 {
return &millis
}
func validWorkspaceTTLMillis(millis *int64, templateDefault, templateMax time.Duration) (sql.NullInt64, error) {
if templateDefault == 0 && templateMax != 0 || (templateMax > 0 && templateDefault > templateMax) {
templateDefault = templateMax
}
func validWorkspaceTTLMillis(millis *int64, templateDefault time.Duration) (sql.NullInt64, error) {
if ptr.NilOrZero(millis) {
if templateDefault == 0 {
if templateMax > 0 {
return sql.NullInt64{
Int64: int64(templateMax),
Valid: true,
}, nil
}
return sql.NullInt64{}, nil
}
@@ -1718,10 +1695,6 @@ func validWorkspaceTTLMillis(millis *int64, templateDefault, templateMax time.Du
return sql.NullInt64{}, errTTLMax
}
if templateMax > 0 && truncated > templateMax {
return sql.NullInt64{}, xerrors.Errorf("time until shutdown must be less than or equal to the template's maximum TTL %q", templateMax.String())
}
return sql.NullInt64{
Valid: true,
Int64: int64(truncated),