- Notifications
You must be signed in to change notification settings - Fork920
fix(agent/agentcontainers): ensure agent name env var is correct#18457
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
222e227
fix(agent/agentcontainers): ensure agent name env var is correct
DanielleMaywoode29d0d0
fix: skip test on windows
DanielleMaywood94865d1
chore: feedback on log
DanielleMaywoodb1b3fd4
chore: only read config twice if agent name is changed
DanielleMaywoodbe4a45b
chore: add regex to log
DanielleMaywoodfa55d0c
chore: channel size 2 -> 1
DanielleMaywoodFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
74 changes: 46 additions & 28 deletionsagent/agentcontainers/api.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1147,18 +1147,49 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c | ||
} | ||
var appsWithPossibleDuplicates []SubAgentApp | ||
if err := func() error { | ||
var ( | ||
config DevcontainerConfig | ||
configOutdated bool | ||
) | ||
readConfig := func() (DevcontainerConfig, error) { | ||
return api.dccli.ReadConfig(ctx, dc.WorkspaceFolder, dc.ConfigPath, []string{ | ||
fmt.Sprintf("CODER_WORKSPACE_AGENT_NAME=%s", subAgentConfig.Name), | ||
fmt.Sprintf("CODER_WORKSPACE_OWNER_NAME=%s", api.ownerName), | ||
fmt.Sprintf("CODER_WORKSPACE_NAME=%s", api.workspaceName), | ||
fmt.Sprintf("CODER_URL=%s", api.subAgentURL), | ||
}) | ||
} | ||
if config, err = readConfig(); err != nil { | ||
return err | ||
} | ||
// NOTE(DanielleMaywood): | ||
// We only want to take an agent name specified in the root customization layer. | ||
// This restricts the ability for a feature to specify the agent name. We may revisit | ||
// this in the future, but for now we want to restrict this behavior. | ||
if name := config.Configuration.Customizations.Coder.Name; name != "" { | ||
DanielleMaywood marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
// We only want to pick this name if it is a valid name. | ||
if provisioner.AgentNameRegex.Match([]byte(name)) { | ||
subAgentConfig.Name = name | ||
configOutdated = true | ||
} else { | ||
logger.Warn(ctx, "invalid name in devcontainer customization, ignoring", | ||
slog.F("name", name), | ||
slog.F("regex", provisioner.AgentNameRegex.String()), | ||
) | ||
} | ||
} | ||
if configOutdated { | ||
if config, err = readConfig(); err != nil { | ||
return err | ||
} | ||
} | ||
coderCustomization := config.MergedConfiguration.Customizations.Coder | ||
for _, customization := range coderCustomization { | ||
@@ -1176,18 +1207,9 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c | ||
appsWithPossibleDuplicates = append(appsWithPossibleDuplicates, customization.Apps...) | ||
} | ||
return nil | ||
}(); err != nil { | ||
api.logger.Error(ctx, "unable to read devcontainer config", slog.Error(err)) | ||
} | ||
displayApps := make([]codersdk.DisplayApp, 0, len(displayAppsMap)) | ||
@@ -1219,10 +1241,6 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c | ||
subAgentConfig.DisplayApps = displayApps | ||
subAgentConfig.Apps = apps | ||
} | ||
deleteSubAgent := proc.agent.ID != uuid.Nil && maybeRecreateSubAgent && !proc.agent.EqualConfig(subAgentConfig) | ||
105 changes: 105 additions & 0 deletionsagent/agentcontainers/api_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.