- Notifications
You must be signed in to change notification settings - Fork920
feat(agent/agentcontainers): support agent name in customization#18451
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
4 commits Select commitHold shift + click to select a range
a5278c9
feat(agent/agentcontainers): support agent name in customization
DanielleMaywooddb59693
chore: add extra test case
DanielleMaywoodd094205
chore: ignore invalid names
DanielleMaywoodb738124
refactor: include configuration and merged configuration
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
19 changes: 19 additions & 0 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 |
---|---|---|
@@ -28,6 +28,7 @@ import ( | ||
"github.com/coder/coder/v2/coderd/httpapi" | ||
"github.com/coder/coder/v2/codersdk" | ||
"github.com/coder/coder/v2/codersdk/agentsdk" | ||
"github.com/coder/coder/v2/provisioner" | ||
DanielleMaywood marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
"github.com/coder/quartz" | ||
) | ||
@@ -1146,6 +1147,7 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c | ||
} | ||
var appsWithPossibleDuplicates []SubAgentApp | ||
var possibleAgentName string | ||
if config, err := api.dccli.ReadConfig(ctx, dc.WorkspaceFolder, dc.ConfigPath, | ||
[]string{ | ||
@@ -1173,6 +1175,19 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c | ||
appsWithPossibleDuplicates = append(appsWithPossibleDuplicates, customization.Apps...) | ||
} | ||
// 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. | ||
DanielleMaywood marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
if name := config.Configuration.Customizations.Coder.Name; name != "" { | ||
// We only want to pick this name if it is a valid name. | ||
if provisioner.AgentNameRegex.Match([]byte(name)) { | ||
possibleAgentName = name | ||
} else { | ||
logger.Warn(ctx, "invalid agent name in devcontainer customization, ignoring", slog.F("name", name)) | ||
} | ||
} | ||
} | ||
displayApps := make([]codersdk.DisplayApp, 0, len(displayAppsMap)) | ||
@@ -1204,6 +1219,10 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c | ||
subAgentConfig.DisplayApps = displayApps | ||
subAgentConfig.Apps = apps | ||
if possibleAgentName != "" { | ||
subAgentConfig.Name = possibleAgentName | ||
DanielleMaywood marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
} | ||
} | ||
deleteSubAgent := proc.agent.ID != uuid.Nil && maybeRecreateSubAgent && !proc.agent.EqualConfig(subAgentConfig) | ||
77 changes: 64 additions & 13 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
14 changes: 12 additions & 2 deletionsagent/agentcontainers/devcontainercli.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
8 changes: 4 additions & 4 deletionsagent/agentcontainers/devcontainercli_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.