Skip to content

Commit 383b64f

Browse files
authored
Merge branch 'main' into stevenmasley/param_form_type
2 parents 108ad42 + 1314dbd commit 383b64f

File tree

51 files changed

+1714
-296
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1714
-296
lines changed

agent/agent.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ type Options struct {
9595
}
9696

9797
type Client interface {
98-
ConnectRPC24(ctx context.Context) (
99-
proto.DRPCAgentClient24, tailnetproto.DRPCTailnetClient24, error,
98+
ConnectRPC25(ctx context.Context) (
99+
proto.DRPCAgentClient25, tailnetproto.DRPCTailnetClient25, error,
100100
)
101101
RewriteDERPMap(derpMap *tailcfg.DERPMap)
102102
}
@@ -908,7 +908,7 @@ func (a *agent) run() (retErr error) {
908908
a.sessionToken.Store(&sessionToken)
909909

910910
// ConnectRPC returns the dRPC connection we use for the Agent and Tailnet v2+ APIs
911-
aAPI, tAPI, err := a.client.ConnectRPC24(a.hardCtx)
911+
aAPI, tAPI, err := a.client.ConnectRPC25(a.hardCtx)
912912
if err != nil {
913913
return err
914914
}

agent/agenttest/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ func (c *Client) Close() {
9898
c.derpMapOnce.Do(func() { close(c.derpMapUpdates) })
9999
}
100100

101-
func (c *Client) ConnectRPC24(ctx context.Context) (
102-
agentproto.DRPCAgentClient24, proto.DRPCTailnetClient24, error,
101+
func (c *Client) ConnectRPC25(ctx context.Context) (
102+
agentproto.DRPCAgentClient25, proto.DRPCTailnetClient25, error,
103103
) {
104104
conn, lis := drpcsdk.MemTransportPipe()
105105
c.LastWorkspaceAgent = func() {

agent/proto/agent.pb.go

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

agent/proto/agent.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ message Manifest {
9090
string motd_path = 6;
9191
bool disable_direct_connections = 7;
9292
bool derp_force_websockets = 8;
93+
optional bytes parent_id = 18;
9394

9495
coder.tailnet.v2.DERPMap derp_map = 9;
9596
repeated WorkspaceAgentScript scripts = 10;

agent/proto/agent_drpc_old.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,8 @@ type DRPCAgentClient24 interface {
5050
PushResourcesMonitoringUsage(ctx context.Context, in *PushResourcesMonitoringUsageRequest) (*PushResourcesMonitoringUsageResponse, error)
5151
ReportConnection(ctx context.Context, in *ReportConnectionRequest) (*emptypb.Empty, error)
5252
}
53+
54+
// DRPCAgentClient25 is the Agent API at v2.5.
55+
type DRPCAgentClient25 interface {
56+
DRPCAgentClient24
57+
}

cli/testdata/coder_provisioner_jobs_list_--help.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ OPTIONS:
1111
-O, --org string, $CODER_ORGANIZATION
1212
Select which organization (uuid or name) to use.
1313

14-
-c, --column [id|created at|started at|completed at|canceled at|error|error code|status|worker id|file id|tags|queue position|queue size|organization id|template version id|workspace build id|type|available workers|template version name|template id|template name|template display name|template icon|workspace id|workspace name|organization|queue] (default: created at,id,type,template display name,status,queue,tags)
14+
-c, --column [id|created at|started at|completed at|canceled at|error|error code|status|worker id|worker name|file id|tags|queue position|queue size|organization id|template version id|workspace build id|type|available workers|template version name|template id|template name|template display name|template icon|workspace id|workspace name|organization|queue] (default: created at,id,type,template display name,status,queue,tags)
1515
Columns to display in table output.
1616

1717
-l, --limit int, $CODER_PROVISIONER_JOB_LIST_LIMIT (default: 50)

cli/testdata/coder_provisioner_jobs_list_--output_json.golden

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"completed_at": "====[timestamp]=====",
77
"status": "succeeded",
88
"worker_id": "====[workspace build worker ID]=====",
9+
"worker_name": "test-daemon",
910
"file_id": "=====[workspace build file ID]======",
1011
"tags": {
1112
"owner": "",
@@ -34,6 +35,7 @@
3435
"completed_at": "====[timestamp]=====",
3536
"status": "succeeded",
3637
"worker_id": "====[workspace build worker ID]=====",
38+
"worker_name": "test-daemon",
3739
"file_id": "=====[workspace build file ID]======",
3840
"tags": {
3941
"owner": "",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
CREATED AT LAST SEEN AT KEY NAME NAME VERSION STATUS TAGS
2-
====[timestamp]===== ====[timestamp]===== built-in test v0.0.0-devel idle map[owner: scope:organization]
1+
CREATED AT LAST SEEN AT KEY NAME NAME VERSION STATUS TAGS
2+
====[timestamp]===== ====[timestamp]===== built-in test-daemon v0.0.0-devel idle map[owner: scope:organization]

cli/testdata/coder_provisioner_list_--output_json.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"key_id": "00000000-0000-0000-0000-000000000001",
66
"created_at": "====[timestamp]=====",
77
"last_seen_at": "====[timestamp]=====",
8-
"name": "test",
8+
"name": "test-daemon",
99
"version": "v0.0.0-devel",
1010
"api_version": "1.6",
1111
"provisioners": [

coderd/agentapi/manifest.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ func (a *ManifestAPI) GetManifest(ctx context.Context, _ *agentproto.GetManifest
120120
return nil, xerrors.Errorf("converting workspace apps: %w", err)
121121
}
122122

123+
var parentID []byte
124+
if workspaceAgent.ParentID.Valid {
125+
parentID = workspaceAgent.ParentID.UUID[:]
126+
}
127+
123128
return &agentproto.Manifest{
124129
AgentId: workspaceAgent.ID[:],
125130
AgentName: workspaceAgent.Name,
@@ -133,6 +138,7 @@ func (a *ManifestAPI) GetManifest(ctx context.Context, _ *agentproto.GetManifest
133138
MotdPath: workspaceAgent.MOTDFile,
134139
DisableDirectConnections: a.DisableDirectConnections,
135140
DerpForceWebsockets: a.DerpForceWebSockets,
141+
ParentId: parentID,
136142

137143
DerpMap: tailnet.DERPMapToProto(a.DerpMapFn()),
138144
Scripts: dbAgentScriptsToProto(scripts),

coderd/agentapi/manifest_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ func TestGetManifest(t *testing.T) {
6060
Directory: "/cool/dir",
6161
MOTDFile: "/cool/motd",
6262
}
63+
childAgent = database.WorkspaceAgent{
64+
ID: uuid.New(),
65+
Name: "cool-child-agent",
66+
ParentID: uuid.NullUUID{Valid: true, UUID: agent.ID},
67+
Directory: "/workspace/dir",
68+
MOTDFile: "/workspace/motd",
69+
}
6370
apps = []database.WorkspaceApp{
6471
{
6572
ID: uuid.New(),
@@ -337,6 +344,7 @@ func TestGetManifest(t *testing.T) {
337344
expected := &agentproto.Manifest{
338345
AgentId: agent.ID[:],
339346
AgentName: agent.Name,
347+
ParentId: nil,
340348
OwnerUsername: owner.Username,
341349
WorkspaceId: workspace.ID[:],
342350
WorkspaceName: workspace.Name,
@@ -364,6 +372,70 @@ func TestGetManifest(t *testing.T) {
364372
require.Equal(t, expected, got)
365373
})
366374

375+
t.Run("OK/Child", func(t *testing.T) {
376+
t.Parallel()
377+
378+
mDB := dbmock.NewMockStore(gomock.NewController(t))
379+
380+
api := &agentapi.ManifestAPI{
381+
AccessURL: &url.URL{Scheme: "https", Host: "example.com"},
382+
AppHostname: "*--apps.example.com",
383+
ExternalAuthConfigs: []*externalauth.Config{
384+
{Type: string(codersdk.EnhancedExternalAuthProviderGitHub)},
385+
{Type: "some-provider"},
386+
{Type: string(codersdk.EnhancedExternalAuthProviderGitLab)},
387+
},
388+
DisableDirectConnections: true,
389+
DerpForceWebSockets: true,
390+
391+
AgentFn: func(ctx context.Context) (database.WorkspaceAgent, error) {
392+
return childAgent, nil
393+
},
394+
WorkspaceID: workspace.ID,
395+
Database: mDB,
396+
DerpMapFn: derpMapFn,
397+
}
398+
399+
mDB.EXPECT().GetWorkspaceAppsByAgentID(gomock.Any(), childAgent.ID).Return([]database.WorkspaceApp{}, nil)
400+
mDB.EXPECT().GetWorkspaceAgentScriptsByAgentIDs(gomock.Any(), []uuid.UUID{childAgent.ID}).Return([]database.WorkspaceAgentScript{}, nil)
401+
mDB.EXPECT().GetWorkspaceAgentMetadata(gomock.Any(), database.GetWorkspaceAgentMetadataParams{
402+
WorkspaceAgentID: childAgent.ID,
403+
Keys: nil, // all
404+
}).Return([]database.WorkspaceAgentMetadatum{}, nil)
405+
mDB.EXPECT().GetWorkspaceAgentDevcontainersByAgentID(gomock.Any(), childAgent.ID).Return([]database.WorkspaceAgentDevcontainer{}, nil)
406+
mDB.EXPECT().GetWorkspaceByID(gomock.Any(), workspace.ID).Return(workspace, nil)
407+
mDB.EXPECT().GetUserByID(gomock.Any(), workspace.OwnerID).Return(owner, nil)
408+
409+
got, err := api.GetManifest(context.Background(), &agentproto.GetManifestRequest{})
410+
require.NoError(t, err)
411+
412+
expected := &agentproto.Manifest{
413+
AgentId: childAgent.ID[:],
414+
AgentName: childAgent.Name,
415+
ParentId: agent.ID[:],
416+
OwnerUsername: owner.Username,
417+
WorkspaceId: workspace.ID[:],
418+
WorkspaceName: workspace.Name,
419+
GitAuthConfigs: 2, // two "enhanced" external auth configs
420+
EnvironmentVariables: nil,
421+
Directory: childAgent.Directory,
422+
VsCodePortProxyUri: fmt.Sprintf("https://{{port}}--%s--%s--%s--apps.example.com", childAgent.Name, workspace.Name, owner.Username),
423+
MotdPath: childAgent.MOTDFile,
424+
DisableDirectConnections: true,
425+
DerpForceWebsockets: true,
426+
// tailnet.DERPMapToProto() is extensively tested elsewhere, so it's
427+
// not necessary to manually recreate a big DERP map here like we
428+
// did for apps and metadata.
429+
DerpMap: tailnet.DERPMapToProto(derpMapFn()),
430+
Scripts: []*agentproto.WorkspaceAgentScript{},
431+
Apps: []*agentproto.WorkspaceApp{},
432+
Metadata: []*agentproto.WorkspaceAgentMetadata_Description{},
433+
Devcontainers: []*agentproto.WorkspaceAgentDevcontainer{},
434+
}
435+
436+
require.Equal(t, expected, got)
437+
})
438+
367439
t.Run("NoAppHostname", func(t *testing.T) {
368440
t.Parallel()
369441

coderd/apidoc/docs.go

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

coderd/apidoc/swagger.json

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

coderd/coderdtest/coderdtest.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ import (
9696
"github.com/coder/coder/v2/testutil"
9797
)
9898

99+
const defaultTestDaemonName = "test-daemon"
100+
99101
type Options struct {
100102
// AccessURL denotes a custom access URL. By default we use the httptest
101103
// server's URL. Setting this may result in unexpected behavior (especially
@@ -602,7 +604,7 @@ func NewWithAPI(t testing.TB, options *Options) (*codersdk.Client, io.Closer, *c
602604
setHandler(rootHandler)
603605
var provisionerCloser io.Closer = nopcloser{}
604606
if options.IncludeProvisionerDaemon {
605-
provisionerCloser = NewTaggedProvisionerDaemon(t, coderAPI, "test", options.ProvisionerDaemonTags, coderd.MemoryProvisionerWithVersionOverride(options.ProvisionerDaemonVersion))
607+
provisionerCloser = NewTaggedProvisionerDaemon(t, coderAPI, defaultTestDaemonName, options.ProvisionerDaemonTags, coderd.MemoryProvisionerWithVersionOverride(options.ProvisionerDaemonVersion))
606608
}
607609
client := codersdk.New(serverURL)
608610
t.Cleanup(func() {
@@ -646,7 +648,7 @@ func (c *ProvisionerdCloser) Close() error {
646648
// well with coderd testing. It registers the "echo" provisioner for
647649
// quick testing.
648650
func NewProvisionerDaemon(t testing.TB, coderAPI *coderd.API) io.Closer {
649-
return NewTaggedProvisionerDaemon(t, coderAPI, "test", nil)
651+
return NewTaggedProvisionerDaemon(t, coderAPI, defaultTestDaemonName, nil)
650652
}
651653

652654
func NewTaggedProvisionerDaemon(t testing.TB, coderAPI *coderd.API, name string, provisionerTags map[string]string, opts ...coderd.MemoryProvisionerDaemonOption) io.Closer {

coderd/database/dbmem/dbmem.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4848,6 +4848,13 @@ func (q *FakeQuerier) GetProvisionerJobsByOrganizationAndStatusWithQueuePosition
48484848
row.AvailableWorkers = append(row.AvailableWorkers, worker.ID)
48494849
}
48504850
}
4851+
4852+
// Add daemon name to provisioner job
4853+
for _, daemon := range q.provisionerDaemons {
4854+
if job.WorkerID.Valid && job.WorkerID.UUID == daemon.ID {
4855+
row.WorkerName = daemon.Name
4856+
}
4857+
}
48514858
rows = append(rows, row)
48524859
}
48534860

0 commit comments

Comments
 (0)