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

Commit0a47fd1

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 commit0a47fd1

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

‎cli/ssh.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -926,35 +926,38 @@ func getWorkspaceAgent(workspace codersdk.Workspace, agentName string) (workspac
926926
resources:=workspace.LatestBuild.Resources
927927

928928
agents:=make([]codersdk.WorkspaceAgent,0)
929+
subAgents:=make([]codersdk.WorkspaceAgent,0)
929930
for_,resource:=rangeresources {
930-
agents=append(agents,resource.Agents...)
931+
for_,agent:=rangeresource.Agents {
932+
ifagent.ParentID.UUID==uuid.Nil {
933+
agents=append(agents,agent)
934+
}else {
935+
subAgents=append(subAgents,agent)
936+
}
937+
}
931938
}
932939
iflen(agents)==0 {
933940
return codersdk.WorkspaceAgent{},xerrors.Errorf("workspace %q has no agents",workspace.Name)
934941
}
935942
ifagentName!="" {
943+
agents=append(agents,subAgents...)
936944
for_,otherAgent:=rangeagents {
937945
ifotherAgent.Name!=agentName {
938946
continue
939947
}
940-
workspaceAgent=otherAgent
941-
break
942-
}
943-
ifworkspaceAgent.ID==uuid.Nil {
944-
return codersdk.WorkspaceAgent{},xerrors.Errorf("agent not found by name %q",agentName)
948+
returnotherAgent,nil
945949
}
950+
return codersdk.WorkspaceAgent{},xerrors.Errorf("agent not found by name %q",agentName)
946951
}
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-
}
952+
iflen(subAgents)==1 {
953+
returnsubAgents[0],nil
954+
}elseiflen(subAgents)>1 {
955+
return codersdk.WorkspaceAgent{},xerrors.New("multiple sub-agents found, please specify the agent name")
956+
}
957+
iflen(agents)==1 {
958+
returnagents[0],nil
956959
}
957-
returnworkspaceAgent,nil
960+
returncodersdk.WorkspaceAgent{},xerrors.New("multiple agents found, please specify the agent name")
958961
}
959962

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp