Skip to content

Commit 9f4033d

Browse files
Inject listener into tunnelserver instead of hardcoding stdio
1 parent 43f0848 commit 9f4033d

File tree

5 files changed

+21
-23
lines changed

5 files changed

+21
-23
lines changed

cmd/build.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
config2 "github.com/loft-sh/devpod/pkg/devcontainer/config"
1515
"github.com/loft-sh/devpod/pkg/image"
1616
"github.com/loft-sh/devpod/pkg/provider"
17+
"github.com/loft-sh/devpod/pkg/stdio"
1718
workspace2 "github.com/loft-sh/devpod/pkg/workspace"
1819
"github.com/loft-sh/log"
1920
"github.com/pkg/errors"
@@ -229,8 +230,7 @@ func buildAgentClient(ctx context.Context, workspaceClient client.WorkspaceClien
229230
// create container etc.
230231
result, err := tunnelserver.RunUpServer(
231232
cancelCtx,
232-
stdoutReader,
233-
stdinWriter,
233+
stdio.NewStdioListener(stdoutReader, stdinWriter, false),
234234
workspaceClient.AgentInjectGitCredentials(cliOptions),
235235
workspaceClient.AgentInjectDockerCredentials(cliOptions),
236236
workspaceClient.WorkspaceConfig(),

cmd/up.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/loft-sh/devpod/pkg/port"
3939
provider2 "github.com/loft-sh/devpod/pkg/provider"
4040
devssh "github.com/loft-sh/devpod/pkg/ssh"
41+
"github.com/loft-sh/devpod/pkg/stdio"
4142
"github.com/loft-sh/devpod/pkg/telemetry"
4243
"github.com/loft-sh/devpod/pkg/tunnel"
4344
"github.com/loft-sh/devpod/pkg/util"
@@ -442,8 +443,7 @@ func (cmd *UpCmd) devPodUpProxy(
442443
// create container etc.
443444
result, err := tunnelserver.RunUpServer(
444445
cancelCtx,
445-
stdoutReader,
446-
stdinWriter,
446+
stdio.NewStdioListener(stdoutReader, stdinWriter, false),
447447
true,
448448
true,
449449
client.WorkspaceConfig(),
@@ -562,8 +562,7 @@ func (cmd *UpCmd) devPodUpMachine(
562562
func(ctx context.Context, stdin io.WriteCloser, stdout io.Reader) (*config2.Result, error) {
563563
return tunnelserver.RunUpServer(
564564
ctx,
565-
stdout,
566-
stdin,
565+
stdio.NewStdioListener(stdout, stdin, false),
567566
client.AgentInjectGitCredentials(cmd.CLIOptions),
568567
client.AgentInjectDockerCredentials(cmd.CLIOptions),
569568
client.WorkspaceConfig(),

pkg/agent/tunnelserver/tunnelserver.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"encoding/base64"
77
"encoding/json"
88
"fmt"
9-
"io"
9+
"net"
1010
"os"
1111
"path/filepath"
1212
"strings"
@@ -23,15 +23,14 @@ import (
2323
"github.com/loft-sh/devpod/pkg/netstat"
2424
"github.com/loft-sh/devpod/pkg/platform"
2525
provider2 "github.com/loft-sh/devpod/pkg/provider"
26-
"github.com/loft-sh/devpod/pkg/stdio"
2726
"github.com/loft-sh/log"
2827
"github.com/moby/patternmatcher/ignorefile"
2928
perrors "github.com/pkg/errors"
3029
"google.golang.org/grpc"
3130
"google.golang.org/grpc/reflection"
3231
)
3332

34-
func RunServicesServer(ctx context.Context, reader io.Reader, writer io.WriteCloser, allowGitCredentials, allowDockerCredentials bool, forwarder netstat.Forwarder, workspace *provider2.Workspace, log log.Logger, options ...Option) error {
33+
func RunServicesServer(ctx context.Context, lis net.Listener, allowGitCredentials, allowDockerCredentials bool, forwarder netstat.Forwarder, workspace *provider2.Workspace, log log.Logger, options ...Option) error {
3534
opts := append(options, []Option{
3635
WithForwarder(forwarder),
3736
WithAllowGitCredentials(allowGitCredentials),
@@ -40,21 +39,21 @@ func RunServicesServer(ctx context.Context, reader io.Reader, writer io.WriteClo
4039
}...)
4140
tunnelServ := New(log, opts...)
4241

43-
return tunnelServ.Run(ctx, reader, writer)
42+
return tunnelServ.Run(ctx, lis)
4443
}
4544

46-
func RunUpServer(ctx context.Context, reader io.Reader, writer io.WriteCloser, allowGitCredentials, allowDockerCredentials bool, workspace *provider2.Workspace, log log.Logger, options ...Option) (*config.Result, error) {
45+
func RunUpServer(ctx context.Context, lis net.Listener, allowGitCredentials, allowDockerCredentials bool, workspace *provider2.Workspace, log log.Logger, options ...Option) (*config.Result, error) {
4746
opts := append(options, []Option{
4847
WithWorkspace(workspace),
4948
WithAllowGitCredentials(allowGitCredentials),
5049
WithAllowDockerCredentials(allowDockerCredentials),
5150
}...)
5251
tunnelServ := New(log, opts...)
5352

54-
return tunnelServ.RunWithResult(ctx, reader, writer)
53+
return tunnelServ.RunWithResult(ctx, lis)
5554
}
5655

57-
func RunSetupServer(ctx context.Context, reader io.Reader, writer io.WriteCloser, allowGitCredentials, allowDockerCredentials bool, mounts []*config.Mount, log log.Logger, options ...Option) (*config.Result, error) {
56+
func RunSetupServer(ctx context.Context, lis net.Listener, allowGitCredentials, allowDockerCredentials bool, mounts []*config.Mount, log log.Logger, options ...Option) (*config.Result, error) {
5857
opts := append(options, []Option{
5958
WithMounts(mounts),
6059
WithAllowGitCredentials(allowGitCredentials),
@@ -64,7 +63,7 @@ func RunSetupServer(ctx context.Context, reader io.Reader, writer io.WriteCloser
6463
tunnelServ := New(log, opts...)
6564
tunnelServ.allowPlatformOptions = true
6665

67-
return tunnelServ.RunWithResult(ctx, reader, writer)
66+
return tunnelServ.RunWithResult(ctx, lis)
6867
}
6968

7069
func New(log log.Logger, options ...Option) *tunnelServer {
@@ -96,8 +95,7 @@ type tunnelServer struct {
9695
platformOptions *devpod.PlatformOptions
9796
}
9897

99-
func (t *tunnelServer) RunWithResult(ctx context.Context, reader io.Reader, writer io.WriteCloser) (*config.Result, error) {
100-
lis := stdio.NewStdioListener(reader, writer, false)
98+
func (t *tunnelServer) RunWithResult(ctx context.Context, lis net.Listener) (*config.Result, error) {
10199
s := grpc.NewServer()
102100
tunnel.RegisterTunnelServer(s, t)
103101
reflection.Register(s)
@@ -114,8 +112,8 @@ func (t *tunnelServer) RunWithResult(ctx context.Context, reader io.Reader, writ
114112
}
115113
}
116114

117-
func (t *tunnelServer) Run(ctx context.Context, reader io.Reader, writer io.WriteCloser) error {
118-
_, err := t.RunWithResult(ctx, reader, writer)
115+
func (t *tunnelServer) Run(ctx context.Context, lis net.Listener) error {
116+
_, err := t.RunWithResult(ctx, lis)
119117
return err
120118
}
121119

pkg/devcontainer/setup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/loft-sh/devpod/pkg/driver"
2121
"github.com/loft-sh/devpod/pkg/ide"
2222
provider2 "github.com/loft-sh/devpod/pkg/provider"
23+
"github.com/loft-sh/devpod/pkg/stdio"
2324
"github.com/loft-sh/log"
2425
"github.com/pkg/errors"
2526
"github.com/sirupsen/logrus"
@@ -127,8 +128,7 @@ func (r *runner) setupContainer(
127128
runSetupServer := func(ctx context.Context, stdin io.WriteCloser, stdout io.Reader) (*config.Result, error) {
128129
return tunnelserver.RunSetupServer(
129130
ctx,
130-
stdout,
131-
stdin,
131+
stdio.NewStdioListener(stdout, stdin, false),
132132
r.WorkspaceConfig.Agent.InjectGitCredentials != "false",
133133
r.WorkspaceConfig.Agent.InjectDockerCredentials != "false",
134134
config.GetMounts(result),

pkg/tunnel/services.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/loft-sh/devpod/pkg/netstat"
2525
"github.com/loft-sh/devpod/pkg/provider"
2626
devssh "github.com/loft-sh/devpod/pkg/ssh"
27+
"github.com/loft-sh/devpod/pkg/stdio"
2728
"github.com/loft-sh/log"
2829
"github.com/pkg/errors"
2930
"github.com/sirupsen/logrus"
@@ -92,11 +93,11 @@ func RunServices(
9293
go func() {
9394
defer cancel()
9495
defer stdinWriter.Close()
95-
// forward credentials to container
96+
// TODO: pass either stdio or network listener depending on whether or not we're using the platform
97+
// Start local credentials server and forward credentials to container
9698
err := tunnelserver.RunServicesServer(
9799
cancelCtx,
98-
stdoutReader,
99-
stdinWriter,
100+
stdio.NewStdioListener(stdoutReader, stdinWriter, false),
100101
configureGitCredentials,
101102
configureDockerCredentials,
102103
forwarder,

0 commit comments

Comments
 (0)