Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: replace wsconncache with a single tailnet#8176

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

Merged
coadler merged 26 commits intomainfromcolin/rm-wsconncache2
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
26 commits
Select commitHold shift + click to select a range
7222135
chore: replace wsconncache with a single tailnet
coadlerJun 26, 2023
d4181b0
remove duplicate AwaitReachable
coadlerJun 26, 2023
2a133d1
properly release net.Conn
coadlerJun 26, 2023
aa6bcb6
tailnetTransport
coadlerJun 26, 2023
f9040fc
link to issue in deprecation notice
coadlerJun 26, 2023
a988fef
address review comments
coadlerJun 28, 2023
2e201dc
fixup! address review comments
coadlerJun 28, 2023
5901f68
Merge branch 'main' into colin/rm-wsconncache2
coadlerJun 28, 2023
311ea2b
second round
coadlerJun 28, 2023
30aefcb
fixup! second round
coadlerJun 28, 2023
e55e146
support swapping coordinators
coadlerJun 29, 2023
457470d
use multiagents for all clients
coadlerJun 29, 2023
2c32434
Merge branch 'main' into colin/rm-wsconncache2
coadlerJun 29, 2023
11f2805
fixups
coadlerJun 30, 2023
a88be66
fixup! fixups
coadlerJun 30, 2023
49a8364
Merge branch 'main' into colin/rm-wsconncache2
coadlerJun 30, 2023
5e4b631
fixes
coadlerJun 30, 2023
8ef2fb7
Merge branch 'main' into colin/rm-wsconncache2
coadlerJun 30, 2023
9864d89
Merge branch 'main' into colin/rm-wsconncache2
coadlerJul 7, 2023
dd3cc15
comment
coadlerJul 7, 2023
8896ae4
fixup! comment
coadlerJul 7, 2023
be4db71
fixup! comment
coadlerJul 7, 2023
7bfac9b
add feature flag
coadlerJul 11, 2023
10d44fe
Merge branch 'main' into colin/rm-wsconncache2
coadlerJul 11, 2023
ef44092
fixes
coadlerJul 12, 2023
9a29d85
Merge branch 'main' into colin/rm-wsconncache2
coadlerJul 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletionsagent/agent.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,6 +64,7 @@ type Options struct {
SSHMaxTimeout time.Duration
TailnetListenPort uint16
Subsystem codersdk.AgentSubsystem
Addresses []netip.Prefix

PrometheusRegistry *prometheus.Registry
}
Expand DownExpand Up@@ -132,6 +133,7 @@ func New(options Options) Agent {
connStatsChan: make(chan *agentsdk.Stats, 1),
sshMaxTimeout: options.SSHMaxTimeout,
subsystem: options.Subsystem,
addresses: options.Addresses,

prometheusRegistry: prometheusRegistry,
metrics: newAgentMetrics(prometheusRegistry),
Expand DownExpand Up@@ -177,6 +179,7 @@ type agent struct {
lifecycleStates []agentsdk.PostLifecycleRequest

network *tailnet.Conn
addresses []netip.Prefix
connStatsChan chan *agentsdk.Stats
latestStat atomic.Pointer[agentsdk.Stats]

Expand DownExpand Up@@ -545,6 +548,10 @@ func (a *agent) run(ctx context.Context) error {
}
a.logger.Info(ctx, "fetched manifest", slog.F("manifest", manifest))

if manifest.AgentID == uuid.Nil {
return xerrors.New("nil agentID returned by manifest")
}

// Expand the directory and send it back to coderd so external
// applications that rely on the directory can use it.
//
Expand DownExpand Up@@ -630,7 +637,7 @@ func (a *agent) run(ctx context.Context) error {
network := a.network
a.closeMutex.Unlock()
if network == nil {
network, err = a.createTailnet(ctx, manifest.DERPMap, manifest.DisableDirectConnections)
network, err = a.createTailnet(ctx, manifest.AgentID, manifest.DERPMap, manifest.DisableDirectConnections)
if err != nil {
return xerrors.Errorf("create tailnet: %w", err)
}
Expand All@@ -648,6 +655,11 @@ func (a *agent) run(ctx context.Context) error {

a.startReportingConnectionStats(ctx)
} else {
// Update the wireguard IPs if the agent ID changed.
err := network.SetAddresses(a.wireguardAddresses(manifest.AgentID))
if err != nil {
a.logger.Error(ctx, "update tailnet addresses", slog.Error(err))
}
// Update the DERP map and allow/disallow direct connections.
network.SetDERPMap(manifest.DERPMap)
network.SetBlockEndpoints(manifest.DisableDirectConnections)
Expand All@@ -661,6 +673,20 @@ func (a *agent) run(ctx context.Context) error {
return nil
}

func (a *agent) wireguardAddresses(agentID uuid.UUID) []netip.Prefix {
if len(a.addresses) == 0 {
return []netip.Prefix{
// This is the IP that should be used primarily.
netip.PrefixFrom(tailnet.IPFromUUID(agentID), 128),
// We also listen on the legacy codersdk.WorkspaceAgentIP. This
// allows for a transition away from wsconncache.
netip.PrefixFrom(codersdk.WorkspaceAgentIP, 128),
}
}

return a.addresses
}

func (a *agent) trackConnGoroutine(fn func()) error {
a.closeMutex.Lock()
defer a.closeMutex.Unlock()
Expand All@@ -675,9 +701,9 @@ func (a *agent) trackConnGoroutine(fn func()) error {
return nil
}

func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap, disableDirectConnections bool) (_ *tailnet.Conn, err error) {
func (a *agent) createTailnet(ctx context.Context,agentID uuid.UUID,derpMap *tailcfg.DERPMap, disableDirectConnections bool) (_ *tailnet.Conn, err error) {
network, err := tailnet.NewConn(&tailnet.Options{
Addresses:[]netip.Prefix{netip.PrefixFrom(codersdk.WorkspaceAgentIP, 128)},
Addresses:a.wireguardAddresses(agentID),
DERPMap: derpMap,
Logger: a.logger.Named("tailnet"),
ListenPort: a.tailnetListenPort,
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp