8000 chore!: remove max_ttl from templates by Emyrk · Pull Request #12644 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

chore!: remove max_ttl from templates #12644

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
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
remove max ttl from ui
  • Loading branch information
Emyrk committed Mar 19, 2024
commit e82c533e2513e5f3bd30f3ddee85e3f0721c21f0
2 changes: 1 addition & 1 deletion coderd/activitybump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,6 @@ func TestWorkspaceActivityBump(t *testing.T) {
require.NoError(t, err)
_ = sshConn.Close()

assertBumped(true) // also asserts max ttl not exceeded
assertBumped(true)
})
}
2 changes: 1 addition & 1 deletion coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion codersdk/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ when required by your organization's security policy.`,
}
deploymentGroupUserQuietHoursSchedule = serpent.Group{
Name: "User Quiet Hours Schedule",
Description: "Allow users to set quiet hours schedules each day for workspaces to avoid workspaces stopping during the day due to template max TTL.",
Description: "Allow users to set quiet hours schedules each day for workspaces to avoid workspaces stopping during the day due to template scheduling.",
YAML: "userQuietHoursSchedule",
}
deploymentGroupDangerous = serpent.Group{
Expand Down
2 changes: 1 addition & 1 deletion codersdk/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ type UpdateUserQuietHoursScheduleRequest struct {
// window is. Schedule must not be empty. For new users, the schedule is set
// to 2am in their browser or computer's timezone. The schedule denotes the
// beginning of a 4 hour window where the workspace is allowed to
// automatically stop or restart due to maintenance or template max TTL.
// automatically stop or restart due to maintenance or template schedule.
//
// The schedule must be daily with a single time, and should have a timezone
// specified via a CRON_TZ prefix (otherwise UTC will be used).
Expand Down
6 changes: 3 additions & 3 deletions docs/api/schemas.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,6 @@ export const ActivityBumpHelperText = (props: { bump?: number }) => {
);
};

export const MaxTTLHelperText = (props: { ttl?: number }) => {
const { ttl = 0 } = props;

// Error will show once field is considered touched
if (ttl < 0) {
return null;
}

if (ttl === 0) {
8000 return <span>Workspaces may run indefinitely.</span>;
}

return (
<span>
Workspaces must stop within {ttl} {hours(ttl)} of starting, regardless of
any active connections.
</span>
);
};

export const FailureTTLHelperText = (props: { ttl?: number }) => {
const { ttl = 0 } = props;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useTheme } from "@emotion/react";
import Checkbox from "@mui/material/Checkbox";
import FormControlLabel from "@mui/material/FormControlLabel";
import Link from "@mui/material/Link";
import MenuItem from "@mui/material/MenuItem";
import Switch from "@mui/material/Switch";
import TextField from "@mui/material/TextField";
Expand All @@ -15,7 +14,6 @@ import {
FormFields,
} from "components/Form/Form";
import { Stack } from "components/Stack/Stack";
import { docs } from "utils/docs";
import { getFormHelpers } from "utils/formUtils";
import {
calculateAutostopRequirementDaysValue,
Expand All @@ -38,7 +36,6 @@ import {
DormancyAutoDeletionTTLHelperText,
DormancyTTLHelperText,
FailureTTLHelperText,
MaxTTLHelperText,
} from "./TTLHelperText";
import {
useWorkspacesToGoDormant,
Expand Down Expand Up @@ -77,15 +74,6 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
// on display, convert from ms => hours
default_ttl_ms: template.default_ttl_ms / MS_HOUR_CONVERSION,
activity_bump_ms: template.activity_bump_ms / MS_HOUR_CONVERSION,
// the API ignores these values, but to avoid tripping up validation set
// it to zero if the user can't set the field.
use_max_ttl:
template.use_max_ttl === undefined
? template.max_ttl_ms > 0
: template.use_max_ttl,
max_ttl_ms: allowAdvancedScheduling
? template.max_ttl_ms / MS_HOUR_CONVERSION
: 0,
failure_ttl_ms: allowAdvancedScheduling
? template.failure_ttl_ms / MS_DAY_CONVERSION
: 0,
Expand Down Expand Up @@ -214,10 +202,6 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
activity_bump_ms: form.values.activity_bump_ms
? form.values.activity_bump_ms * MS_HOUR_CONVERSION
: undefined,
max_ttl_ms:
form.values.max_ttl_ms && form.values.use_max_ttl
? form.values.max_ttl_ms * MS_HOUR_CONVERSION
: undefined,
failure_ttl_ms: form.values.failure_ttl_ms
? form.values.failure_ttl_ms * MS_DAY_CONVERSION
: undefined,
Expand All @@ -228,14 +212,12 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
? form.values.time_til_dormant_autodelete_ms * MS_DAY_CONVERSION
: undefined,

autostop_requirement: form.values.use_max_ttl
? undefined
: {
days_of_week: calculateAutostopRequirementDaysValue(
form.values.autostop_requirement_days_of_week,
),
weeks: autostop_requirement_weeks,
},
autostop_requirement: {
days_of_week: calculateAutostopRequirementDaysValue(
form.values.autostop_requirement_days_of_week,
),
weeks: autostop_requirement_weeks,
},
autostart_requirement: {
days_of_week: form.values.autostart_requirement_days_of_week,
},
Expand Down Expand Up @@ -330,27 +312,6 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
}
};

const handleToggleUseMaxTTL = async () => {
const val = !form.values.use_max_ttl;
if (val) {
// set max_ttl to 1, set autostop_requirement to empty
await form.setValues({
...form.values,
use_max_ttl: val,
max_ttl_ms: 1,
autostop_requirement_days_of_week: "off",
autostop_requirement_weeks: 1,
});
} else {
// set max_ttl to 0
await form.setValues({
...form.values,
use_max_ttl: val,
max_ttl_ms: 0,
});
}
};

return (
<HorizontalForm
onSubmit={form.handleSubmit}
Expand Down Expand Up @@ -402,7 +363,7 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
/>
),
})}
disabled={isSubmitting || form.values.use_max_ttl}
disabled={isSubmitting}
fullWidth
select
value={form.values.autostop_requirement_days_of_week}
Expand Down Expand Up @@ -433,7 +394,6 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
})}
disabled={
isSubmitting ||
form.values.use_max_ttl ||
!["saturday", "sunday"].includes(
form.values.autostop_requirement_days_of_week || "",
)
Expand All @@ -446,68 +406,6 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
</Stack>
</FormSection>

<FormSection
title="Max Lifetime"
description="Define the maximum lifetime for workspaces created from this template."
deprecated
>
<Stack direction="column" spacing={4}>
<Stack direction="row" alignItems="center">
<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>

<TextField
{...getFieldHelpers("max_ttl_ms", {
helperText: allowAdvancedScheduling ? (
<MaxTTLHelperText ttl={form.values.max_ttl_ms} />
) : (
<>
You need an enterprise license to use it{" "}
<Link href={docs("/enterprise")}>Learn more</Link>.
</>
),
})}
disabled={
isSubmitting ||
!form.values.use_max_ttl ||
!allowAdvancedScheduling
}
fullWidth
inputProps={{ min: 0, step: 1 }}
label="Max lifetime (hours)"
type="number"
/>
</Stack>
</FormSection>

<FormSection
title="Allow users scheduling"
description="Allow users to set custom autostart and autostop scheduling options for workspaces created from this template."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ type FillAndSubmitConfig = {

const fillAndSubmitForm = async ({
default_ttl_ms,
max_ttl_ms,
failure_ttl_ms,
time_til_dormant_ms,
time_til_dormant_autodelete_ms,
Expand All @@ -78,17 +77,6 @@ const fillAndSubmitForm = async ({
await user.type(defaultTtlField, default_ttl_ms.toString());
}

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());
}

if (failure_ttl_ms) {
const failureTtlField = screen.getByRole("checkbox", {
name: /Failure Cleanup/i,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export interface TemplateScheduleFormValues
UpdateTemplateMeta,
"autostop_requirement" | "autostart_requirement"
> {
use_max_ttl: boolean;
autostart_requirement_days_of_week: TemplateAutostartRequirementDaysValue[];
autostop_requirement_days_of_week: TemplateAutostopRequirementDaysValue;
autostop_requirement_weeks: number;
Expand Down
0