Skip to content

Commit bede39d

Browse files
committed
Merge branch 'main' into multibuild
2 parents 96b068b + e8b3101 commit bede39d

File tree

15 files changed

+17
-227
lines changed

15 files changed

+17
-227
lines changed

cli/cliui/resources.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource
4444
if resource.Transition != database.WorkspaceTransitionStop {
4545
continue
4646
}
47-
addressOnStop[resource.Address] = resource
47+
addressOnStop[resource.Type+"."+resource.Name] = resource
4848
}
4949
// Displayed stores whether a resource has already been shown.
5050
// Resources can be stored with numerous states, which we
@@ -75,24 +75,25 @@ func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource
7575
// callers to hide resources eventually.
7676
continue
7777
}
78-
if _, shown := displayed[resource.Address]; shown {
78+
resourceAddress := resource.Type + "." + resource.Name
79+
if _, shown := displayed[resourceAddress]; shown {
7980
// The same resource can have multiple transitions.
8081
continue
8182
}
82-
displayed[resource.Address] = struct{}{}
83+
displayed[resourceAddress] = struct{}{}
8384

8485
// Sort agents by name for consistent output.
8586
sort.Slice(resource.Agents, func(i, j int) bool {
8687
return resource.Agents[i].Name < resource.Agents[j].Name
8788
})
88-
_, existsOnStop := addressOnStop[resource.Address]
89+
_, existsOnStop := addressOnStop[resourceAddress]
8990
resourceState := "ephemeral"
9091
if existsOnStop {
9192
resourceState = "persistent"
9293
}
9394
// Display a line for the resource.
9495
tableWriter.AppendRow(table.Row{
95-
Styles.Bold.Render(resource.Type + "." + resource.Name),
96+
Styles.Bold.Render(resourceAddress),
9697
Styles.Placeholder.Render(resourceState),
9798
"",
9899
})

cli/cliui/resources_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,14 @@ func TestWorkspaceResources(t *testing.T) {
4242
disconnected := database.Now().Add(-4 * time.Second)
4343
go func() {
4444
err := cliui.WorkspaceResources(ptty.Output(), []codersdk.WorkspaceResource{{
45-
Address: "disk",
4645
Transition: database.WorkspaceTransitionStart,
4746
Type: "google_compute_disk",
4847
Name: "root",
4948
}, {
50-
Address: "disk",
5149
Transition: database.WorkspaceTransitionStop,
5250
Type: "google_compute_disk",
5351
Name: "root",
5452
}, {
55-
Address: "another",
5653
Transition: database.WorkspaceTransitionStart,
5754
Type: "google_compute_instance",
5855
Name: "dev",

cmd/cliui/main.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,14 @@ func main() {
188188
RunE: func(cmd *cobra.Command, args []string) error {
189189
disconnected := database.Now().Add(-4 * time.Second)
190190
return cliui.WorkspaceResources(cmd.OutOrStdout(), []codersdk.WorkspaceResource{{
191-
Address: "disk",
192191
Transition: database.WorkspaceTransitionStart,
193192
Type: "google_compute_disk",
194193
Name: "root",
195194
}, {
196-
Address: "disk",
197195
Transition: database.WorkspaceTransitionStop,
198196
Type: "google_compute_disk",
199197
Name: "root",
200198
}, {
201-
Address: "another",
202199
Transition: database.WorkspaceTransitionStart,
203200
Type: "google_compute_instance",
204201
Name: "dev",

coderd/database/databasefake/databasefake.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,6 @@ func (q *fakeQuerier) InsertWorkspaceResource(_ context.Context, arg database.In
10261026
CreatedAt: arg.CreatedAt,
10271027
JobID: arg.JobID,
10281028
Transition: arg.Transition,
1029-
Address: arg.Address,
10301029
Type: arg.Type,
10311030
Name: arg.Name,
10321031
}

coderd/database/dump.sql

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/migrations/000004_jobs.up.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ CREATE TABLE workspace_resources (
6666
created_at timestamptz NOT NULL,
6767
job_id uuid NOT NULL REFERENCES provisioner_jobs (id) ON DELETE CASCADE,
6868
transition workspace_transition NOT NULL,
69-
address varchar(256) NOT NULL,
7069
type varchar(192) NOT NULL,
7170
name varchar(64) NOT NULL,
7271
PRIMARY KEY (id)

coderd/database/models.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 4 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaceresources.sql

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ WHERE
1616

1717
-- name: InsertWorkspaceResource :one
1818
INSERT INTO
19-
workspace_resources (
20-
id,
21-
created_at,
22-
job_id,
23-
transition,
24-
address,
25-
type,
26-
name
27-
)
19+
workspace_resources (id, created_at, job_id, transition, type, name)
2820
VALUES
29-
($1, $2, $3, $4, $5, $6, $7) RETURNING *;
21+
($1, $2, $3, $4, $5, $6) RETURNING *;

coderd/provisionerdaemons.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"github.com/coder/coder/coderd/httpapi"
2828
"github.com/coder/coder/coderd/parameter"
2929
"github.com/coder/coder/provisionerd/proto"
30-
"github.com/coder/coder/provisionersdk"
3130
sdkproto "github.com/coder/coder/provisionersdk/proto"
3231
)
3332

@@ -475,18 +474,14 @@ func (server *provisionerdServer) CompleteJob(ctx context.Context, completed *pr
475474
database.WorkspaceTransitionStart: jobType.TemplateImport.StartResources,
476475
database.WorkspaceTransitionStop: jobType.TemplateImport.StopResources,
477476
} {
478-
addresses, err := provisionersdk.ResourceAddresses(resources)
479-
if err != nil {
480-
return nil, xerrors.Errorf("compute resource addresses: %w", err)
481-
}
482-
for index, resource := range resources {
477+
for _, resource := range resources {
483478
server.Logger.Info(ctx, "inserting template import job resource",
484479
slog.F("job_id", job.ID.String()),
485480
slog.F("resource_name", resource.Name),
486481
slog.F("resource_type", resource.Type),
487482
slog.F("transition", transition))
488483

489-
err = insertWorkspaceResource(ctx, server.Database, jobID, transition, resource, addresses[index])
484+
err = insertWorkspaceResource(ctx, server.Database, jobID, transition, resource)
490485
if err != nil {
491486
return nil, xerrors.Errorf("insert resource: %w", err)
492487
}
@@ -540,13 +535,9 @@ func (server *provisionerdServer) CompleteJob(ctx context.Context, completed *pr
540535
if err != nil {
541536
return xerrors.Errorf("update workspace build: %w", err)
542537
}
543-
addresses, err := provisionersdk.ResourceAddresses(jobType.WorkspaceBuild.Resources)
544-
if err != nil {
545-
return xerrors.Errorf("compute resource addresses: %w", err)
546-
}
547538
// This could be a bulk insert to improve performance.
548-
for index, protoResource := range jobType.WorkspaceBuild.Resources {
549-
err = insertWorkspaceResource(ctx, db, job.ID, workspaceBuild.Transition, protoResource, addresses[index])
539+
for _, protoResource := range jobType.WorkspaceBuild.Resources {
540+
err = insertWorkspaceResource(ctx, db, job.ID, workspaceBuild.Transition, protoResource)
550541
if err != nil {
551542
return xerrors.Errorf("insert provisioner job: %w", err)
552543
}
@@ -578,13 +569,12 @@ func (server *provisionerdServer) CompleteJob(ctx context.Context, completed *pr
578569
return &proto.Empty{}, nil
579570
}
580571

581-
func insertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.UUID, transition database.WorkspaceTransition, protoResource *sdkproto.Resource, address string) error {
572+
func insertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.UUID, transition database.WorkspaceTransition, protoResource *sdkproto.Resource) error {
582573
resource, err := db.InsertWorkspaceResource(ctx, database.InsertWorkspaceResourceParams{
583574
ID: uuid.New(),
584575
CreatedAt: database.Now(),
585576
JobID: jobID,
586577
Transition: transition,
587-
Address: address,
588578
Type: protoResource.Type,
589579
Name: protoResource.Name,
590580
})

coderd/workspacebuilds.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ func convertWorkspaceResource(resource database.WorkspaceResource, agents []code
110110
CreatedAt: resource.CreatedAt,
111111
JobID: resource.JobID,
112112
Transition: resource.Transition,
113-
Address: resource.Address,
114113
Type: resource.Type,
115114
Name: resource.Name,
116115
Agents: agents,

coderd/workspacebuilds_test.go

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,10 @@ import (
66
"testing"
77
"time"
88

9-
"github.com/google/uuid"
109
"github.com/stretchr/testify/require"
1110

12-
"cdr.dev/slog/sloggers/slogtest"
13-
14-
"github.com/coder/coder/agent"
1511
"github.com/coder/coder/coderd/coderdtest"
16-
"github.com/coder/coder/coderd/database"
1712
"github.com/coder/coder/codersdk"
18-
"github.com/coder/coder/peer"
1913
"github.com/coder/coder/provisioner/echo"
2014
"github.com/coder/coder/provisionersdk/proto"
2115
)
@@ -121,56 +115,6 @@ func TestWorkspaceBuildResources(t *testing.T) {
121115
require.Equal(t, "example", resources[0].Type)
122116
require.Len(t, resources[0].Agents, 1)
123117
})
124-
t.Run("MultipleBuilds", func(t *testing.T) {
125-
// This ensures that the latest agent can connect through multiple builds.
126-
// Agents won't always have new authentication tokens on rebuild, because
127-
// infrastructure as code won't always recreate the resource.
128-
t.Parallel()
129-
client := coderdtest.New(t, nil)
130-
user := coderdtest.CreateFirstUser(t, client)
131-
coderdtest.NewProvisionerDaemon(t, client)
132-
authToken := uuid.NewString()
133-
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
134-
Parse: echo.ParseComplete,
135-
Provision: []*proto.Provision_Response{{
136-
Type: &proto.Provision_Response_Complete{
137-
Complete: &proto.Provision_Complete{
138-
Resources: []*proto.Resource{{
139-
Name: "some",
140-
Type: "example",
141-
Agents: []*proto.Agent{{
142-
Id: "something",
143-
Auth: &proto.Agent_Token{
144-
Token: authToken,
145-
},
146-
}},
147-
}},
148-
},
149-
},
150-
}},
151-
})
152-
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
153-
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
154-
workspace := coderdtest.CreateWorkspace(t, client, codersdk.Me, template.ID)
155-
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
156-
build, err := client.CreateWorkspaceBuild(context.Background(), workspace.ID, codersdk.CreateWorkspaceBuildRequest{
157-
TemplateVersionID: template.ActiveVersionID,
158-
Transition: database.WorkspaceTransitionStart,
159-
DryRun: false,
160-
})
161-
require.NoError(t, err)
162-
coderdtest.AwaitWorkspaceBuildJob(t, client, build.ID)
163-
164-
agentClient := codersdk.New(client.URL)
165-
agentClient.SessionToken = authToken
166-
agentCloser := agent.New(agentClient.ListenWorkspaceAgent, &peer.ConnOptions{
167-
Logger: slogtest.Make(t, nil),
168-
})
169-
t.Cleanup(func() {
170-
_ = agentCloser.Close()
171-
})
172-
coderdtest.AwaitWorkspaceAgents(t, client, build.ID)
173-
})
174118
}
175119

176120
func TestWorkspaceBuildLogs(t *testing.T) {

codersdk/workspaceresources.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ type WorkspaceResource struct {
2525
CreatedAt time.Time `json:"created_at"`
2626
JobID uuid.UUID `json:"job_id"`
2727
Transition database.WorkspaceTransition `json:"workspace_transition"`
28-
Address string `json:"address"`
2928
Type string `json:"type"`
3029
Name string `json:"name"`
3130
Agents []WorkspaceAgent `json:"agents,omitempty"`

0 commit comments

Comments
 (0)