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

Skip to content

feat: reinitialize agents when a prebuilt workspace is claimed - #17475

Merged
SasSwart merged 49 commits into
mainfrom
jjs/prebuilds-agent-reinit
May 14, 2025
Merged

feat: reinitialize agents when a prebuilt workspace is claimed#17475
SasSwart merged 49 commits into
mainfrom
jjs/prebuilds-agent-reinit

Conversation

@SasSwart

Copy link
Copy Markdown
Contributor

This pull request allows coder workspace agents to be reinitialized when a prebuilt workspace is claimed by a user. This facilitates the transfer of ownership between the anonymous prebuilds system user and the new owner of the workspace.

Only a single agent per prebuilt workspace is supported for now, but plumbing has already been done to facilitate the seamless transition to multi-agent support.

@SasSwart SasSwart changed the title WIP: agent reinitialization feat: reinitialize agents when a prebuilt workspace is claimed Apr 21, 2025
Comment thread agent/metrics.go Outdated
@SasSwart
SasSwart force-pushed the jjs/prebuilds-agent-reinit branch from 35e4bf8 to 18da76e Compare April 23, 2025 13:49
@evgeniy-scherbina
evgeniy-scherbina force-pushed the yevhenii/512-claim-prebuild branch from fe569d4 to fcdbba8 Compare April 23, 2025 15:23
@SasSwart
SasSwart force-pushed the jjs/prebuilds-agent-reinit branch from cc25406 to 26dbc3a Compare April 24, 2025 12:34
Base automatically changed from yevhenii/512-claim-prebuild to main April 24, 2025 13:39
@SasSwart
SasSwart force-pushed the jjs/prebuilds-agent-reinit branch from ec9ed29 to 362db7c Compare April 25, 2025 08:32
Comment thread cli/agent.go Outdated
Comment thread coderd/agentapi/api.go Outdated
Comment thread coderd/agentapi/manifest.go Outdated
Comment thread coderd/coderdtest/coderdtest.go
Comment thread coderd/workspaceagents.go Outdated
Comment thread provisioner/terraform/executor.go
Comment thread provisioner/terraform/executor.go
Comment thread provisioner/terraform/executor.go
Comment thread provisioner/terraform/executor.go Outdated
Comment thread provisioner/terraform/provision.go
Comment thread coderd/provisionerdserver/provisionerdserver.go Outdated
Comment thread coderd/provisionerdserver/provisionerdserver_test.go Outdated
Comment thread coderd/provisionerdserver/provisionerdserver_test.go
Comment thread coderd/provisionerdserver/provisionerdserver_test.go Outdated
Comment thread coderd/provisionerdserver/provisionerdserver_test.go Outdated
Comment thread coderd/provisionerdserver/provisionerdserver_test.go Outdated
Comment thread coderd/prebuilds/claim.go Outdated
Comment thread coderd/prebuilds/claim.go
Comment thread coderd/prebuilds/claim.go Outdated
Comment thread coderd/prebuilds/claim.go Outdated
Comment thread coderd/prebuilds/claim.go Outdated
}

func StreamAgentReinitEvents(ctx context.Context, logger slog.Logger, rw http.ResponseWriter, r *http.Request, reinitEvents <-chan agentsdk.ReinitializationEvent) {
sseSendEvent, sseSenderClosed, err := httpapi.ServerSentEventSender(rw, r)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can fix this later, but I think this might be inappropriate at this layer.
This seems like a detail of the HTTP API, and we aren't testing this directly so I'd argue this code could go back to coderd/workspaceagents.go.

Comment thread coderd/prebuilds/claim_test.go
Comment thread coderd/prebuilds/claim_test.go Outdated
Comment thread coderd/provisionerdserver/provisionerdserver.go Outdated
Comment thread coderd/workspaceagents.go Outdated
Comment thread codersdk/agentsdk/agentsdk.go Outdated

@spikecurtis spikecurtis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The biggest remaining issue is around back compatibility for old versions of the provisionerd server.

Comment thread coderd/prebuilds/claim.go Outdated
Comment thread codersdk/agentsdk/agentsdk.go Outdated
Comment thread coderd/workspaceagents.go
Comment thread coderd/prebuilds/claim_test.go Outdated
Comment thread coderd/prebuilds/claim_test.go
Comment thread enterprise/coderd/workspaceagents_test.go Outdated
Comment thread enterprise/coderd/workspaceagents_test.go Outdated
Comment thread coderd/provisionerdserver/provisionerdserver_test.go Outdated
Comment thread coderd/provisionerdserver/provisionerdserver_test.go Outdated
Comment thread coderd/provisionerdserver/provisionerdserver.go
dannykopping added a commit that referenced this pull request May 12, 2025
…17757)

Used in combination with
coder/terraform-provider-coder#396

This is required by both #17475 and
#17571

Operators may need to conditionalize their templates to perform certain
operations once a prebuilt workspace has been claimed. This value will
**only** be set once a claim takes place and a subsequent `terraform
apply` occurs. Any `terraform apply` runs thereafter will be
indistinguishable from a normal run on a workspace.

---------

Signed-off-by: Danny Kopping <[email protected]>
@SasSwart
SasSwart requested a review from spikecurtis May 13, 2025 08:56
Comment thread codersdk/agentsdk/agentsdk.go
Comment thread coderd/prebuilds/claim_test.go Outdated
Comment thread coderd/workspaceagents_test.go Outdated
Comment thread coderd/provisionerdserver/provisionerdserver.go
Comment thread enterprise/coderd/workspaceagents_test.go Outdated
Comment thread enterprise/coderd/workspaceagents_test.go Outdated
Comment thread enterprise/coderd/workspaceagents_test.go Outdated
Comment thread enterprise/coderd/workspaces_test.go Outdated
@SasSwart
SasSwart requested a review from spikecurtis May 14, 2025 09:03

@mtojek mtojek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's get this merged now, Sas. Based on the discussion we had yesterday, we can work on improvements iteratively 👍

Comment thread coderd/workspaceagents_test.go
Comment thread provisioner/terraform/executor.go
@SasSwart
SasSwart merged commit 425ee6f into main May 14, 2025
@SasSwart
SasSwart deleted the jjs/prebuilds-agent-reinit branch May 14, 2025 12:15
@github-actions github-actions Bot locked and limited conversation to collaborators May 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.

5 participants