fix: Remove resource addresses (#982)

These were added under the impression that there was significant
user-experience impact if multiple resources share the same name.

This hasn't proven to be true yet, so figured we'd take this out
until it becomes necessary.
This commit is contained in:
Kyle Carberry
2022-04-12 14:38:02 -05:00
committed by GitHub
parent 52271ff9f8
commit e8b310166f
14 changed files with 17 additions and 171 deletions
+6 -5
View File
@@ -44,7 +44,7 @@ func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource
if resource.Transition != database.WorkspaceTransitionStop {
continue
}
addressOnStop[resource.Address] = resource
addressOnStop[resource.Type+"."+resource.Name] = resource
}
// Displayed stores whether a resource has already been shown.
// Resources can be stored with numerous states, which we
@@ -75,24 +75,25 @@ func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource
// callers to hide resources eventually.
continue
}
if _, shown := displayed[resource.Address]; shown {
resourceAddress := resource.Type + "." + resource.Name
if _, shown := displayed[resourceAddress]; shown {
// The same resource can have multiple transitions.
continue
}
displayed[resource.Address] = struct{}{}
displayed[resourceAddress] = 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]
_, existsOnStop := addressOnStop[resourceAddress]
resourceState := "ephemeral"
if existsOnStop {
resourceState = "persistent"
}
// Display a line for the resource.
tableWriter.AppendRow(table.Row{
Styles.Bold.Render(resource.Type + "." + resource.Name),
Styles.Bold.Render(resourceAddress),
Styles.Placeholder.Render(resourceState),
"",
})
-3
View File
@@ -42,17 +42,14 @@ func TestWorkspaceResources(t *testing.T) {
disconnected := database.Now().Add(-4 * time.Second)
go func() {
err := cliui.WorkspaceResources(ptty.Output(), []codersdk.WorkspaceResource{{
Address: "disk",
Transition: database.WorkspaceTransitionStart,
Type: "google_compute_disk",
Name: "root",
}, {
Address: "disk",
Transition: database.WorkspaceTransitionStop,
Type: "google_compute_disk",
Name: "root",
}, {
Address: "another",
Transition: database.WorkspaceTransitionStart,
Type: "google_compute_instance",
Name: "dev",