Skip to content

refactor(agent/agentssh): move envs to agent and add agentssh config struct #12204

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
Feb 19, 2024

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented Feb 19, 2024

This PR refactors where custom environment variables are set in the workspace and decouples agent specific configs from the agentssh.Server. To reproduce all functionality, agentssh.Config is introduced.

The custom environment variables are now configured in agent/agent.go and the agent retains control of the final state. This will allow for easier extension in the future and keep other modules decoupled.

Related #11131 (follow-up PR).

@mafredri mafredri self-assigned this Feb 19, 2024
@mafredri mafredri requested review from johnstcn and mtojek February 19, 2024 11:14
@@ -278,8 +278,13 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
subsystems = append(subsystems, subsystem)
}

procTicker := time.NewTicker(time.Second)
defer procTicker.Stop()
Copy link
Member Author

Choose a reason for hiding this comment

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

Review: This is unused.

environmentVariables := map[string]string{
"GIT_ASKPASS": executablePath,
}
if v, ok := os.LookupEnv(agent.EnvProcPrioMgmt); ok {
Copy link
Member Author

@mafredri mafredri Feb 19, 2024

Choose a reason for hiding this comment

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

Review: This was dirtying all workspaces with an empty env, even when not set.

"CODER": "true", // From the agent.
"MY_MANIFEST": "true", // From the manifest.
"MY_OVERRIDE": "true", // From the agent environment variables option, overrides manifest.
"MY_SESSION_MANIFEST": "false", // From the manifest, overrides session env.
Copy link
Member Author

Choose a reason for hiding this comment

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

Review: This is not necessarily correct behavior (IMO), but I wanted to stay truthful to the existing implementation.

environmentVariables := map[string]string{
"GIT_ASKPASS": executablePath,
}
if v, ok := os.LookupEnv(agent.EnvProcPrioMgmt); ok {
Copy link
Member

Choose a reason for hiding this comment

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

I see that this os.LookupEnv(agent.EnvProcPrioMgmt) appears a few times. I'm wondering if we should cover it with a dedicated function.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's only really used here, in the other place we check the map passed to the agent which is better for tests, so I don't think this needs any change at the moment.

Copy link
Member

Choose a reason for hiding this comment

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

My only concern is the future when somebody decides to introduce another variable and forgets to correct it in the test. Anyway, let's assume it is sort of nitpick 👍

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.

LGTM once CI is happy!

@mafredri mafredri force-pushed the mafredri/refactor-agentssh-config branch from e151c86 to 112a0d0 Compare February 19, 2024 12:24
@mafredri mafredri force-pushed the mafredri/refactor-agentssh-config branch 2 times, most recently from b9895ac to ffae4ad Compare February 19, 2024 13:45
@mafredri mafredri force-pushed the mafredri/refactor-agentssh-config branch from ffae4ad to dd66b45 Compare February 19, 2024 14:02
@mafredri mafredri merged commit c63f569 into main Feb 19, 2024
@mafredri mafredri deleted the mafredri/refactor-agentssh-config branch February 19, 2024 14:30
@github-actions github-actions bot locked and limited conversation to collaborators Feb 19, 2024
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.

3 participants