Skip to content

Commit 06e4577

Browse files
Cleanup naming in workspace network server
1 parent bfab31c commit 06e4577

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

pkg/credentials/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func handleGitCredentialsOverTSNet(ctx context.Context, writer http.ResponseWrit
160160

161161
log.Infof("Received git credentials post data: %s", string(bodyBytes))
162162
// Set up HTTP transport that uses our network socket.
163-
socketPath := filepath.Join(workspaced.RootDir, network.TSNetProxySocket)
163+
socketPath := filepath.Join(workspaced.RootDir, network.NetworkProxySocket)
164164
transport := &http.Transport{
165165
Dial: func(network, addr string) (net.Conn, error) {
166166
return net.Dial("unix", socketPath)

pkg/daemon/workspace/network/port_forward.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const (
1616
// TSPortForwardPort is the fixed port on which the workspace HTTP reverse proxy listens.
1717
TSPortForwardPort string = "12051"
1818

19-
RunnerProxySocket string = "runner-proxy.sock"
20-
TSNetProxySocket string = "devpod-net.sock"
19+
RunnerProxySocket string = "runner-proxy.sock"
20+
NetworkProxySocket string = "devpod-net.sock"
2121

2222
netMapCooldown = 30 * time.Second
2323
)

pkg/daemon/workspace/network/server.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type WorkspaceServerConfig struct {
2929
// It creates and manages network server instance as well as
3030
// all services that run on DevPod network inside the workspace.
3131
type WorkspaceServer struct {
32-
tsServer *tsnet.Server
32+
network *tsnet.Server // TODO: we probably want to hide network behind our own interface at some point
3333
config *WorkspaceServerConfig
3434
log log.Logger
3535
connTracker *ConnTracker
@@ -55,47 +55,47 @@ func NewWorkspaceServer(config *WorkspaceServerConfig, logger log.Logger) *Works
5555
// Start initializes the network server server and all services, then blocks until the context is canceled.
5656
func (s *WorkspaceServer) Start(ctx context.Context) error {
5757
s.log.Infof("Starting workspace server")
58-
workspaceName, projectName, err := s.setupTSNet(ctx)
58+
workspaceName, projectName, err := s.joinNetwork(ctx)
5959
if err != nil {
6060
return err
6161
}
6262

63-
lc, err := s.tsServer.LocalClient()
63+
lc, err := s.network.LocalClient()
6464
if err != nil {
6565
return err
6666
}
6767

6868
// Create and start the SSH service.
69-
s.sshSvc, err = NewSSHServer(s.tsServer, s.connTracker, s.log)
69+
s.sshSvc, err = NewSSHServer(s.network, s.connTracker, s.log)
7070
if err != nil {
7171
return err
7272
}
7373
s.sshSvc.Start(ctx)
7474

7575
// Create and start the HTTP port forward service.
76-
s.httpProxySvc, err = NewHTTPPortForwardService(s.tsServer, s.connTracker, s.log)
76+
s.httpProxySvc, err = NewHTTPPortForwardService(s.network, s.connTracker, s.log)
7777
if err != nil {
7878
return err
7979
}
8080
s.httpProxySvc.Start(ctx)
8181

8282
// Create and start the platform git credentials service.
83-
s.platformGitCredentialsSvc, err = NewPlatformGitCredentialsService(s.config, s.tsServer, lc, projectName, workspaceName, s.log)
83+
s.platformGitCredentialsSvc, err = NewPlatformGitCredentialsService(s.config, s.network, lc, projectName, workspaceName, s.log)
8484
if err != nil {
8585
return err
8686
}
8787
s.platformGitCredentialsSvc.Start(ctx)
8888

89-
// Create and start the TS proxy service.
90-
tsProxySocket := filepath.Join(s.config.RootDir, TSNetProxySocket)
91-
s.netProxySvc, err = NewNetworkProxyService(tsProxySocket, s.tsServer, s.log)
89+
// Create and start the network proxy service.
90+
networkSocket := filepath.Join(s.config.RootDir, NetworkProxySocket)
91+
s.netProxySvc, err = NewNetworkProxyService(networkSocket, s.network, s.log)
9292
if err != nil {
9393
return err
9494
}
9595
s.netProxySvc.Start(ctx)
9696

9797
// Start the heartbeat service.
98-
s.heartbeatSvc = NewHeartbeatService(s.config, s.tsServer, lc, projectName, workspaceName, s.connTracker, s.log)
98+
s.heartbeatSvc = NewHeartbeatService(s.config, s.network, lc, projectName, workspaceName, s.connTracker, s.log)
9999
go s.heartbeatSvc.Start(ctx)
100100

101101
// Start netmap watcher.
@@ -107,7 +107,7 @@ func (s *WorkspaceServer) Start(ctx context.Context) error {
107107
return nil
108108
}
109109

110-
// Stop shuts down all sub-servers and the TSNet server.
110+
// Stop shuts down all services and the network server.
111111
func (s *WorkspaceServer) Stop() {
112112
if s.sshSvc != nil {
113113
s.sshSvc.Stop()
@@ -121,32 +121,32 @@ func (s *WorkspaceServer) Stop() {
121121
if s.netProxySvc != nil {
122122
s.netProxySvc.Stop()
123123
}
124-
if s.tsServer != nil {
125-
s.tsServer.Close()
126-
s.tsServer = nil
124+
if s.network != nil {
125+
s.network.Close()
126+
s.network = nil
127127
}
128128
s.log.Info("Workspace server stopped")
129129
}
130130

131-
// Dial dials the given address using the TSNet server.
131+
// Dial dials the given address using the network server.
132132
func (s *WorkspaceServer) Dial(ctx context.Context, network, addr string) (net.Conn, error) {
133-
if s.tsServer == nil {
134-
return nil, fmt.Errorf("tailscale server is not running")
133+
if s.network == nil {
134+
return nil, fmt.Errorf("network server is not running")
135135
}
136-
return s.tsServer.Dial(ctx, network, addr)
136+
return s.network.Dial(ctx, network, addr)
137137
}
138138

139-
// setupTSNet validates configuration, sets up the control URL, starts the TSNet server,
139+
// joinNetwork validates configuration, sets up the control URL, starts the network server,
140140
// and parses the hostname into workspace and project names.
141-
func (s *WorkspaceServer) setupTSNet(ctx context.Context) (workspace, project string, err error) {
141+
func (s *WorkspaceServer) joinNetwork(ctx context.Context) (workspace, project string, err error) {
142142
if err = s.validateConfig(); err != nil {
143143
return "", "", err
144144
}
145145
baseURL, err := s.setupControlURL(ctx)
146146
if err != nil {
147147
return "", "", err
148148
}
149-
if err = s.initTsServer(ctx, baseURL); err != nil {
149+
if err = s.initNetworkServer(ctx, baseURL); err != nil {
150150
return "", "", err
151151
}
152152
return s.parseWorkspaceHostname()
@@ -170,11 +170,11 @@ func (s *WorkspaceServer) setupControlURL(ctx context.Context) (*url.URL, error)
170170
return baseURL, nil
171171
}
172172

173-
func (s *WorkspaceServer) initTsServer(ctx context.Context, controlURL *url.URL) error {
173+
func (s *WorkspaceServer) initNetworkServer(ctx context.Context, controlURL *url.URL) error {
174174
store, _ := mem.New(s.config.LogF, "")
175175
envknob.Setenv("TS_DEBUG_TLS_DIAL_INSECURE_SKIP_VERIFY", "true")
176176
s.log.Infof("Connecting to control URL - %s/coordinator/", controlURL.String())
177-
s.tsServer = &tsnet.Server{
177+
s.network = &tsnet.Server{ // TODO: this probably could be extracted from here and local daemon into pkg/ts
178178
Hostname: s.config.WorkspaceHost,
179179
Logf: s.config.LogF,
180180
ControlURL: controlURL.String() + "/coordinator/",
@@ -183,7 +183,7 @@ func (s *WorkspaceServer) initTsServer(ctx context.Context, controlURL *url.URL)
183183
Ephemeral: true,
184184
Store: store,
185185
}
186-
if _, err := s.tsServer.Up(ctx); err != nil {
186+
if _, err := s.network.Up(ctx); err != nil {
187187
return err
188188
}
189189
return nil

0 commit comments

Comments
 (0)