8000 feat: add `is_prebuild_claim` to distinguish post-claim provisioning by dannykopping · Pull Request #17757 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: add is_prebuild_claim to distinguish post-claim provisioning #17757

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 5 commits into from
May 12, 2025
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
Next Next commit
feat: pass flag to terraform provider when prebuilt workspace claimed
Signed-off-by: Danny Kopping <dannykopping@gmail.com>
  • Loading branch information
dannykopping committed May 12, 2025
commit 1e8385d840d3debf4dfebb3542fde05f25982fd7
2 changes: 1 addition & 1 deletion cli/testdata/coder_provisioner_list_--output_json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"last_seen_at": "====[timestamp]=====",
"name": "test",
"version": "v0.0.0-devel",
"api_version": "1.4",
"api_version": "1.5",
"provisioners": [
"echo"
],
Expand Down
11 changes: 6 additions & 5 deletions coderd/provisionerdserver/provisionerdserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ func (s *server) acquireProtoJob(ctx context.Context, job database.ProvisionerJo
WorkspaceOwnerLoginType: string(owner.LoginType),
WorkspaceOwnerRbacRoles: ownerRbacRoles,
IsPrebuild: input.IsPrebuild,
IsPrebuildClaim: input.IsPrebuildClaim,
},
LogLevel: input.LogLevel,
},
Expand Down Expand Up @@ -2471,11 +2472,11 @@ type TemplateVersionImportJob struct {

// WorkspaceProvisionJob is the payload for the "workspace_provision" job type.
type WorkspaceProvisionJob struct {
WorkspaceBuildID uuid.UUID `json:"workspace_build_id"`
DryRun bool `json:"dry_run"`
IsPrebuild bool `json:"is_prebuild,omitempty"`
PrebuildClaimedByUser uuid.UUID `json:"prebuild_claimed_by,omitempty"`
LogLevel string `json:"log_level,omitempty"`
WorkspaceBuildID uuid.UUID `json:"workspace_build_id"`
DryRun bool `json:"dry_run"`
IsPrebuild bool `json:"is_prebuild,omitempty"`
IsPrebuildClaim bool `json:"is_prebuild_claim,omitempty"`
LogLevel string `json:"log_level,omitempty"`
}

// TemplateVersionDryRunJob is the payload for the "template_version_dry_run" job type.
Expand Down
2 changes: 1 addition & 1 deletion coderd/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ func createWorkspace(
builder = builder.TemplateVersionPresetID(req.TemplateVersionPresetID)
}
if claimedWorkspace != nil {
builder = builder.MarkPrebuildClaimedBy(owner.ID)
builder = builder.MarkPrebuildClaim()
}

if req.EnableDynamicParameters && api.Experiments.Enabled(codersdk.ExperimentDynamicParameters) {
Expand Down
17 changes: 9 additions & 8 deletions coderd/wsbuilder/wsbuilder.go
8000
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ type Builder struct {
parameterValues *[]string
templateVersionPresetParameterValues []database.TemplateVersionPresetParameter

prebuild bool
prebuildClaimedBy uuid.UUID
prebuild, prebuildClaim bool

verifyNoLegacyParametersOnce bool
}
Expand Down Expand Up @@ -174,15 +173,17 @@ func (b Builder) RichParameterValues(p []codersdk.WorkspaceBuildParameter) Build
return b
}

// MarkPrebuild indicates that a prebuilt workspace is being built.
func (b Builder) MarkPrebuild() Builder {
// nolint: revive
b.prebuild = true
return b
}

func (b Builder) MarkPrebuildClaimedBy(userID uuid.UUID) Builder {
// MarkPrebuildClaim indicates that a prebuilt workspace is being claimed.
func (b Builder) MarkPrebuildClaim() Builder {
// nolint: revive
b.prebuildClaimedBy = userID
b.prebuildClaim = true
return b
}

Expand Down Expand Up @@ -322,10 +323,10 @@ func (b *Builder) buildTx(authFunc func(action policy.Action, object rbac.Object

workspaceBuildID := uuid.New()
input, err := json.Marshal(provisionerdserver.WorkspaceProvisionJob{
WorkspaceBuildID: workspaceBuildID,
LogLevel: b.logLevel,
IsPrebuild: b.prebuild,
PrebuildClaimedByUser: b.prebuildClaimedBy,
WorkspaceBuildID: workspaceBuildID,
LogLevel: b.logLevel,
IsPrebuild: b.prebuild,
IsPrebuildClaim: b.prebuildClaim,
})
if err != nil {
return nil, nil, nil, BuildError{
Expand Down
3 changes: 3 additions & 0 deletions provisioner/terraform/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ func provisionEnv(
if metadata.GetIsPrebuild() {
env = append(env, provider.IsPrebuildEnvironmentVariable()+"=true")
}
if metadata.GetIsPrebuildClaim() {
env = append(env, provider.IsPrebuildClaimEnvironmentVariable()+"=true")
}

for key, value := range provisionersdk.AgentScriptEnv() {
env = append(env, key+"="+value)
Expand Down
7 changes: 6 additions & 1 deletion provisionerd/proto/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ import "github.com/coder/coder/v2/apiversion"
//
// API v1.4:
// - Add new field named `devcontainers` in the Agent.
//
// API v1.5:
// - Add new field named `is_prebuild_claim` in the Metadata message.
const (
CurrentMajor = 1
CurrentMinor = 4
CurrentMinor = 5
)

// CurrentVersion is the current provisionerd API version.
// Breaking changes to the provisionerd API **MUST** increment
// CurrentMajor above.
// Non-breaking changes to the provisionerd API **MUST** increment
// CurrentMinor above.
var CurrentVersion = apiversion.New(CurrentMajor, CurrentMinor)
355 changes: 183 additions & 172 deletions provisionersdk/proto/provisioner.pb.go

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions provisionersdk/proto/provisioner.proto
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,9 @@ message Metadata {
string workspace_build_id = 17;
string workspace_owner_login_type = 18;
repeated Role workspace_owner_rbac_roles = 19;
bool is_prebuild = 20;
string running_workspace_agent_token = 21;
bool is_prebuild = 20; // Indicates that a prebuilt workspace is being built.
string running_workspace_agent_token = 21; // Preserves the running agent token of a prebuilt workspace so it can reinitialize.
bool is_prebuild_claim = 22; // Indicates that a prebuilt workspace is being claimed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
bool is_prebuild_claim = 22; // Indicates that a prebuilt workspace is being claimed.
bool claims_prebuilt_workspace = 22; // Indicates that a prebuilt workspace is being claimed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right; I probably shouldn't refer to "prebuild" here.
I'll make it is_prebuilt_workspace_claim to be similar in form to is_prebuild, since they're related fields.

CEB2 Copy link
Contributor

Choose a reason for hiding this comment

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

You could make them a single enum...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could work, lemme try it and see how it feels.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@spikecurtis great suggestion, this is more in line with how we do other things like workspace transitions; should've done this from the beginning.

bc9ff3d

}

// Config represents execution configuration shared by all subsequent requests in the Session
Expand Down
7 changes: 7 additions & 0 deletions site/e2e/provisionerGenerated.ts

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

0