Skip to content

Commit 118bf98

Browse files
chore(agent): add workspace owner env var and log dev container app failures (#18433)
Listen to feedback that was missed in #18346 - Adds `CODER_WORKSPACE_OWNER_NAME` into the agent environment. - Logs warnings for when dev container app creation fails.
1 parent 8b27983 commit 118bf98

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

agent/agent.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,7 @@ func (a *agent) updateCommandEnv(current []string) (updated []string, err error)
12971297
"CODER": "true",
12981298
"CODER_WORKSPACE_NAME": manifest.WorkspaceName,
12991299
"CODER_WORKSPACE_AGENT_NAME": manifest.AgentName,
1300+
"CODER_WORKSPACE_OWNER_NAME": manifest.OwnerName,
13001301

13011302
// Specific Coder subcommands require the agent token exposed!
13021303
"CODER_AGENT_TOKEN": *a.sessionToken.Load(),

agent/agent_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ func TestAgent_EnvironmentVariableExpansion(t *testing.T) {
12091209
func TestAgent_CoderEnvVars(t *testing.T) {
12101210
t.Parallel()
12111211

1212-
for _, key := range []string{"CODER", "CODER_WORKSPACE_NAME", "CODER_WORKSPACE_AGENT_NAME"} {
1212+
for _, key := range []string{"CODER", "CODER_WORKSPACE_NAME", "CODER_WORKSPACE_OWNER_NAME", "CODER_WORKSPACE_AGENT_NAME"} {
12131213
key := key
12141214
t.Run(key, func(t *testing.T) {
12151215
t.Parallel()
@@ -3079,6 +3079,9 @@ func setupAgent(t *testing.T, metadata agentsdk.Manifest, ptyTimeout time.Durati
30793079
if metadata.WorkspaceName == "" {
30803080
metadata.WorkspaceName = "test-workspace"
30813081
}
3082+
if metadata.OwnerName == "" {
3083+
metadata.OwnerName = "test-user"
3084+
}
30823085
if metadata.WorkspaceID == uuid.Nil {
30833086
metadata.WorkspaceID = uuid.New()
30843087
}

agent/agentcontainers/subagent.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,20 @@ func (a *subAgentAPIClient) Create(ctx context.Context, agent SubAgent) (SubAgen
243243
if err != nil {
244244
return agent, err
245245
}
246+
247+
for _, appError := range resp.AppCreationErrors {
248+
app := apps[appError.Index]
249+
250+
a.logger.Warn(ctx, "unable to create app",
251+
slog.F("agent_name", agent.Name),
252+
slog.F("agent_id", agent.ID),
253+
slog.F("directory", agent.Directory),
254+
slog.F("app_slug", app.Slug),
255+
slog.F("field", appError.GetField()),
256+
slog.F("error", appError.GetError()),
257+
)
258+
}
259+
246260
return agent, nil
247261
}
248262

0 commit comments

Comments
 (0)