feat: Allow workspace resources to attach multiple agents (#942)

This enables a "kubernetes_pod" to attach multiple agents that
could be for multiple services. Each agent is required to have
a unique name, so SSH syntax is:

`coder ssh <workspace>.<agent>`

A resource can have zero agents too, they aren't required.
This commit is contained in:
Kyle Carberry
2022-04-11 16:06:15 -05:00
committed by GitHub
parent 2835bb45e5
commit 19b4323512
47 changed files with 1550 additions and 1040 deletions

View File

@ -161,21 +161,17 @@ func main() {
root.AddCommand(&cobra.Command{
Use: "agent",
RunE: func(cmd *cobra.Command, args []string) error {
resource := codersdk.WorkspaceResource{
Type: "google_compute_instance",
Name: "dev",
Agent: &codersdk.WorkspaceAgent{
Status: codersdk.WorkspaceAgentDisconnected,
},
agent := codersdk.WorkspaceAgent{
Status: codersdk.WorkspaceAgentDisconnected,
}
go func() {
time.Sleep(3 * time.Second)
resource.Agent.Status = codersdk.WorkspaceAgentConnected
agent.Status = codersdk.WorkspaceAgentConnected
}()
err := cliui.Agent(cmd.Context(), cmd.OutOrStdout(), cliui.AgentOptions{
WorkspaceName: "dev",
Fetch: func(ctx context.Context) (codersdk.WorkspaceResource, error) {
return resource, nil
Fetch: func(ctx context.Context) (codersdk.WorkspaceAgent, error) {
return agent, nil
},
WarnInterval: 2 * time.Second,
})