-
Notifications
You must be signed in to change notification settings - Fork 874
feat: reinitialize agents when a prebuilt workspace is claimed #17475
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
c09c9b9
476fe71
8c8bca6
7ce4eea
52ac64e
362db7c
dcc7379
ff66b3f
efff5d9
cebd5db
2679138
9feebef
b117b5c
a22b414
9bbd2c7
5804201
7e8dcee
725f97b
a9b1567
21ee970
e54d7e7
2799858
1d93003
763fc12
0f879c7
61784c9
604eb27
bf4d2cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -692,10 +692,6 @@ func createWorkspace( | |
if len(agents) > 1 { | ||
return xerrors.Errorf("multiple agents are not yet supported in prebuilt workspaces") | ||
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. It feels wrong to error here. While we don't support multiple agents, we shouldn't fail the call to Can you please add a test for this scenario to validate this behaviour? We could hard-fail this, though, on the template import side when an admin tries to use prebuilds with multiple agents (in a follow-up PR). |
||
} | ||
// agentTokensByAgentID = make(map[uuid.UUID]string, len(agents)) | ||
// for _, agent := range agents { | ||
// agentTokensByAgentID[agent.ID] = agent.AuthToken.String() | ||
// } | ||
} | ||
|
||
// We have to refetch the workspace for the joined in fields. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -694,7 +694,7 @@ const ( | |
ReinitializeReasonPrebuildClaimed ReinitializationReason = "prebuild_claimed" | ||
) | ||
|
||
type ReinitializationResponse struct { | ||
type ReinitializationEvent struct { | ||
Message string `json:"message"` | ||
Reason ReinitializationReason `json:"reason"` | ||
} | ||
|
@@ -707,7 +707,7 @@ func PrebuildClaimedChannel(id uuid.UUID) string { | |
// - ping: ignored, keepalive | ||
// - prebuild claimed: a prebuilt workspace is claimed, so the agent must reinitialize. | ||
// NOTE: the caller is responsible for closing the events chan. | ||
func (c *Client) WaitForReinit(ctx context.Context, events chan<- ReinitializationResponse) error { | ||
func (c *Client) WaitForReinit(ctx context.Context, events chan<- ReinitializationEvent) error { | ||
// TODO: allow configuring httpclient | ||
c.SDK.HTTPClient.Timeout = time.Hour * 24 | ||
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. Does this essentially place an upper limit of 24 hours on the maximum lifetime of a prebuild? 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. This is being worked on currently; disregard for the moment. 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. Why is a 24 hour timeout desirable? A prebuilt workspace could remain up without a reinit for much longer than this, no? Also, this is a quiet side effect to the client: leaving it in a different state than it started in. |
||
|
||
|
@@ -737,19 +737,19 @@ func (c *Client) WaitForReinit(ctx context.Context, events chan<- Reinitializati | |
if sse.Type != codersdk.ServerSentEventTypeData { | ||
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. Ignoring Ping seems OK, but probably shouldn't ignore errors. |
||
continue | ||
} | ||
var reinitResp ReinitializationResponse | ||
var reinitEvent ReinitializationEvent | ||
b, ok := sse.Data.([]byte) | ||
if !ok { | ||
return xerrors.Errorf("expected data as []byte, got %T", sse.Data) | ||
} | ||
err = json.Unmarshal(b, &reinitResp) | ||
err = json.Unmarshal(b, &reinitEvent) | ||
if err != nil { | ||
return xerrors.Errorf("unmarshal reinit response: %w", err) | ||
} | ||
select { | ||
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. At this point you've got the event; no reason to check the context for cancelation again, just return it. |
||
case <-ctx.Done(): | ||
return ctx.Err() | ||
case events <- reinitResp: | ||
case events <- reinitEvent: | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion, nonblocking: rename to
WaitForAgentFn
for clarity