Skip to content

Commit b9b5c9f

Browse files
committed
Merge branch 'main' into mes/debounce-fix
2 parents 4266b85 + 6746e16 commit b9b5c9f

Some content is hidden

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

45 files changed

+2635
-305
lines changed

.github/.linkspector.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ ignorePatterns:
2525
- pattern: "docs.github.com"
2626
- pattern: "claude.ai"
2727
- pattern: "splunk.com"
28+
- pattern: "stackoverflow.com/questions"
2829
aliveStatusCodes:
2930
- 200

CODEOWNERS

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
# These APIs are versioned, so any changes need to be carefully reviewed for whether
2-
# to bump API major or minor versions.
1+
# These APIs are versioned, so any changes need to be carefully reviewed for
2+
# whether to bump API major or minor versions.
33
agent/proto/ @spikecurtis @johnstcn
4+
provisionerd/proto/ @spikecurtis @johnstcn
5+
provisionersdk/proto/ @spikecurtis @johnstcn
46
tailnet/proto/ @spikecurtis @johnstcn
57
vpn/vpn.proto @spikecurtis @johnstcn
68
vpn/version.go @spikecurtis @johnstcn
7-
provisionerd/proto/ @spikecurtis @johnstcn
8-
provisionersdk/proto/ @spikecurtis @johnstcn
9+
10+
11+
# This caching code is particularly tricky, and one must be very careful when
12+
# altering it.
13+
coderd/files/ @aslilac
14+
15+
16+
site/ @aslilac

agent/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ type Client interface {
9898
ConnectRPC26(ctx context.Context) (
9999
proto.DRPCAgentClient26, tailnetproto.DRPCTailnetClient26, error,
100100
)
101-
RewriteDERPMap(derpMap *tailcfg.DERPMap)
101+
tailnet.DERPMapRewriter
102102
}
103103

104104
type Agent interface {

agent/agentcontainers/api_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,15 +358,22 @@ func TestAPI(t *testing.T) {
358358
fakeCLI = &fakeContainerCLI{
359359
listErr: firstErr,
360360
}
361+
fWatcher = newFakeWatcher(t)
361362
)
362363

363364
api := agentcontainers.NewAPI(logger,
365+
agentcontainers.WithWatcher(fWatcher),
364366
agentcontainers.WithClock(mClock),
365367
agentcontainers.WithContainerCLI(fakeCLI),
366368
)
367369
api.Start()
368370
defer api.Close()
369371

372+
// The watcherLoop writes a log when it is initialized.
373+
// We want to ensure this has happened before we start
374+
// the test so that it does not intefere.
375+
fWatcher.waitNext(ctx)
376+
370377
// Make sure the ticker function has been registered
371378
// before advancing the clock.
372379
tickerTrap.MustWait(ctx).MustRelease(ctx)

coderd/apidoc/docs.go

Lines changed: 29 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: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/tailnet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func NewServerTailnet(
9898
controller := tailnet.NewController(logger, dialer)
9999
// it's important to set the DERPRegionDialer above _before_ we set the DERP map so that if
100100
// there is an embedded relay, we use the local in-memory dialer.
101-
controller.DERPCtrl = tailnet.NewBasicDERPController(logger, conn)
101+
controller.DERPCtrl = tailnet.NewBasicDERPController(logger, nil, conn)
102102
coordCtrl := NewMultiAgentController(serverCtx, logger, tracer, conn)
103103
controller.CoordCtrl = coordCtrl
104104
// TODO: support controller.TelemetryCtrl

codersdk/agentsdk/agentsdk.go

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"net/http"
99
"net/http/cookiejar"
1010
"net/url"
11-
"strconv"
1211
"time"
1312

1413
"cloud.google.com/go/compute/metadata"
@@ -27,6 +26,7 @@ import (
2726
"github.com/coder/coder/v2/coderd/httpapi"
2827
"github.com/coder/coder/v2/codersdk"
2928
"github.com/coder/coder/v2/codersdk/drpcsdk"
29+
"github.com/coder/coder/v2/tailnet"
3030
tailnetproto "github.com/coder/coder/v2/tailnet/proto"
3131
)
3232

@@ -126,40 +126,13 @@ type Script struct {
126126
Script string `json:"script"`
127127
}
128128

129-
// RewriteDERPMap rewrites the DERP map to use the access URL of the SDK as the
130-
// "embedded relay" access URL. The passed derp map is modified in place.
129+
// RewriteDERPMap rewrites the DERP map to use the configured access URL of the
130+
// agent as the "embedded relay" access URL.
131131
//
132-
// Agents can provide an arbitrary access URL that may be different that the
133-
// globally configured one. This breaks the built-in DERP, which would continue
134-
// to reference the global access URL.
132+
// See tailnet.RewriteDERPMapDefaultRelay for more details on why this is
133+
// necessary.
135134
func (c *Client) RewriteDERPMap(derpMap *tailcfg.DERPMap) {
136-
accessingPort := c.SDK.URL.Port()
137-
if accessingPort == "" {
138-
accessingPort = "80"
139-
if c.SDK.URL.Scheme == "https" {
140-
accessingPort = "443"
141-
}
142-
}
143-
accessPort, err := strconv.Atoi(accessingPort)
144-
if err != nil {
145-
// this should never happen because URL.Port() returns the empty string if the port is not
146-
// valid.
147-
c.SDK.Logger().Critical(context.Background(), "failed to parse URL port", slog.F("port", accessingPort))
148-
}
149-
for _, region := range derpMap.Regions {
150-
if !region.EmbeddedRelay {
151-
continue
152-
}
153-
154-
for _, node := range region.Nodes {
155-
if node.STUNOnly {
156-
continue
157-
}
158-
node.HostName = c.SDK.URL.Hostname()
159-
node.DERPPort = accessPort
160-
node.ForceHTTP = c.SDK.URL.Scheme == "http"
161-
}
162-
}
135+
tailnet.RewriteDERPMapDefaultRelay(context.Background(), c.SDK.Logger(), derpMap, c.SDK.URL)
163136
}
164137

165138
// ConnectRPC20 returns a dRPC client to the Agent API v2.0. Notably, it is missing

codersdk/agentsdk/agentsdk_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import (
55
"io"
66
"net/http"
77
"net/http/httptest"
8+
"net/url"
89
"testing"
910

1011
"github.com/google/uuid"
1112
"github.com/stretchr/testify/require"
13+
"tailscale.com/tailcfg"
1214

1315
"cdr.dev/slog/sloggers/slogtest"
1416
"github.com/coder/coder/v2/codersdk/agentsdk"
@@ -120,3 +122,31 @@ func TestStreamAgentReinitEvents(t *testing.T) {
120122
require.ErrorIs(t, receiveErr, context.Canceled)
121123
})
122124
}
125+
126+
func TestRewriteDERPMap(t *testing.T) {
127+
t.Parallel()
128+
// This test ensures that RewriteDERPMap mutates built-in DERPs with the
129+
// client access URL.
130+
dm := &tailcfg.DERPMap{
131+
Regions: map[int]*tailcfg.DERPRegion{
132+
1: {
133+
EmbeddedRelay: true,
134+
RegionID: 1,
135+
Nodes: []*tailcfg.DERPNode{{
136+
HostName: "bananas.org",
137+
DERPPort: 1,
138+
}},
139+
},
140+
},
141+
}
142+
parsed, err := url.Parse("https://coconuts.org:44558")
143+
require.NoError(t, err)
144+
client := agentsdk.New(parsed)
145+
client.RewriteDERPMap(dm)
146+
region := dm.Regions[1]
147+
require.True(t, region.EmbeddedRelay)
148+
require.Len(t, region.Nodes, 1)
149+
node := region.Nodes[0]
150+
require.Equal(t, "coconuts.org", node.HostName)
151+
require.Equal(t, 44558, node.DERPPort)
152+
}

0 commit comments

Comments
 (0)