@@ -863,11 +863,12 @@ func (r *basicResumeTokenRefresher) refresh() {
863
863
}
864
864
865
865
type TunnelAllWorkspaceUpdatesController struct {
866
- coordCtrl * TunnelSrcCoordController
867
- dnsHostSetter DNSHostsSetter
868
- updateHandler UpdatesHandler
869
- ownerUsername string
870
- logger slog.Logger
866
+ coordCtrl * TunnelSrcCoordController
867
+ dnsHostSetter DNSHostsSetter
868
+ dnsNameOptions DNSNameOptions
869
+ updateHandler UpdatesHandler
870
+ ownerUsername string
871
+ logger slog.Logger
871
872
872
873
mu sync.Mutex
873
874
updater * tunnelUpdater
@@ -882,37 +883,39 @@ type Workspace struct {
882
883
agents map [uuid.UUID ]* Agent
883
884
}
884
885
886
+ type DNSNameOptions struct {
887
+ Suffix string
888
+ }
889
+
885
890
// updateDNSNames updates the DNS names for all agents in the workspace.
886
891
// DNS hosts must be all lowercase, or the resolver won't be able to find them.
887
892
// Usernames are globally unique & case-insensitive.
888
893
// Workspace names are unique per-user & case-insensitive.
889
894
// Agent names are unique per-workspace & case-insensitive.
890
- func (w * Workspace ) updateDNSNames () error {
895
+ func (w * Workspace ) updateDNSNames (options DNSNameOptions ) error {
891
896
wsName := strings .ToLower (w .Name )
892
897
username := strings .ToLower (w .ownerUsername )
893
898
for id , a := range w .agents {
894
899
agentName := strings .ToLower (a .Name )
895
900
names := make (map [dnsname.FQDN ][]netip.Addr )
896
901
// TODO: technically, DNS labels cannot start with numbers, but the rules are often not
897
902
// strictly enforced.
898
- fqdn , err := dnsname .ToFQDN (fmt .Sprintf ("%s.%s.me.coder ." , agentName , wsName ))
903
+ fqdn , err := dnsname .ToFQDN (fmt .Sprintf ("%s.%s.me.%s ." , agentName , wsName , options . Suffix ))
899
904
if err != nil {
900
905
return err
901
906
}
902
907
names [fqdn ] = []netip.Addr {CoderServicePrefix .AddrFromUUID (a .ID )}
903
- fqdn , err = dnsname .ToFQDN (fmt .Sprintf ("%s.%s.%s.coder ." , agentName , wsName , username ))
908
+ fqdn , err = dnsname .ToFQDN (fmt .Sprintf ("%s.%s.%s.%s ." , agentName , wsName , username , options . Suffix ))
904
909
if err != nil {
905
910
return err
906
911
}
907
912
names [fqdn ] = []netip.Addr {CoderServicePrefix .AddrFromUUID (a .ID )}
908
913
if len (w .agents ) == 1 {
909
- fqdn , err : = dnsname .ToFQDN (fmt .Sprintf ("%s.coder ." , wsName ))
914
+ fqdn , err = dnsname .ToFQDN (fmt .Sprintf ("%s.%s ." , wsName , options . Suffix ))
910
915
if err != nil {
911
916
return err
912
917
}
913
- for _ , a := range w .agents {
914
- names [fqdn ] = []netip.Addr {CoderServicePrefix .AddrFromUUID (a .ID )}
915
- }
918
+ names [fqdn ] = []netip.Addr {CoderServicePrefix .AddrFromUUID (a .ID )}
916
919
}
917
920
a .Hosts = names
918
921
w .agents [id ] = a
@@ -949,6 +952,7 @@ func (t *TunnelAllWorkspaceUpdatesController) New(client WorkspaceUpdatesClient)
949
952
logger : t .logger ,
950
953
coordCtrl : t .coordCtrl ,
951
954
dnsHostsSetter : t .dnsHostSetter ,
955
+ dnsNameOptions : t .dnsNameOptions ,
952
956
updateHandler : t .updateHandler ,
953
957
ownerUsername : t .ownerUsername ,
954
958
recvLoopDone : make (chan struct {}),
@@ -995,6 +999,7 @@ type tunnelUpdater struct {
995
999
updateHandler UpdatesHandler
996
1000
ownerUsername string
997
1001
recvLoopDone chan struct {}
1002
+ dnsNameOptions DNSNameOptions
998
1003
999
1004
sync.Mutex
1000
1005
workspaces map [uuid.UUID ]* Workspace
@@ -1249,7 +1254,7 @@ func (t *tunnelUpdater) allAgentIDsLocked() []uuid.UUID {
1249
1254
func (t * tunnelUpdater ) updateDNSNamesLocked () map [dnsname.FQDN ][]netip.Addr {
1250
1255
names := make (map [dnsname.FQDN ][]netip.Addr )
1251
1256
for _ , w := range t .workspaces {
1252
- err := w .updateDNSNames ()
1257
+ err := w .updateDNSNames (t . dnsNameOptions )
1253
1258
if err != nil {
1254
1259
// This should never happen in production, because converting the FQDN only fails
1255
1260
// if names are too long, and we put strict length limits on agent, workspace, and user
@@ -1272,10 +1277,11 @@ type TunnelAllOption func(t *TunnelAllWorkspaceUpdatesController)
1272
1277
1273
1278
// WithDNS configures the tunnelAllWorkspaceUpdatesController to set DNS names for all workspaces
1274
1279
// and agents it learns about.
1275
- func WithDNS (d DNSHostsSetter , ownerUsername string ) TunnelAllOption {
1280
+ func WithDNS (d DNSHostsSetter , ownerUsername string , options DNSNameOptions ) TunnelAllOption {
1276
1281
return func (t * TunnelAllWorkspaceUpdatesController ) {
1277
1282
t .dnsHostSetter = d
1278
1283
t .ownerUsername = ownerUsername
1284
+ t .dnsNameOptions = options
1279
1285
}
1280
1286
}
1281
1287
@@ -1291,7 +1297,11 @@ func WithHandler(h UpdatesHandler) TunnelAllOption {
1291
1297
func NewTunnelAllWorkspaceUpdatesController (
1292
1298
logger slog.Logger , c * TunnelSrcCoordController , opts ... TunnelAllOption ,
1293
1299
) * TunnelAllWorkspaceUpdatesController {
1294
- t := & TunnelAllWorkspaceUpdatesController {logger : logger , coordCtrl : c }
1300
+ t := & TunnelAllWorkspaceUpdatesController {
1301
+ logger : logger ,
1302
+ coordCtrl : c ,
1303
+ dnsNameOptions : DNSNameOptions {"coder" },
1304
+ }
1295
1305
for _ , opt := range opts {
1296
1306
opt (t )
1297
1307
}
0 commit comments