Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
15 changes: 14 additions & 1 deletion agent/agent.go
Original file line number Diff line number Diff 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 Down Expand Up @@ -111,6 +112,16 @@ func New(options Options) Agent {
prometheusRegistry = prometheus.NewRegistry()
}

if len(options.Addresses) == 0 {
options.Addresses = []netip.Prefix{
// This is the IP that should be used primarily.
netip.PrefixFrom(tailnet.IP(), 128),
// We also listen on the legacy codersdk.WorkspaceAgentIP. This
// allows for a transition away from wsconncache.
netip.PrefixFrom(codersdk.WorkspaceAgentIP, 128),
}
}

ctx, cancelFunc := context.WithCancel(context.Background())
a := &agent{
tailnetListenPort: options.TailnetListenPort,
Expand All @@ -131,6 +142,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 Down Expand Up @@ -174,6 +186,7 @@ type agent struct {
lifecycleStates []agentsdk.PostLifecycleRequest

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

Expand Down Expand Up @@ -639,7 +652,7 @@ func (a *agent) trackConnGoroutine(fn func()) error {

func (a *agent) createTailnet(ctx context.Context, 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.addresses,
DERPMap: derpMap,
Logger: a.logger.Named("tailnet"),
ListenPort: a.tailnetListenPort,
Expand Down
Loading