Skip to content

Commit b36071c

Browse files
authored
feat: allow templates to specify max_ttl or autostop_requirement (#10920)
1 parent 30f032d commit b36071c

Some content is hidden

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

46 files changed

+699
-495
lines changed

cli/testdata/coder_server_--help.golden

+6-6
Original file line numberDiff line numberDiff line change
@@ -447,15 +447,15 @@ USER QUIET HOURS SCHEDULE OPTIONS:
447447
Allow users to set quiet hours schedules each day for workspaces to avoid
448448
workspaces stopping during the day due to template max TTL.
449449

450-
--default-quiet-hours-schedule string, $CODER_QUIET_HOURS_DEFAULT_SCHEDULE
450+
--default-quiet-hours-schedule string, $CODER_QUIET_HOURS_DEFAULT_SCHEDULE (default: CRON_TZ=UTC 0 0 * * *)
451451
The default daily cron schedule applied to users that haven't set a
452452
custom quiet hours schedule themselves. The quiet hours schedule
453453
determines when workspaces will be force stopped due to the template's
454-
max TTL, and will round the max TTL up to be within the user's quiet
455-
hours window (or default). The format is the same as the standard cron
456-
format, but the day-of-month, month and day-of-week must be *. Only
457-
one hour and minute can be specified (ranges or comma separated values
458-
are not supported).
454+
autostop requirement, and will round the max deadline up to be within
455+
the user's quiet hours window (or default). The format is the same as
456+
the standard cron format, but the day-of-month, month and day-of-week
457+
must be *. Only one hour and minute can be specified (ranges or comma
458+
separated values are not supported).
459459

460460
⚠️ DANGEROUS OPTIONS:
461461
--dangerous-allow-path-app-sharing bool, $CODER_DANGEROUS_ALLOW_PATH_APP_SHARING

cli/testdata/server-config.yaml.golden

+7-7
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,10 @@ wgtunnelHost: ""
450450
userQuietHoursSchedule:
451451
# The default daily cron schedule applied to users that haven't set a custom quiet
452452
# hours schedule themselves. The quiet hours schedule determines when workspaces
453-
# will be force stopped due to the template's max TTL, and will round the max TTL
454-
# up to be within the user's quiet hours window (or default). The format is the
455-
# same as the standard cron format, but the day-of-month, month and day-of-week
456-
# must be *. Only one hour and minute can be specified (ranges or comma separated
457-
# values are not supported).
458-
# (default: <unset>, type: string)
459-
defaultQuietHoursSchedule: ""
453+
# will be force stopped due to the template's autostop requirement, and will round
454+
# the max deadline up to be within the user's quiet hours window (or default). The
455+
# format is the same as the standard cron format, but the day-of-month, month and
456+
# day-of-week must be *. Only one hour and minute can be specified (ranges or
457+
# comma separated values are not supported).
458+
# (default: CRON_TZ=UTC 0 0 * * *, type: string)
459+
defaultQuietHoursSchedule: CRON_TZ=UTC 0 0 * * *

coderd/apidoc/docs.go

+6-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

+6-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbmem/dbmem.go

+1
Original file line numberDiff line numberDiff line change
@@ -6158,6 +6158,7 @@ func (q *FakeQuerier) UpdateTemplateScheduleByID(_ context.Context, arg database
61586158
tpl.AllowUserAutostop = arg.AllowUserAutostop
61596159
tpl.UpdatedAt = dbtime.Now()
61606160
tpl.DefaultTTL = arg.DefaultTTL
6161+
tpl.UseMaxTtl = arg.UseMaxTtl
61616162
tpl.MaxTTL = arg.MaxTTL
61626163
tpl.AutostopRequirementDaysOfWeek = arg.AutostopRequirementDaysOfWeek
61636164
tpl.AutostopRequirementWeeks = arg.AutostopRequirementWeeks

coderd/database/dump.sql

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
DROP VIEW template_with_users;
2+
3+
ALTER TABLE templates DROP COLUMN use_max_ttl;
4+
5+
CREATE VIEW
6+
template_with_users
7+
AS
8+
SELECT
9+
templates.*,
10+
coalesce(visible_users.avatar_url, '') AS created_by_avatar_url,
11+
coalesce(visible_users.username, '') AS created_by_username
12+
FROM
13+
templates
14+
LEFT JOIN
15+
visible_users
16+
ON
17+
templates.created_by = visible_users.id;
18+
19+
COMMENT ON VIEW template_with_users IS 'Joins in the username + avatar url of the created by user.';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-- Add column with default true, so existing templates will function as usual
2+
ALTER TABLE templates ADD COLUMN use_max_ttl boolean NOT NULL DEFAULT true;
3+
4+
-- Find any templates with autostop_requirement_days_of_week set and set them to
5+
-- use_max_ttl = false
6+
UPDATE templates SET use_max_ttl = false WHERE autostop_requirement_days_of_week != 0;
7+
8+
-- Alter column to default false, because we want autostop_requirement to be the
9+
-- default from now on
10+
ALTER TABLE templates ALTER COLUMN use_max_ttl SET DEFAULT false;
11+
12+
DROP VIEW template_with_users;
13+
14+
CREATE VIEW
15+
template_with_users
16+
AS
17+
SELECT
18+
templates.*,
19+
coalesce(visible_users.avatar_url, '') AS created_by_avatar_url,
20+
coalesce(visible_users.username, '') AS created_by_username
21+
FROM
22+
templates
23+
LEFT JOIN
24+
visible_users
25+
ON
26+
templates.created_by = visible_users.id;
27+
28+
COMMENT ON VIEW template_with_users IS 'Joins in the username + avatar url of the created by user.';

coderd/database/modelqueries.go

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func (q *sqlQuerier) GetAuthorizedTemplates(ctx context.Context, arg GetTemplate
8989
&i.AutostartBlockDaysOfWeek,
9090
&i.RequireActiveVersion,
9191
&i.Deprecated,
92+
&i.UseMaxTtl,
9293
&i.CreatedByAvatarURL,
9394
&i.CreatedByUsername,
9495
); err != nil {

coderd/database/models.go

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

+18-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/templates.sql

+8-7
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,14 @@ SET
128128
allow_user_autostart = $3,
129129
allow_user_autostop = $4,
130130
default_ttl = $5,
131-
max_ttl = $6,
132-
autostop_requirement_days_of_week = $7,
133-
autostop_requirement_weeks = $8,
134-
autostart_block_days_of_week = $9,
135-
failure_ttl = $10,
136-
time_til_dormant = $11,
137-
time_til_dormant_autodelete = $12
131+
use_max_ttl = $6,
132+
max_ttl = $7,
133+
autostop_requirement_days_of_week = $8,
134+
autostop_requirement_weeks = $9,
135+
autostart_block_days_of_week = $10,
136+
failure_ttl = $11,
137+
time_til_dormant = $12,
138+
time_til_dormant_autodelete = $13
138139
WHERE
139140
id = $1
140141
;

0 commit comments

Comments
 (0)