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
more removal of max_ttl
  • Loading branch information
Emyrk committed Mar 19, 2024
commit e6754957292fab23760165571248734ebd522cfd
2 changes: 1 addition & 1 deletion cli/templatecreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (r *RootCmd) templateCreate() *serpent.Command {

if isTemplateSchedulingOptionsSet {
if !entitlements.Features[codersdk.FeatureAdvancedTemplateScheduling].Enabled {
return xerrors.Errorf("your license is not entitled to use advanced template scheduling, so you cannot set --failure-ttl, --inactivity-ttl, or --max-ttl")
return xerrors.Errorf("your license is not entitled to use advanced template scheduling, so you cannot set --failure-ttl, or --inactivity-ttl")
}
}

Expand Down
10 changes: 0 additions & 10 deletions site/src/pages/CreateTemplatePage/CreateTemplateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ export interface CreateTemplateData {
description: string;
icon: string;
default_ttl_hours: number;
use_max_ttl: boolean;
max_ttl_hours: number;
autostart_requirement_days_of_week: TemplateAutostartRequirementDaysValue[];
autostop_requirement_days_of_week: TemplateAutostopRequirementDaysValue;
autostop_requirement_weeks: number;
Expand Down Expand Up @@ -70,13 +68,6 @@ const defaultInitialValues: CreateTemplateData = {
description: "",
icon: "",
default_ttl_hours: 24,
// max_ttl is an enterprise-only feature, and the server ignores the value if
// you are not licensed. We hide the form value based on entitlements.
//
// The maximum value is 30 days but we default to 7 days as it's a much more
// sensible value for most teams.
use_max_ttl: false, // autostop_requirement is default
max_ttl_hours: 24 * 7,
// autostop_requirement is an enterprise-only feature, and the server ignores
// the value if you are not licensed. We hide the form value based on
// entitlements.
Expand Down Expand Up @@ -110,7 +101,6 @@ const getInitialValues = ({
if (!allowAdvancedScheduling) {
initialValues = {
...initialValues,
max_ttl_hours: 0,
autostop_requirement_days_of_week: "off",
autostop_requirement_weeks: 1,
};
Expand Down
16 changes: 2 additions & 14 deletions site/src/pages/CreateTemplatePage/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,25 @@ const provisioner: ProvisionerType =
typeof (window as any).playwright !== "undefined" ? "echo" : "terraform";

export const newTemplate = (formData: CreateTemplateData) => {
let {
max_ttl_hours,
autostop_requirement_days_of_week,
autostop_requirement_weeks,
} = formData;
const { autostop_requirement_days_of_week, autostop_requirement_weeks } =
formData;

const safeTemplateData = {
name: formData.name,
display_name: formData.display_name,
description: formData.description,
icon: formData.icon,
use_max_ttl: formData.use_max_ttl,
allow_user_autostart: formData.allow_user_autostart,
allow_user_autostop: formData.allow_user_autostop,
allow_user_cancel_workspace_jobs: formData.allow_user_cancel_workspace_jobs,
user_variable_values: formData.user_variable_values,
allow_everyone_group_access: formData.allow_everyone_group_access,
};

if (formData.use_max_ttl) {
autostop_requirement_days_of_week = "off";
autostop_requirement_weeks = 1;
} else {
max_ttl_hours = 0;
}

return {
...safeTemplateData,
disable_everyone_group_access: !formData.allow_everyone_group_access,
default_ttl_ms: formData.default_ttl_hours * 60 * 60 * 1000, // Convert hours to ms
max_ttl_ms: max_ttl_hours * 60 * 60 * 1000, // Convert hours to ms
autostop_requirement: {
days_of_week: calculateAutostopRequirementDaysValue(
autostop_requirement_days_of_week,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { TemplateSettingsPage } from "./TemplateSettingsPage";
type FormValues = Required<
Omit<
UpdateTemplateMeta,
"default_ttl_ms" | "activity_bump_ms" | "max_ttl_ms" | "deprecation_message"
"default_ttl_ms" | "activity_bump_ms" | "deprecation_message"
>
>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import TemplateSchedulePage from "./TemplateSchedulePage";
const validFormValues: TemplateScheduleFormValues = {
default_ttl_ms: 1,
activity_bump_ms: 1,
use_max_ttl: true,
max_ttl_ms: 2,
failure_ttl_ms: 7,
time_til_dormant_ms: 180,
time_til_dormant_autodelete_ms: 30,
Expand Down Expand Up @@ -146,7 +144,7 @@ describe("TemplateSchedulePage", () => {
);
});

test("default and max ttl is converted to and from hours", async () => {
test("default is converted to and from hours", async () => {
await renderTemplateSchedulePage();

jest.spyOn(API, "updateTemplateMeta").mockResolvedValueOnce({
Expand All @@ -164,7 +162,6 @@ describe("TemplateSchedulePage", () => {
"test-template",
expect.objectContaining({
default_ttl_ms: (validFormValues.default_ttl_ms || 0) * 3600000,
max_ttl_ms: (validFormValues.max_ttl_ms || 0) * 3600000,
}),
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ export const getValidationSchema = (): Yup.AnyObjectSchema =>
24 * MAX_TTL_DAYS /* 30 days in hours */,
"Please enter an activity bump duration that is less than or equal to 720 hours (30 days).",
),
max_ttl_ms: Yup.number()
.integer()
.required()
.min(0, "Maximum time until autostop must not be less than 0.")
.max(
24 * MAX_TTL_DAYS /* 30 days in hours */,
"Please enter a limit that is less than or equal to 720 hours (30 days).",
),
failure_ttl_ms: Yup.number()
.integer()
.required()
Expand Down
2 changes: 0 additions & 2 deletions site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,6 @@ export const MockTemplate: TypesGen.Template = {
description: "This is a test description.",
default_ttl_ms: 24 * 60 * 60 * 1000,
activity_bump_ms: 1 * 60 * 60 * 1000,
use_max_ttl: false,
max_ttl_ms: 0,
autostop_requirement: {
days_of_week: ["sunday"],
weeks: 1,
Expand Down
0