mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
+3
-30
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user