Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1372bf8

Browse files
authored
chore: revert "chore: remove workspace_actions experiment (#10030)" (#10363)
1 parent 57c9d88 commit 1372bf8

20 files changed

+124
-36
lines changed

cli/templatecreate.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
5050
isTemplateSchedulingOptionsSet := failureTTL != 0 || inactivityTTL != 0 || maxTTL != 0
5151

5252
if isTemplateSchedulingOptionsSet || requireActiveVersion {
53+
if failureTTL != 0 || inactivityTTL != 0 {
54+
// This call can be removed when workspace_actions is no longer experimental
55+
experiments, exErr := client.Experiments(inv.Context())
56+
if exErr != nil {
57+
return xerrors.Errorf("get experiments: %w", exErr)
58+
}
59+
60+
if !experiments.Enabled(codersdk.ExperimentWorkspaceActions) {
61+
return xerrors.Errorf("--failure-ttl and --inactivity-ttl are experimental features. Use the workspace_actions CODER_EXPERIMENTS flag to set these configuration values.")
62+
}
63+
}
64+
5365
entitlements, err := client.Entitlements(inv.Context())
5466
if cerr, ok := codersdk.AsError(err); ok && cerr.StatusCode() == http.StatusNotFound {
5567
return xerrors.Errorf("your deployment appears to be an AGPL deployment, so you cannot set enterprise-only flags")
@@ -59,7 +71,7 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
5971

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

cli/templateedit.go

+12
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
4343
),
4444
Short: "Edit the metadata of a template by name.",
4545
Handler: func(inv *clibase.Invocation) error {
46+
// This clause can be removed when workspace_actions is no longer experimental
47+
if failureTTL != 0 || inactivityTTL != 0 {
48+
experiments, exErr := client.Experiments(inv.Context())
49+
if exErr != nil {
50+
return xerrors.Errorf("get experiments: %w", exErr)
51+
}
52+
53+
if !experiments.Enabled(codersdk.ExperimentWorkspaceActions) {
54+
return xerrors.Errorf("--failure-ttl and --inactivity-ttl are experimental features. Use the workspace_actions CODER_EXPERIMENTS flag to set these configuration values.")
55+
}
56+
}
57+
4658
unsetAutostopRequirementDaysOfWeek := len(autostopRequirementDaysOfWeek) == 1 && autostopRequirementDaysOfWeek[0] == "none"
4759
requiresScheduling := (len(autostopRequirementDaysOfWeek) > 0 && !unsetAutostopRequirementDaysOfWeek) ||
4860
autostopRequirementWeeks > 0 ||

coderd/apidoc/docs.go

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

coderd/apidoc/swagger.json

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

codersdk/deployment.go

+3
Original file line numberDiff line numberDiff line change
@@ -1973,6 +1973,9 @@ const (
19731973
// feature is not yet complete in functionality.
19741974
ExperimentMoons Experiment = "moons"
19751975

1976+
// https://github.com/coder/coder/milestone/19
1977+
ExperimentWorkspaceActions Experiment = "workspace_actions"
1978+
19761979
// ExperimentTailnetPGCoordinator enables the PGCoord in favor of the pubsub-
19771980
// only Coordinator
19781981
ExperimentTailnetPGCoordinator Experiment = "tailnet_pg_coordinator"

docs/api/schemas.md

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

site/src/api/typesGenerated.ts

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

site/src/components/Dashboard/DashboardProvider.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,13 @@ export const useDashboard = (): DashboardProviderValue => {
112112

113113
return context;
114114
};
115+
116+
export const useIsWorkspaceActionsEnabled = (): boolean => {
117+
const { entitlements, experiments } = useDashboard();
118+
const allowAdvancedScheduling =
119+
entitlements.features["advanced_template_scheduling"].enabled;
120+
// This check can be removed when https://github.com/coder/coder/milestone/19
121+
// is merged up
122+
const allowWorkspaceActions = experiments.includes("workspace_actions");
123+
return allowWorkspaceActions && allowAdvancedScheduling;
124+
};

site/src/components/WorkspaceDeletion/DormantDeletionStat.tsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,20 @@ interface DormantDeletionStatProps {
1414
export const DormantDeletionStat: FC<DormantDeletionStatProps> = ({
1515
workspace,
1616
}) => {
17-
const { entitlements } = useDashboard();
17+
const { entitlements, experiments } = useDashboard();
1818
const allowAdvancedScheduling =
1919
entitlements.features["advanced_template_scheduling"].enabled;
20+
// This check can be removed when https://github.com/coder/coder/milestone/19
21+
// is merged up
22+
const allowWorkspaceActions = experiments.includes("workspace_actions");
2023

21-
if (!displayDormantDeletion(workspace, allowAdvancedScheduling)) {
24+
if (
25+
!displayDormantDeletion(
26+
workspace,
27+
allowAdvancedScheduling,
28+
allowWorkspaceActions,
29+
)
30+
) {
2231
return null;
2332
}
2433

site/src/components/WorkspaceDeletion/DormantDeletionText.tsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,20 @@ export const DormantDeletionText = ({
99
}: {
1010
workspace: Workspace;
1111
}): JSX.Element | null => {
12-
const { entitlements } = useDashboard();
12+
const { entitlements, experiments } = useDashboard();
1313
const allowAdvancedScheduling =
1414
entitlements.features["advanced_template_scheduling"].enabled;
15+
// This check can be removed when https://github.com/coder/coder/milestone/19
16+
// is merged up
17+
const allowWorkspaceActions = experiments.includes("workspace_actions");
1518

16-
if (!displayDormantDeletion(workspace, allowAdvancedScheduling)) {
19+
if (
20+
!displayDormantDeletion(
21+
workspace,
22+
allowAdvancedScheduling,
23+
allowWorkspaceActions,
24+
)
25+
) {
1726
return null;
1827
}
1928
return <StyledSpan role="status">Impending deletion</StyledSpan>;

site/src/components/WorkspaceDeletion/DormantWorkspaceBanner.tsx

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Workspace } from "api/typesGenerated";
2-
import { useDashboard } from "components/Dashboard/DashboardProvider";
2+
import { useIsWorkspaceActionsEnabled } from "components/Dashboard/DashboardProvider";
33
import { Alert } from "components/Alert/Alert";
44
import { formatDistanceToNow } from "date-fns";
55
import Link from "@mui/material/Link";
@@ -21,9 +21,7 @@ export const DormantWorkspaceBanner = ({
2121
shouldRedisplayBanner: boolean;
2222
count?: Count;
2323
}): JSX.Element | null => {
24-
const { entitlements } = useDashboard();
25-
const schedulingEnabled =
26-
entitlements.features["advanced_template_scheduling"].enabled;
24+
const experimentEnabled = useIsWorkspaceActionsEnabled();
2725

2826
if (!workspaces) {
2927
return null;
@@ -39,7 +37,7 @@ export const DormantWorkspaceBanner = ({
3937

4038
if (
4139
// Only show this if the experiment is included.
42-
!schedulingEnabled ||
40+
!experimentEnabled ||
4341
!hasDormantWorkspaces ||
4442
// Banners should be redisplayed after dismissal when additional workspaces are newly scheduled for deletion
4543
!shouldRedisplayBanner

site/src/components/WorkspaceDeletion/utils.test.ts

+22-8
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,53 @@ import { displayDormantDeletion } from "./utils";
44

55
describe("displayDormantDeletion", () => {
66
const today = new Date();
7-
it.each<[string, boolean, boolean]>([
7+
it.each<[string, boolean, boolean, boolean]>([
88
[
99
new Date(new Date().setDate(today.getDate() + 15)).toISOString(),
1010
true,
11+
true,
1112
false,
1213
], // today + 15 days out
1314
[
1415
new Date(new Date().setDate(today.getDate() + 14)).toISOString(),
1516
true,
1617
true,
18+
true,
1719
], // today + 14
1820
[
1921
new Date(new Date().setDate(today.getDate() + 13)).toISOString(),
2022
true,
2123
true,
24+
true,
2225
], // today + 13
2326
[
2427
new Date(new Date().setDate(today.getDate() + 1)).toISOString(),
2528
true,
2629
true,
30+
true,
2731
], // today + 1
28-
[new Date().toISOString(), true, true], // today + 0
29-
[new Date().toISOString(), false, false], // Advanced Scheduling off
32+
[new Date().toISOString(), true, true, true], // today + 0
33+
[new Date().toISOString(), false, true, false], // Advanced Scheduling off
34+
[new Date().toISOString(), true, false, false], // Workspace Actions off
3035
])(
31-
`deleting_at=%p, allowAdvancedScheduling=%p, shouldDisplay=%p`,
32-
(deleting_at, allowAdvancedScheduling, shouldDisplay) => {
36+
`deleting_at=%p, allowAdvancedScheduling=%p, AllowWorkspaceActions=%p, shouldDisplay=%p`,
37+
(
38+
deleting_at,
39+
allowAdvancedScheduling,
40+
allowWorkspaceActions,
41+
shouldDisplay,
42+
) => {
3343
const workspace: TypesGen.Workspace = {
3444
...Mocks.MockWorkspace,
3545
deleting_at,
3646
};
37-
expect(displayDormantDeletion(workspace, allowAdvancedScheduling)).toBe(
38-
shouldDisplay,
39-
);
47+
expect(
48+
displayDormantDeletion(
49+
workspace,
50+
allowAdvancedScheduling,
51+
allowWorkspaceActions,
52+
),
53+
).toBe(shouldDisplay);
4054
},
4155
);
4256
});

site/src/components/WorkspaceDeletion/utils.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ const IMPENDING_DELETION_DISPLAY_THRESHOLD = 14; // 14 days
1414
export const displayDormantDeletion = (
1515
workspace: Workspace,
1616
allowAdvancedScheduling: boolean,
17+
allowWorkspaceActions: boolean,
1718
) => {
1819
const today = new Date();
19-
if (!workspace.deleting_at || !allowAdvancedScheduling) {
20+
if (
21+
!workspace.deleting_at ||
22+
!allowAdvancedScheduling ||
23+
!allowWorkspaceActions
24+
) {
2025
return false;
2126
}
2227
return (

site/src/pages/TemplateSettingsPage/TemplateSchedulePage/TemplateScheduleForm.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface TemplateScheduleForm {
5454
isSubmitting: boolean;
5555
error?: unknown;
5656
allowAdvancedScheduling: boolean;
57+
allowWorkspaceActions: boolean;
5758
allowAutostopRequirement: boolean;
5859
// Helpful to show field errors on Storybook
5960
initialTouched?: FormikTouched<UpdateTemplateMeta>;
@@ -65,6 +66,7 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
6566
onCancel,
6667
error,
6768
allowAdvancedScheduling,
69+
allowWorkspaceActions,
6870
allowAutostopRequirement,
6971
isSubmitting,
7072
initialTouched,
@@ -491,7 +493,7 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
491493
</Stack>
492494
</Stack>
493495
</FormSection>
494-
{allowAdvancedScheduling && (
496+
{allowAdvancedScheduling && allowWorkspaceActions && (
495497
<>
496498
<FormSection
497499
title="Failure Cleanup"

site/src/pages/TemplateSettingsPage/TemplateSchedulePage/TemplateSchedulePage.test.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ describe("TemplateSchedulePage", () => {
133133
jest
134134
.spyOn(API, "getEntitlements")
135135
.mockResolvedValue(MockEntitlementsWithScheduling);
136+
137+
// remove when https://github.com/coder/coder/milestone/19 is completed.
138+
jest.spyOn(API, "getExperiments").mockResolvedValue(["workspace_actions"]);
136139
});
137140

138141
it("Calls the API when user fills in and submits a form", async () => {

site/src/pages/TemplateSettingsPage/TemplateSchedulePage/TemplateSchedulePage.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ const TemplateSchedulePage: FC = () => {
1818
const queryClient = useQueryClient();
1919
const orgId = useOrganizationId();
2020
const { template } = useTemplateSettings();
21-
const { entitlements } = useDashboard();
21+
const { entitlements, experiments } = useDashboard();
2222
const allowAdvancedScheduling =
2323
entitlements.features["advanced_template_scheduling"].enabled;
2424
// This check can be removed when https://github.com/coder/coder/milestone/19
2525
// is merged up
26+
const allowWorkspaceActions = experiments.includes("workspace_actions");
2627
const allowAutostopRequirement =
2728
entitlements.features["template_autostop_requirement"].enabled;
2829
const { clearLocal } = useLocalStorage();
@@ -53,6 +54,7 @@ const TemplateSchedulePage: FC = () => {
5354
</Helmet>
5455
<TemplateSchedulePageView
5556
allowAdvancedScheduling={allowAdvancedScheduling}
57+
allowWorkspaceActions={allowWorkspaceActions}
5658
allowAutostopRequirement={allowAutostopRequirement}
5759
isSubmitting={isSubmitting}
5860
template={template}

site/src/pages/TemplateSettingsPage/TemplateSchedulePage/TemplateSchedulePageView.stories.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type Story = StoryObj<typeof TemplateSchedulePageView>;
3131

3232
const defaultArgs = {
3333
allowAdvancedScheduling: true,
34+
allowWorkspaceActions: true,
3435
template: MockTemplate,
3536
onSubmit: action("onSubmit"),
3637
onCancel: action("cancel"),

site/src/pages/TemplateSettingsPage/TemplateSchedulePage/TemplateSchedulePageView.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface TemplateSchedulePageViewProps {
1313
typeof TemplateScheduleForm
1414
>["initialTouched"];
1515
allowAdvancedScheduling: boolean;
16+
allowWorkspaceActions: boolean;
1617
allowAutostopRequirement: boolean;
1718
}
1819

@@ -22,6 +23,7 @@ export const TemplateSchedulePageView: FC<TemplateSchedulePageViewProps> = ({
2223
onSubmit,
2324
isSubmitting,
2425
allowAdvancedScheduling,
26+
allowWorkspaceActions,
2527
allowAutostopRequirement,
2628
submitError,
2729
initialTouched,
@@ -34,6 +36,7 @@ export const TemplateSchedulePageView: FC<TemplateSchedulePageViewProps> = ({
3436

3537
<TemplateScheduleForm
3638
allowAdvancedScheduling={allowAdvancedScheduling}
39+
allowWorkspaceActions={allowWorkspaceActions}
3740
allowAutostopRequirement={allowAutostopRequirement}
3841
initialTouched={initialTouched}
3942
isSubmitting={isSubmitting}

0 commit comments

Comments
 (0)