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

Skip to content

feat: mark prebuilds as such and set their preset ids #16965

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 9 commits into from
Apr 14, 2025
Merged

feat: mark prebuilds as such and set their preset ids #16965

merged 9 commits into from
Apr 14, 2025

Conversation

SasSwart
Copy link
Contributor

@SasSwart SasSwart commented Mar 17, 2025

This pull request closes coder/internal#513

@SasSwart SasSwart changed the title mark prebuilds as such and set their preset ids feat: mark prebuilds as such and set their preset ids Mar 17, 2025
@SasSwart SasSwart requested review from dannykopping and removed request for dannykopping March 17, 2025 11:58
@SasSwart SasSwart requested a review from johnstcn April 1, 2025 11:55
@SasSwart SasSwart marked this pull request as ready for review April 1, 2025 11:56
@SasSwart SasSwart requested a review from mtojek April 1, 2025 11:56
Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments, mainly related to naming convention.

build, err := client.CreateWorkspaceBuild(ctx, workspace.ID, codersdk.CreateWorkspaceBuildRequest{
TemplateVersionID: version.ID,
Transition: codersdk.WorkspaceTransitionStart,
TemplateVersionPresetID: presets[0].ID,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is ID here, UUID? Should we rely on a value that is human readable instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ID is randomly generated by the database.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say, I'm a template admin and want to modify the template with presets. I'm pushing a new template revision, it gets a new template version name and new template version ID. Does it happen the same for template version presets? will they get new IDs on every template version push, or will IDs be reused?

BTW we can move this to slack to keep things rolling.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it happen the same for template version presets?

Yes it does.
Presets are associated to a template version, so a new template version will create new preset entries.

build, err := client.CreateWorkspaceBuild(ctx, workspace.ID, codersdk.CreateWorkspaceBuildRequest{
TemplateVersionID: version.ID,
Transition: codersdk.WorkspaceTransitionStart,
TemplateVersionPresetID: presets[0].ID,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say, I'm a template admin and want to modify the template with presets. I'm pushing a new template revision, it gets a new template version name and new template version ID. Does it happen the same for template version presets? will they get new IDs on every template version push, or will IDs be reused?

BTW we can move this to slack to keep things rolling.

Base automatically changed from prebuilds-db to main April 3, 2025 08:58
@SasSwart SasSwart requested a review from dannykopping April 10, 2025 07:53
Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM, a few minor suggestions & nits
Thanks!

build, err := client.CreateWorkspaceBuild(ctx, workspace.ID, codersdk.CreateWorkspaceBuildRequest{
TemplateVersionID: version.ID,
Transition: codersdk.WorkspaceTransitionStart,
TemplateVersionPresetID: presets[0].ID,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it happen the same for template version presets?

Yes it does.
Presets are associated to a template version, so a new template version will create new preset entries.

Type: &proto.Response_Plan{
Plan: &proto.PlanComplete{
Presets: []*proto.Preset{{
Name: "test",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wary of creating such minimal definitions here and in coderd/workspacebuilds_test.go (i.e. ones that do not have other fields like params); this does not reflect a legitimate use of presets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presets are allowed to have 0 parameters. This is to enable prebuilds on templates in which provisioning times are not contingent on parameters having certain values, which is a legitimate use case.

We're also not asserting anything that depends on these parameters in any way. I can add some, but I'm not sure what specifically to add that you find find beneficial? Should I just contrive a few parameters for good measure?


presets, err := client.TemplateVersionPresets(ctx, version.ID)
require.NoError(t, err)
require.Equal(t, 1, len(presets))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're only ever testing a single preset, and I think there's some risk associated with that. Can you expand this, or add another test which uses multiple presets please?

@@ -107,6 +107,8 @@ type CreateWorkspaceBuildRequest struct {

// Log level changes the default logging verbosity of a provider ("info" if empty).
LogLevel ProvisionerLogLevel `json:"log_level,omitempty" validate:"omitempty,oneof=debug"`
// TemplateVersionPresetID is the ID of the template version preset to use for the build.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this comment is a bit redundant.

Suggested change
// TemplateVersionPresetID is the ID of the template version preset to use for the build.
// TemplateVersionPresetID is the ID of the selected preset, if available.

Comment on lines +273 to +276
if metadata.GetIsPrebuild() {
env = append(env, provider.IsPrebuildEnvironmentVariable()+"=true")
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, I'm thinking maybe we should always include the env for the absence of doubt:

Suggested change
if metadata.GetIsPrebuild() {
env = append(env, provider.IsPrebuildEnvironmentVariable()+"=true")
}
env = append(env, fmt.Sprintf("%s=%v", provider.IsPrebuildEnvironmentVariable(), metadata.GetIsPrebuild()))

@SasSwart SasSwart merged commit a986059 into main Apr 14, 2025
39 checks passed
@SasSwart SasSwart deleted the 16930 branch April 14, 2025 13:34
@github-actions github-actions bot locked and limited conversation to collaborators Apr 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provisioning New Prebuild Workspaces
3 participants