Skip to content

fix: coderd: decouple ttl and deadline #2282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 14, 2022
Prev Previous commit
Next Next commit
address PR comments
  • Loading branch information
johnstcn committed Jun 14, 2022
commit bbd8288a6fcd5d18803d5e044bf10f8a686d31fc
5 changes: 3 additions & 2 deletions cli/bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ func bump() *cobra.Command {

_, _ = fmt.Fprintf(
cmd.OutOrStdout(),
"Workspace %q will now stop at %s\n", workspace.Name,
newDeadline.Format(time.RFC822),
"Workspace %q will now stop at %s on %s\n", workspace.Name,
newDeadline.Format(timeFormat),
newDeadline.Format(dateFormat),
)

return nil
Expand Down
6 changes: 6 additions & 0 deletions cli/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package cli

const (
timeFormat = "3:04:05 PM MST"
dateFormat = "Jan 2, 2006"
)
6 changes: 4 additions & 2 deletions cli/ttl.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,12 @@ func ttlset() *cobra.Command {
nextShutdown := sched.Next(time.Now()).Add(truncated).In(sched.Location())
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "%q will shut down at %s on %s (%s after start).\n",
workspace.Name,
nextShutdown.Format("15:04:05 MST"),
nextShutdown.Format("2006-02-01"),
nextShutdown.Format(timeFormat),
nextShutdown.Format(dateFormat),
truncated,
)

_, _ = fmt.Fprintf(cmd.OutOrStdout(), "NOTE: this will only take effect the next time the workspace is started.\n")
return nil
},
}
Expand Down
4 changes: 3 additions & 1 deletion coderd/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"github.com/coder/coder/codersdk"
)

const workspaceDefaultTTL = 12 * time.Hour

func (api *API) workspace(rw http.ResponseWriter, r *http.Request) {
workspace := httpmw.WorkspaceParam(r)
if !api.Authorize(rw, r, rbac.ActionRead, workspace) {
Expand Down Expand Up @@ -320,7 +322,7 @@ func (api *API) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Req

if !dbTTL.Valid {
// 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))}
dbTTL = sql.NullInt64{Valid: true, Int64: min(template.MaxTtl, int64(workspaceDefaultTTL))}
}

workspace, err := api.Database.GetWorkspaceByOwnerIDAndName(r.Context(), database.GetWorkspaceByOwnerIDAndNameParams{
Expand Down