Skip to content
Prev Previous commit
Next Next commit
drive-by: default ttl to min(12 hours, template max) for new workspaces
  • Loading branch information
johnstcn committed Jun 14, 2022
commit 91e3171d1bdec966845f5345aa50ec302027ef81
11 changes: 9 additions & 2 deletions coderd/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ func (api *API) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Req
}

if !dbTTL.Valid {
// Default to template maximum when creating a new workspace
dbTTL = sql.NullInt64{Valid: true, Int64: template.MaxTtl}
// Default to min(12 hours, template maximum). Just defaulting to template maximum can be surprising.
dbTTL = sql.NullInt64{Valid: true, Int64: min(template.MaxTtl, int64(12*time.Hour))}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review: as the default max_ttl for templates is 168 hours, setting the workspace default to something hopefully more reasonable on a day-to-day basis. Folks can still change this if they want!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion (non-blocking): Should we make this a constant somewhere, or perhaps define in the db? It could be hard to determine where this limit is coming from.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constant sounds good!

}

workspace, err := api.Database.GetWorkspaceByOwnerIDAndName(r.Context(), database.GetWorkspaceByOwnerIDAndNameParams{
Expand Down Expand Up @@ -940,3 +940,10 @@ func validWorkspaceSchedule(s *string, min time.Duration) (sql.NullString, error
String: *s,
}, nil
}

func min(x, y int64) int64 {
if x < y {
return x
}
return y
}