- Notifications
You must be signed in to change notification settings - Fork929
feat: enforce template-level constraints for TTL and autostart#2018
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
1713431
f11f942
c5c9a7a
74f4dee
7da27a0
5ad048b
65b980e
aa298a6
a5ec9bf
a6255d6
245795e
709db5b
c4a0927
244e479
60ef479
c9aab8b
f997af2
d7f697b
ebe4c15
08ef2eb
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -6,6 +6,7 @@ import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
"time" | ||
"github.com/stretchr/testify/require" | ||
@@ -158,4 +159,32 @@ func TestAutostart(t *testing.T) { | ||
require.NoError(t, err, "fetch updated workspace") | ||
require.Equal(t, expectedSchedule, *updated.AutostartSchedule, "expected default autostart schedule") | ||
}) | ||
t.Run("BelowTemplateConstraint", func(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Question(gut-check): Should there be a similar case forAboveTemplateConstraint ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I don't see any reason to enforce an upper bound on the interval between successive autostarts. | ||
t.Parallel() | ||
var ( | ||
ctx = context.Background() | ||
client = coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true}) | ||
user = coderdtest.CreateFirstUser(t, client) | ||
version = coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil) | ||
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID) | ||
project = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID, func(ctr *codersdk.CreateTemplateRequest) { | ||
ctr.MinAutostartIntervalMillis = ptr.Ref(time.Hour.Milliseconds()) | ||
}) | ||
workspace = coderdtest.CreateWorkspace(t, client, user.OrganizationID, project.ID) | ||
cmdArgs = []string{"autostart", "enable", workspace.Name, "--minute", "*", "--hour", "*"} | ||
) | ||
cmd, root := clitest.New(t, cmdArgs...) | ||
clitest.SetupConfig(t, client, root) | ||
err := cmd.Execute() | ||
require.NoError(t, err, "unexpected error") | ||
// Ensure nothing happened | ||
updated, err := client.Workspace(ctx, workspace.ID) | ||
require.NoError(t, err, "fetch updated workspace") | ||
require.Equal(t, *workspace.AutostartSchedule, *updated.AutostartSchedule, "expected previous autostart schedule") | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -61,6 +61,15 @@ type CreateTemplateRequest struct { | ||
// templates, but it doesn't make sense for users. | ||
VersionID uuid.UUID `json:"template_version_id" validate:"required"` | ||
ParameterValues []CreateParameterRequest `json:"parameter_values,omitempty"` | ||
// MaxTTLMillis allows optionally specifying the maximum allowable TTL | ||
// for all workspaces created from this template. | ||
MaxTTLMillis *int64 `json:"max_ttl_ms,omitempty"` | ||
// MinAutostartIntervalMillis allows optionally specifying the minimum | ||
// allowable duration between autostarts for all workspaces created from | ||
// this template. | ||
MinAutostartIntervalMillis *int64 `json:"min_autostart_interval_ms,omitempty"` | ||
Comment on lines +65 to +72 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Making these optional in creation; if preferred I can make them mandatory. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Is this so you don't have some autostart config that says start my workspace every minute? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Yup! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Thought: Can we make he zero values useful here? Or can these be set to zero to disable them entirely? If zero doesn't need to disable, we can treat it as not set, avoiding the use of pointers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. FE prefers to consume null instead of zero-values; hence the pointers. | ||
} | ||
// CreateWorkspaceRequest provides options for creating a new workspace. | ||