Skip to content

Commit 50f1c7f

Browse files
committed
hide behind experimental flag
1 parent 92130fe commit 50f1c7f

File tree

4 files changed

+56
-42
lines changed

4 files changed

+56
-42
lines changed

agent/agent.go

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,27 @@ const (
6868
)
6969

7070
type Options struct {
71-
Filesystem afero.Fs
72-
LogDir string
73-
TempDir string
74-
ScriptDataDir string
75-
ExchangeToken func(ctx context.Context) (string, error)
76-
Client Client
77-
ReconnectingPTYTimeout time.Duration
78-
EnvironmentVariables map[string]string
79-
Logger slog.Logger
80-
IgnorePorts map[int]string
81-
PortCacheDuration time.Duration
82-
SSHMaxTimeout time.Duration
83-
TailnetListenPort uint16
84-
Subsystems []codersdk.AgentSubsystem
85-
PrometheusRegistry *prometheus.Registry
86-
ReportMetadataInterval time.Duration
87-
ServiceBannerRefreshInterval time.Duration
88-
BlockFileTransfer bool
89-
Execer agentexec.Execer
90-
ContainerLister agentcontainers.Lister
71+
Filesystem afero.Fs
72+
LogDir string
73+
TempDir string
74+
ScriptDataDir string
75+
ExchangeToken func(ctx context.Context) (string, error)
76+
Client Client
77+
ReconnectingPTYTimeout time.Duration
78+
EnvironmentVariables map[string]string
79+
Logger slog.Logger
80+
IgnorePorts map[int]string
81+
PortCacheDuration time.Duration
82+
SSHMaxTimeout time.Duration
83+
TailnetListenPort uint16
84+
Subsystems []codersdk.AgentSubsystem
85+
PrometheusRegistry *prometheus.Registry
86+
ReportMetadataInterval time.Duration
87+
ServiceBannerRefreshInterval time.Duration
88+
BlockFileTransfer bool
89+
Execer agentexec.Execer
90+
ContainerLister agentcontainers.Lister
91+
ExperimentalContainersEnabled bool
9192
}
9293

9394
type Client interface {
@@ -184,10 +185,11 @@ func New(options Options) Agent {
184185
logSender: agentsdk.NewLogSender(options.Logger),
185186
blockFileTransfer: options.BlockFileTransfer,
186187

187-
prometheusRegistry: prometheusRegistry,
188-
metrics: newAgentMetrics(prometheusRegistry),
189-
execer: options.Execer,
190-
lister: options.ContainerLister,
188+
prometheusRegistry: prometheusRegistry,
189+
metrics: newAgentMetrics(prometheusRegistry),
190+
execer: options.Execer,
191+
lister: options.ContainerLister,
192+
experimentalDevcontainersEnabled: options.ExperimentalContainersEnabled,
191193
}
192194
// Initially, we have a closed channel, reflecting the fact that we are not initially connected.
193195
// Each time we connect we replace the channel (while holding the closeMutex) with a new one
@@ -255,9 +257,10 @@ type agent struct {
255257
prometheusRegistry *prometheus.Registry
256258
// metrics are prometheus registered metrics that will be collected and
257259
// labeled in Coder with the agent + workspace.
258-
metrics *agentMetrics
259-
execer agentexec.Execer
260-
lister agentcontainers.Lister
260+
metrics *agentMetrics
261+
execer agentexec.Execer
262+
lister agentcontainers.Lister
263+
experimentalDevcontainersEnabled bool
261264
}
262265

263266
func (a *agent) TailnetConn() *tailnet.Conn {
@@ -297,6 +300,9 @@ func (a *agent) init() {
297300
a.sshServer,
298301
a.metrics.connectionsTotal, a.metrics.reconnectingPTYErrors,
299302
a.reconnectingPTYTimeout,
303+
func(s *reconnectingpty.Server) {
304+
s.ExperimentalContainersEnabled = a.experimentalDevcontainersEnabled
305+
},
300306
)
301307
go a.runLoop()
302308
}

agent/agent_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,9 @@ func TestAgent_ReconnectingPTYContainer(t *testing.T) {
17971797
}, testutil.WaitShort, testutil.IntervalSlow, "Container did not start in time")
17981798

17991799
// nolint: dogsled
1800-
conn, _, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0)
1800+
conn, _, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0, func(_ *agenttest.Client, o *agent.Options) {
1801+
o.ExperimentalContainersEnabled = true
1802+
})
18011803
ac, err := conn.ReconnectingPTY(ctx, uuid.New(), 80, 80, "/bin/sh", func(arp *workspacesdk.AgentReconnectingPTYInit) {
18021804
arp.Container = ct.Container.ID
18031805
})

agent/reconnectingpty/server.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,32 @@ import (
2121
)
2222

2323
type Server struct {
24-
logger slog.Logger
25-
connectionsTotal prometheus.Counter
26-
errorsTotal *prometheus.CounterVec
27-
commandCreator *agentssh.Server
28-
connCount atomic.Int64
29-
reconnectingPTYs sync.Map
30-
timeout time.Duration
24+
logger slog.Logger
25+
connectionsTotal prometheus.Counter
26+
errorsTotal *prometheus.CounterVec
27+
commandCreator *agentssh.Server
28+
connCount atomic.Int64
29+
reconnectingPTYs sync.Map
30+
timeout time.Duration
31+
ExperimentalContainersEnabled bool
3132
}
3233

3334
// NewServer returns a new ReconnectingPTY server
3435
func NewServer(logger slog.Logger, commandCreator *agentssh.Server,
3536
connectionsTotal prometheus.Counter, errorsTotal *prometheus.CounterVec,
36-
timeout time.Duration,
37+
timeout time.Duration, opts ...func(*Server),
3738
) *Server {
38-
return &Server{
39+
s := &Server{
3940
logger: logger,
4041
commandCreator: commandCreator,
4142
connectionsTotal: connectionsTotal,
4243
errorsTotal: errorsTotal,
4344
timeout: timeout,
4445
}
46+
for _, o := range opts {
47+
o(s)
48+
}
49+
return s
4550
}
4651

4752
func (s *Server) Serve(ctx, hardCtx context.Context, l net.Listener) (retErr error) {
@@ -161,7 +166,7 @@ func (s *Server) handleConn(ctx context.Context, logger slog.Logger, conn net.Co
161166
}()
162167

163168
var ei usershell.EnvInfoer
164-
if msg.Container != "" {
169+
if s.ExperimentalContainersEnabled && msg.Container != "" {
165170
dei, err := agentcontainers.EnvInfo(ctx, s.commandCreator.Execer, msg.Container, msg.ContainerUser)
166171
if err != nil {
167172
return xerrors.Errorf("get container env info: %w", err)

cli/agent.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,11 @@ func (r *RootCmd) workspaceAgent() *serpent.Command {
347347
SSHMaxTimeout: sshMaxTimeout,
348348
Subsystems: subsystems,
349349

350-
PrometheusRegistry: prometheusRegistry,
351-
BlockFileTransfer: blockFileTransfer,
352-
Execer: execer,
353-
ContainerLister: containerLister,
350+
PrometheusRegistry: prometheusRegistry,
351+
BlockFileTransfer: blockFileTransfer,
352+
Execer: execer,
353+
ContainerLister: containerLister,
354+
ExperimentalContainersEnabled: devcontainersEnabled,
354355
})
355356

356357
promHandler := agent.PrometheusMetricsHandler(prometheusRegistry, logger)

0 commit comments

Comments
 (0)