Skip to content

feat: allow templates to specify max_ttl or autostop_requirement #10920

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 10 commits into from
Dec 15, 2023
Prev Previous commit
Next Next commit
Fixes
  • Loading branch information
deansheather committed Dec 15, 2023
commit b33ab522b83c60525261b99b0c43843d3275cdba
4 changes: 2 additions & 2 deletions coderd/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ func (api *API) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Req
}

maxTTL := templateSchedule.MaxTTL
if templateSchedule.UseMaxTTL {
if !templateSchedule.UseMaxTTL {
// If we're using autostop requirements, there isn't a max TTL.
maxTTL = 0
}
Expand Down Expand Up @@ -787,7 +787,7 @@ func (api *API) putWorkspaceTTL(rw http.ResponseWriter, r *http.Request) {
}

maxTTL := templateSchedule.MaxTTL
if templateSchedule.UseMaxTTL {
if !templateSchedule.UseMaxTTL {
// If we're using autostop requirements, there isn't a max TTL.
maxTTL = 0
}
Expand Down
3 changes: 1 addition & 2 deletions enterprise/coderd/schedule/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (s *EnterpriseTemplateScheduleStore) now() time.Time {
}

// Get implements agpl.TemplateScheduleStore.
func (s *EnterpriseTemplateScheduleStore) Get(ctx context.Context, db database.Store, templateID uuid.UUID) (agpl.TemplateScheduleOptions, error) {
func (*EnterpriseTemplateScheduleStore) Get(ctx context.Context, db database.Store, templateID uuid.UUID) (agpl.TemplateScheduleOptions, error) {
ctx, span := tracing.StartSpan(ctx)
defer span.End()

Expand Down Expand Up @@ -181,7 +181,6 @@ func (s *EnterpriseTemplateScheduleStore) Set(ctx context.Context, db database.S
}
}

// TODO: update all workspace max_deadlines to be within new bounds
template, err = tx.GetTemplateByID(ctx, tpl.ID)
if err != nil {
return xerrors.Errorf("get updated template schedule: %w", err)
Expand Down
9 changes: 3 additions & 6 deletions enterprise/coderd/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ func TestUserQuietHours(t *testing.T) {
adminClient, adminUser := coderdenttest.New(t, &coderdenttest.Options{
LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureAdvancedTemplateScheduling: 1,
codersdk.FeatureTemplateAutostopRequirement: 1,
codersdk.FeatureAdvancedTemplateScheduling: 1,
},
},
})
Expand Down Expand Up @@ -63,8 +62,7 @@ func TestUserQuietHours(t *testing.T) {
},
LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureAdvancedTemplateScheduling: 1,
codersdk.FeatureTemplateAutostopRequirement: 1,
codersdk.FeatureAdvancedTemplateScheduling: 1,
},
},
})
Expand Down Expand Up @@ -164,9 +162,8 @@ func TestUserQuietHours(t *testing.T) {
},
LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureAdvancedTemplateScheduling: 1,
// Not entitled.
// codersdk.FeatureTemplateAutostopRequirement: 1,
// codersdk.FeatureAdvancedTemplateScheduling: 1,
},
},
})
Expand Down
6 changes: 3 additions & 3 deletions site/src/components/Badges/Badges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ export const DeprecatedBadge: FC = () => {
css={[
styles.badge,
{
border: `1px solid ${colors.red[600]}`,
backgroundColor: colors.red[950],
color: colors.red[50],
border: `1px solid ${colors.orange[600]}`,
backgroundColor: colors.orange[950],
color: colors.orange[50],
},
]}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,29 +422,35 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
>
<Stack direction="column">
<Stack direction="row" alignItems="center">
<Checkbox
id="use_max_ttl"
size="small"
disabled={isSubmitting || !allowAdvancedScheduling}
onChange={handleToggleUseMaxTTL}
name="use_max_ttl"
checked={form.values.use_max_ttl}
<FormControlLabel
control={
<Checkbox
id="use_max_ttl"
size="small"
disabled={isSubmitting || !allowAdvancedScheduling}
onChange={handleToggleUseMaxTTL}
name="use_max_ttl"
checked={form.values.use_max_ttl}
/>
}
label={
<Stack spacing={0.5}>
<strong>
Use a max lifetime instead of a required autostop schedule.
</strong>
<span
css={{
fontSize: 12,
color: theme.palette.text.secondary,
}}
>
Use a maximum lifetime for workspaces created from this
template instead of an autostop requirement as configured
above.
</span>
</Stack>
}
/>
<Stack spacing={0.5}>
<strong>
Use a max lifetime instead of a required autostop schedule.
</strong>
<span
css={{
fontSize: 12,
color: theme.palette.text.secondary,
}}
>
Use a maximum lifetime for workspaces created from this
template instead of an autostop requirement as configured
above.
</span>
</Stack>
</Stack>

<TextField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ const fillAndSubmitForm = async ({
}

if (max_ttl_ms) {
const useMaxTtlCheckbox = screen.getByRole("checkbox", {
name: /Use a max lifetime/i,
});
const maxTtlField = await screen.findByLabelText("Max lifetime (hours)");

await user.click(useMaxTtlCheckbox);
await user.clear(maxTtlField);
await user.type(maxTtlField, max_ttl_ms.toString());
}
Expand Down