Skip to content

feat: reuse agent tokens when a prebuilt agent reinitializes #374

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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

SasSwart
Copy link
Contributor

@SasSwart SasSwart commented Apr 3, 2025

This PR closes #364

Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

I think this is definitely worth an integration test :-)

Base automatically changed from jjs/363 to main April 7, 2025 06:20
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.

I don't think this PR is ready for review yet, is it?

@SasSwart SasSwart marked this pull request as draft April 10, 2025 10:09
"token_provided": existingToken != "",
}
if isPrebuild && existingToken != "" {
// check if a token was already generated for this agent.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: consistency.

Suggested change
// check if a token was already generated for this agent.
// Check if a token was already generated for this agent.

Comment on lines +55 to +57
} else {
tflog.Info(ctx, "using a new agent token", logFields)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's necessary to log this case.

Suggested change
} else {
tflog.Info(ctx, "using a new agent token", logFields)
}
}

Comment on lines +504 to +507
// RunningAgentTokenEnvironmentVariable returns the name of the environment variable
// that contains the token for the running agent. This is used for prebuilds, where
// we want to reuse the same token for the next iteration of a workspace agent before
// and after the workspace was claimed by a user.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment could use some work; I think we should elaborate as to why this is being injected.

// and after the workspace was claimed by a user.
//
// agentID is unused for now, but will be used as soon as we support multiple agents.
func RunningAgentTokenEnvironmentVariable(agentID string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

How will the ID be injected? How will we maintain a persistent identity across terraform apply runs?

@dannykopping dannykopping self-requested a review April 17, 2025 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants