Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit647181e

Browse files
committed
fix(cli)!: select sub agent if available and error on multiple agents
In the past we randomly selected workspace agent if there were multiple.Unless both are running on the same machine with the same configuration,this would be very confusing behavior for a user.With the introduction of sub agents (devcontainer agents), it wasdecided prioritize them if present. Similarly as before, selecting adevcontainer randomly would be confusing. We now error out if the agentname is not specified and there are multiple agents.Fixescoder/internal#696
1 parent5e3a225 commit647181e

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

‎cli/ssh.go

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -925,36 +925,44 @@ func getWorkspaceAndAgent(ctx context.Context, inv *serpent.Invocation, client *
925925
funcgetWorkspaceAgent(workspace codersdk.Workspace,agentNamestring) (workspaceAgent codersdk.WorkspaceAgent,errerror) {
926926
resources:=workspace.LatestBuild.Resources
927927

928-
agents:=make([]codersdk.WorkspaceAgent,0)
928+
var (
929+
availableNames []string
930+
agents []codersdk.WorkspaceAgent
931+
subAgents []codersdk.WorkspaceAgent
932+
)
929933
for_,resource:=rangeresources {
930-
agents=append(agents,resource.Agents...)
934+
for_,agent:=rangeresource.Agents {
935+
availableNames=append(availableNames,agent.Name)
936+
ifagent.ParentID.UUID==uuid.Nil {
937+
agents=append(agents,agent)
938+
}else {
939+
subAgents=append(subAgents,agent)
940+
}
941+
}
931942
}
932943
iflen(agents)==0 {
933944
return codersdk.WorkspaceAgent{},xerrors.Errorf("workspace %q has no agents",workspace.Name)
934945
}
946+
slices.Sort(availableNames)
935947
ifagentName!="" {
948+
agents=append(agents,subAgents...)
936949
for_,otherAgent:=rangeagents {
937950
ifotherAgent.Name!=agentName {
938951
continue
939952
}
940-
workspaceAgent=otherAgent
941-
break
942-
}
943-
ifworkspaceAgent.ID==uuid.Nil {
944-
return codersdk.WorkspaceAgent{},xerrors.Errorf("agent not found by name %q",agentName)
953+
returnotherAgent,nil
945954
}
955+
return codersdk.WorkspaceAgent{},xerrors.Errorf("agent not found by name %q, available agents: %v",agentName,availableNames)
946956
}
947-
ifworkspaceAgent.ID==uuid.Nil {
948-
iflen(agents)>1 {
949-
workspaceAgent,err=cryptorand.Element(agents)
950-
iferr!=nil {
951-
return codersdk.WorkspaceAgent{},err
952-
}
953-
}else {
954-
workspaceAgent=agents[0]
955-
}
957+
iflen(subAgents)==1 {
958+
returnsubAgents[0],nil
959+
}elseiflen(subAgents)>1 {
960+
return codersdk.WorkspaceAgent{},xerrors.Errorf("multiple sub-agents found, please specify the agent name, available agents: %v",availableNames)
961+
}
962+
iflen(agents)==1 {
963+
returnagents[0],nil
956964
}
957-
returnworkspaceAgent,nil
965+
returncodersdk.WorkspaceAgent{},xerrors.Errorf("multiple agents found, please specify the agent name, available agents: %v",availableNames)
958966
}
959967

960968
// Attempt to poll workspace autostop. We write a per-workspace lockfile to

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp