Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
744e476
added workspace actions entitlement
Kira-Pilot May 1, 2023
e6e1ec6
added workspace actions experiment
Kira-Pilot May 1, 2023
c049e9e
added new route for template enterprise meta
Kira-Pilot May 3, 2023
537ced7
removing new route; repurposing old
Kira-Pilot May 3, 2023
cd6a485
add new fields to get endpoints
Kira-Pilot May 3, 2023
6c984fa
Merge remote-tracking branch 'origin/main' into workspace-actions-tem…
Kira-Pilot May 3, 2023
57a9de7
removed workspace actions experiment
Kira-Pilot May 3, 2023
07cb07c
added logic to enterprise template store
Kira-Pilot May 3, 2023
7091fc1
added new form fields
Kira-Pilot May 3, 2023
e565225
feature flagged new fields
Kira-Pilot May 3, 2023
3d9f6f5
fix validation
Kira-Pilot May 4, 2023
abab4c8
fixed submit btn
Kira-Pilot May 4, 2023
ad37203
Merge remote-tracking branch 'origin/main' into workspace-actions-tem…
Kira-Pilot May 4, 2023
240f297
fix tests
Kira-Pilot May 4, 2023
be512ee
changed ttl defaults
Kira-Pilot May 4, 2023
8536b75
added FE tests
Kira-Pilot May 4, 2023
a05eb6c
added BE tests
Kira-Pilot May 4, 2023
0478e07
fixed lint
Kira-Pilot May 4, 2023
bba4722
adjusted comment language
Kira-Pilot May 4, 2023
c76a0f4
fixing unstaged changes check
Kira-Pilot May 4, 2023
9db6b13
fix test
Kira-Pilot May 4, 2023
a2a38f0
Merge branch 'main' into workspace-actions-template-route/kira-pilot
Kira-Pilot May 4, 2023
9fa9c5b
Update coderd/database/migrations/000122_add_template_cleanup_ttls.do…
Kira-Pilot May 5, 2023
43a2267
Update coderd/database/migrations/000122_add_template_cleanup_ttls.up…
Kira-Pilot May 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added logic to enterprise template store
  • Loading branch information
Kira-Pilot committed May 3, 2023
commit 07cb07c506e570a83f012d60a935837efb00a0d4
2 changes: 2 additions & 0 deletions coderd/database/dbfake/databasefake.go
Original file line number Diff line number Diff line change
Expand Up @@ -1945,6 +1945,8 @@ func (q *fakeQuerier) UpdateTemplateScheduleByID(_ context.Context, arg database
tpl.UpdatedAt = database.Now()
tpl.DefaultTTL = arg.DefaultTTL
tpl.MaxTTL = arg.MaxTTL
tpl.FailureTTL = arg.FailureTTL
tpl.InactivityTTL = arg.InactivityTTL
q.templates[idx] = tpl
return tpl.DeepCopy(), nil
}
Expand Down
6 changes: 6 additions & 0 deletions enterprise/coderd/provisionerdaemons.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,16 @@ func (*enterpriseTemplateScheduleStore) GetTemplateScheduleOptions(ctx context.C
UserAutostopEnabled: tpl.AllowUserAutostop,
DefaultTTL: time.Duration(tpl.DefaultTTL),
MaxTTL: time.Duration(tpl.MaxTTL),
FailureTTL: time.Duration(tpl.FailureTTL),
InactivityTTL: time.Duration(tpl.InactivityTTL),
}, nil
}

func (*enterpriseTemplateScheduleStore) SetTemplateScheduleOptions(ctx context.Context, db database.Store, tpl database.Template, opts schedule.TemplateScheduleOptions) (database.Template, error) {
if int64(opts.DefaultTTL) == tpl.DefaultTTL &&
int64(opts.MaxTTL) == tpl.MaxTTL &&
int64(opts.FailureTTL) == tpl.FailureTTL &&
int64(opts.InactivityTTL) == tpl.InactivityTTL &&
Copy link
Member Author

Choose a reason for hiding this comment

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

@deansheather I see us making what looks like a duplicate check in the patchTemplateMeta handler - curious why we need to check at all (I don't see us doing this in other routes) and also why we need to check twice, once in the handler and once in the store.

Copy link
Member

Choose a reason for hiding this comment

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

You're right this does seem unnecessary and can probably be removed from the handlers and just kept in the store. Make sure the AGPL version of the store has the equivalent check though (but only for the AGPL-permitted fields)!

Copy link
Member Author

Choose a reason for hiding this comment

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

Great, will handle that in a follow-up!

opts.UserAutostartEnabled == tpl.AllowUserAutostart &&
opts.UserAutostopEnabled == tpl.AllowUserAutostop {
// Avoid updating the UpdatedAt timestamp if nothing will be changed.
Expand All @@ -341,6 +345,8 @@ func (*enterpriseTemplateScheduleStore) SetTemplateScheduleOptions(ctx context.C
AllowUserAutostop: opts.UserAutostopEnabled,
DefaultTTL: int64(opts.DefaultTTL),
MaxTTL: int64(opts.MaxTTL),
FailureTTL: int64(opts.FailureTTL),
InactivityTTL: int64(opts.InactivityTTL),
})
if err != nil {
return database.Template{}, xerrors.Errorf("update template schedule: %w", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const TTLHelperText = ({

const MAX_TTL_DAYS = 7
const MS_HOUR_CONVERSION = 3600000
const MS_DAY_CONVERSION = 86400000

export const getValidationSchema = (): Yup.AnyObjectSchema =>
Yup.object({
Expand Down Expand Up @@ -79,11 +80,18 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
initialValues: {
// on display, convert from ms => hours
default_ttl_ms: template.default_ttl_ms / MS_HOUR_CONVERSION,
// the API ignores this value, but to avoid tripping up validation set
// the API ignores these values, but to avoid tripping up validation set
// it to zero if the user can't set the field.
max_ttl_ms: allowAdvancedScheduling
? template.max_ttl_ms / MS_HOUR_CONVERSION
: 0,
failure_ttl_ms: allowAdvancedScheduling
? template.failure_ttl_ms / MS_DAY_CONVERSION
: 0,
inactivity_ttl_ms: allowAdvancedScheduling
? template.inactivity_ttl_ms / MS_DAY_CONVERSION
: 0,

allow_user_autostart: template.allow_user_autostart,
allow_user_autostop: template.allow_user_autostop,
},
Expand All @@ -97,6 +105,13 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
max_ttl_ms: formData.max_ttl_ms
? formData.max_ttl_ms * MS_HOUR_CONVERSION
: undefined,
failure_ttl_ms: formData.failure_ttl_ms
? formData.failure_ttl_ms * MS_DAY_CONVERSION
: undefined,
inactivity_ttl_ms: formData.inactivity_ttl_ms
? formData.inactivity_ttl_ms * MS_DAY_CONVERSION
: undefined,

allow_user_autostart: formData.allow_user_autostart,
allow_user_autostop: formData.allow_user_autostop,
})
Expand Down Expand Up @@ -215,7 +230,38 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
</Stack>
</Stack>
</FormSection>

<FormSection
title="Failure Cleanup"
description="When enabled, Coder will automatically stop workspaces that are in a failed state after a specified number of days."
>
<Stack direction="row">
<TextField
{...getFieldHelpers("failure_ttl_ms")}
disabled={isSubmitting}
fullWidth
inputProps={{ min: 0, step: 1 }}
label="Time until cleanup (days)"
variant="outlined"
type="number"
/>
</Stack>
</FormSection>
<FormSection
title="Inactivity Cleanup"
description="When enabled, Coder will automatically delete workspaces that are in an inactive state after a specified number of days."
>
<Stack direction="row">
<TextField
{...getFieldHelpers("inactivity_ttl_ms")}
disabled={isSubmitting}
fullWidth
inputProps={{ min: 0, step: 1 }}
label="Time until cleanup (days)"
variant="outlined"
type="number"
/>
</Stack>
</FormSection>
<FormFooter onCancel={onCancel} isLoading={isSubmitting} />
</HorizontalForm>
)
Expand Down