- Notifications
You must be signed in to change notification settings - Fork929
feat: Improve resource preview and first-time experience#946
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
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
21 commits Select commitHold shift + click to select a range
85745ab
Improve CLI documentation
kylecarbse8258ea
feat: Allow workspace resources to attach multiple agents
kylecarbs6abc4a4
Merge branch 'updatetfprovider' into clihelp
kylecarbsb0cb66d
Add tree view
kylecarbs6ed0bc0
Improve table UI
kylecarbs3ad0766
feat: Allow workspace resources to attach multiple agents
kylecarbs9cbadef
Merge branch 'updatetfprovider' into clihelp
kylecarbs4496f36
Rename `tunnel` to `skip-tunnel`
kylecarbs65c19bd
Add disclaimer about editing templates
kylecarbsc50d170
Add help to template create
kylecarbs326f2d5
Improve workspace create flow
kylecarbs008ba69
Add end-to-end test for config-ssh
kylecarbs71e4544
Improve testing of config-ssh
kylecarbs8fecb67
Fix workspace list
kylecarbs3e31c06
Merge branch 'main' into clihelp
kylecarbs677686b
Fix config ssh tests
kylecarbs603bd90
Update cli/configssh.go
kylecarbs2a6c607
Fix requested changes
kylecarbsfec214d
Merge branch 'clihelp' of github.com:coder/coder into clihelp
kylecarbsf397afc
Remove socat requirement
kylecarbs683f87e
Fix resources not reading in TTY
kylecarbsFile 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
5 changes: 5 additions & 0 deletionsagent/agent.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
91 changes: 80 additions & 11 deletionsagent/agent_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
2 changes: 2 additions & 0 deletionscli/cliui/cliui.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
60 changes: 40 additions & 20 deletionscli/cliui/prompt.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
140 changes: 140 additions & 0 deletionscli/cliui/resources.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 |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package cliui | ||
import ( | ||
"fmt" | ||
"io" | ||
"sort" | ||
"strconv" | ||
"github.com/jedib0t/go-pretty/v6/table" | ||
"github.com/coder/coder/coderd/database" | ||
"github.com/coder/coder/codersdk" | ||
) | ||
type WorkspaceResourcesOptions struct { | ||
WorkspaceName string | ||
HideAgentState bool | ||
HideAccess bool | ||
Title string | ||
} | ||
// WorkspaceResources displays the connection status and tree-view of provided resources. | ||
// ┌────────────────────────────────────────────────────────────────────────────┐ | ||
// │ RESOURCE STATUS ACCESS │ | ||
// ├────────────────────────────────────────────────────────────────────────────┤ | ||
// │ google_compute_disk.root persistent │ | ||
// ├────────────────────────────────────────────────────────────────────────────┤ | ||
// │ google_compute_instance.dev ephemeral │ | ||
// │ └─ dev (linux, amd64) ⦾ connecting [10s] coder ssh dev.dev │ | ||
// ├────────────────────────────────────────────────────────────────────────────┤ | ||
// │ kubernetes_pod.dev ephemeral │ | ||
// │ ├─ go (linux, amd64) ⦿ connected coder ssh dev.go │ | ||
// │ └─ postgres (linux, amd64) ⦾ disconnected [4s] coder ssh dev.postgres │ | ||
// └────────────────────────────────────────────────────────────────────────────┘ | ||
func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource, options WorkspaceResourcesOptions) error { | ||
kylecarbs marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
// Sort resources by type for consistent output. | ||
sort.Slice(resources, func(i, j int) bool { | ||
return resources[i].Type < resources[j].Type | ||
}) | ||
// Address on stop indexes whether a resource still exists when in the stopped transition. | ||
addressOnStop := map[string]codersdk.WorkspaceResource{} | ||
for _, resource := range resources { | ||
if resource.Transition != database.WorkspaceTransitionStop { | ||
continue | ||
} | ||
addressOnStop[resource.Address] = resource | ||
} | ||
// Displayed stores whether a resource has already been shown. | ||
// Resources can be stored with numerous states, which we | ||
// process prior to display. | ||
displayed := map[string]struct{}{} | ||
tableWriter := table.NewWriter() | ||
if options.Title != "" { | ||
tableWriter.SetTitle(options.Title) | ||
} | ||
tableWriter.SetStyle(table.StyleLight) | ||
tableWriter.Style().Options.SeparateColumns = false | ||
row := table.Row{"Resource", "Status"} | ||
if !options.HideAccess { | ||
row = append(row, "Access") | ||
} | ||
tableWriter.AppendHeader(row) | ||
totalAgents := 0 | ||
for _, resource := range resources { | ||
totalAgents += len(resource.Agents) | ||
} | ||
for _, resource := range resources { | ||
if resource.Type == "random_string" { | ||
// Hide resources that aren't substantial to a user! | ||
// This is an unfortunate case, and we should allow | ||
// callers to hide resources eventually. | ||
continue | ||
} | ||
if _, shown := displayed[resource.Address]; shown { | ||
// The same resource can have multiple transitions. | ||
continue | ||
} | ||
displayed[resource.Address] = struct{}{} | ||
// Sort agents by name for consistent output. | ||
sort.Slice(resource.Agents, func(i, j int) bool { | ||
return resource.Agents[i].Name < resource.Agents[j].Name | ||
}) | ||
_, existsOnStop := addressOnStop[resource.Address] | ||
resourceState := "ephemeral" | ||
if existsOnStop { | ||
resourceState = "persistent" | ||
} | ||
// Display a line for the resource. | ||
tableWriter.AppendRow(table.Row{ | ||
Styles.Bold.Render(resource.Type + "." + resource.Name), | ||
Styles.Placeholder.Render(resourceState), | ||
"", | ||
}) | ||
// Display all agents associated with the resource. | ||
for index, agent := range resource.Agents { | ||
sshCommand := "coder ssh " + options.WorkspaceName | ||
if totalAgents > 1 { | ||
sshCommand += "." + agent.Name | ||
} | ||
sshCommand = Styles.Code.Render(sshCommand) | ||
var agentStatus string | ||
if !options.HideAgentState { | ||
switch agent.Status { | ||
case codersdk.WorkspaceAgentConnecting: | ||
since := database.Now().Sub(agent.CreatedAt) | ||
agentStatus = Styles.Warn.Render("⦾ connecting") + " " + | ||
Styles.Placeholder.Render("["+strconv.Itoa(int(since.Seconds()))+"s]") | ||
case codersdk.WorkspaceAgentDisconnected: | ||
since := database.Now().Sub(*agent.DisconnectedAt) | ||
agentStatus = Styles.Error.Render("⦾ disconnected") + " " + | ||
Styles.Placeholder.Render("["+strconv.Itoa(int(since.Seconds()))+"s]") | ||
case codersdk.WorkspaceAgentConnected: | ||
agentStatus = Styles.Keyword.Render("⦿ connected") | ||
} | ||
} | ||
pipe := "├" | ||
if index == len(resource.Agents)-1 { | ||
pipe = "└" | ||
} | ||
row := table.Row{ | ||
// These tree from a resource! | ||
fmt.Sprintf("%s─ %s (%s, %s)", pipe, agent.Name, agent.OperatingSystem, agent.Architecture), | ||
agentStatus, | ||
} | ||
if !options.HideAccess { | ||
row = append(row, sshCommand) | ||
} | ||
tableWriter.AppendRow(row) | ||
} | ||
tableWriter.AppendSeparator() | ||
} | ||
_, err := fmt.Fprintln(writer, tableWriter.Render()) | ||
return err | ||
} |
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.