Skip to content

Commit 444decb

Browse files
committed
Merge branch 'main' into execscripts
2 parents 39fb9d3 + 866ba8e commit 444decb

File tree

139 files changed

+4909
-3048
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+4909
-3048
lines changed

.github/workflows/pr-deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ jobs:
110110
set -euo pipefail
111111
mkdir -p ~/.kube
112112
echo "${{ secrets.PR_DEPLOYMENTS_KUBECONFIG }}" > ~/.kube/config
113+
chmod 644 ~/.kube/config
113114
export KUBECONFIG=~/.kube/config
114115
115116
- name: Check if the helm deployment already exists
@@ -257,6 +258,7 @@ jobs:
257258
set -euo pipefail
258259
mkdir -p ~/.kube
259260
echo "${{ secrets.PR_DEPLOYMENTS_KUBECONFIG }}" > ~/.kube/config
261+
chmod 644 ~/.kube/config
260262
export KUBECONFIG=~/.kube/config
261263
262264
- name: Check if image exists

agent/agent_test.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,13 +1607,15 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
16071607
}
16081608

16091609
// Once for typing the command...
1610-
require.NoError(t, testutil.ReadUntil(ctx, t, netConn1, matchEchoCommand), "find echo command")
1610+
tr1 := testutil.NewTerminalReader(t, netConn1)
1611+
require.NoError(t, tr1.ReadUntil(ctx, matchEchoCommand), "find echo command")
16111612
// And another time for the actual output.
1612-
require.NoError(t, testutil.ReadUntil(ctx, t, netConn1, matchEchoOutput), "find echo output")
1613+
require.NoError(t, tr1.ReadUntil(ctx, matchEchoOutput), "find echo output")
16131614

16141615
// Same for the other connection.
1615-
require.NoError(t, testutil.ReadUntil(ctx, t, netConn2, matchEchoCommand), "find echo command")
1616-
require.NoError(t, testutil.ReadUntil(ctx, t, netConn2, matchEchoOutput), "find echo output")
1616+
tr2 := testutil.NewTerminalReader(t, netConn2)
1617+
require.NoError(t, tr2.ReadUntil(ctx, matchEchoCommand), "find echo command")
1618+
require.NoError(t, tr2.ReadUntil(ctx, matchEchoOutput), "find echo output")
16171619

16181620
_ = netConn1.Close()
16191621
_ = netConn2.Close()
@@ -1622,8 +1624,9 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
16221624
defer netConn3.Close()
16231625

16241626
// Same output again!
1625-
require.NoError(t, testutil.ReadUntil(ctx, t, netConn3, matchEchoCommand), "find echo command")
1626-
require.NoError(t, testutil.ReadUntil(ctx, t, netConn3, matchEchoOutput), "find echo output")
1627+
tr3 := testutil.NewTerminalReader(t, netConn3)
1628+
require.NoError(t, tr3.ReadUntil(ctx, matchEchoCommand), "find echo command")
1629+
require.NoError(t, tr3.ReadUntil(ctx, matchEchoOutput), "find echo output")
16271630

16281631
// Exit should cause the connection to close.
16291632
data, err = json.Marshal(codersdk.ReconnectingPTYRequest{
@@ -1634,19 +1637,20 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
16341637
require.NoError(t, err)
16351638

16361639
// Once for the input and again for the output.
1637-
require.NoError(t, testutil.ReadUntil(ctx, t, netConn3, matchExitCommand), "find exit command")
1638-
require.NoError(t, testutil.ReadUntil(ctx, t, netConn3, matchExitOutput), "find exit output")
1640+
require.NoError(t, tr3.ReadUntil(ctx, matchExitCommand), "find exit command")
1641+
require.NoError(t, tr3.ReadUntil(ctx, matchExitOutput), "find exit output")
16391642

16401643
// Wait for the connection to close.
1641-
require.ErrorIs(t, testutil.ReadUntil(ctx, t, netConn3, nil), io.EOF)
1644+
require.ErrorIs(t, tr3.ReadUntil(ctx, nil), io.EOF)
16421645

16431646
// Try a non-shell command. It should output then immediately exit.
16441647
netConn4, err := conn.ReconnectingPTY(ctx, uuid.New(), 80, 80, "echo test")
16451648
require.NoError(t, err)
16461649
defer netConn4.Close()
16471650

1648-
require.NoError(t, testutil.ReadUntil(ctx, t, netConn4, matchEchoOutput), "find echo output")
1649-
require.ErrorIs(t, testutil.ReadUntil(ctx, t, netConn3, nil), io.EOF)
1651+
tr4 := testutil.NewTerminalReader(t, netConn4)
1652+
require.NoError(t, tr4.ReadUntil(ctx, matchEchoOutput), "find echo output")
1653+
require.ErrorIs(t, tr4.ReadUntil(ctx, nil), io.EOF)
16501654
})
16511655
}
16521656
}

cli/exp_scaletest_test.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77

88
"github.com/stretchr/testify/require"
99

10+
"cdr.dev/slog/sloggers/slogtest"
11+
1012
"github.com/coder/coder/v2/cli/clitest"
1113
"github.com/coder/coder/v2/coderd/coderdtest"
1214
"github.com/coder/coder/v2/pty/ptytest"
@@ -21,7 +23,12 @@ func TestScaleTestCreateWorkspaces(t *testing.T) {
2123
ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitLong)
2224
defer cancelFunc()
2325

24-
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
26+
log := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
27+
client := coderdtest.New(t, &coderdtest.Options{
28+
// We are not including any provisioner daemons because we do not actually
29+
// build any workspaces here.
30+
Logger: &log,
31+
})
2532
_ = coderdtest.CreateFirstUser(t, client)
2633

2734
// Write a parameters file.
@@ -59,7 +66,10 @@ func TestScaleTestWorkspaceTraffic(t *testing.T) {
5966
ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitMedium)
6067
defer cancelFunc()
6168

62-
client := coderdtest.New(t, nil)
69+
log := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
70+
client := coderdtest.New(t, &coderdtest.Options{
71+
Logger: &log,
72+
})
6373
_ = coderdtest.CreateFirstUser(t, client)
6474

6575
inv, root := clitest.New(t, "exp", "scaletest", "workspace-traffic",
@@ -82,21 +92,20 @@ func TestScaleTestWorkspaceTraffic(t *testing.T) {
8292
// This test just validates that the CLI command accepts its known arguments.
8393
func TestScaleTestDashboard(t *testing.T) {
8494
t.Parallel()
85-
if testutil.RaceEnabled() {
86-
t.Skip("Flakes under race detector, see https://github.com/coder/coder/issues/9168")
87-
}
88-
8995
ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitMedium)
9096
defer cancelFunc()
9197

92-
client := coderdtest.New(t, nil)
98+
log := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
99+
client := coderdtest.New(t, &coderdtest.Options{
100+
Logger: &log,
101+
})
93102
_ = coderdtest.CreateFirstUser(t, client)
94103

95104
inv, root := clitest.New(t, "exp", "scaletest", "dashboard",
96105
"--count", "1",
97106
"--min-wait", "100ms",
98107
"--max-wait", "1s",
99-
"--timeout", "1s",
108+
"--timeout", "5s",
100109
"--scaletest-prometheus-address", "127.0.0.1:0",
101110
"--scaletest-prometheus-wait", "0s",
102111
)

cli/login.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,7 @@ func (r *RootCmd) login() *clibase.Cmd {
278278
}
279279

280280
sessionToken, err = cliui.Prompt(inv, cliui.PromptOptions{
281-
Text: "Paste your token here:",
282-
Secret: true,
281+
Text: "Paste your token here:",
283282
Validate: func(token string) error {
284283
client.SetSessionToken(token)
285284
_, err := client.User(ctx, codersdk.Me)

cli/login_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cli_test
33
import (
44
"context"
55
"fmt"
6+
"runtime"
67
"testing"
78

89
"github.com/stretchr/testify/assert"
@@ -170,6 +171,10 @@ func TestLogin(t *testing.T) {
170171

171172
pty.ExpectMatch("Paste your token here:")
172173
pty.WriteLine(client.SessionToken())
174+
if runtime.GOOS != "windows" {
175+
// For some reason, the match does not show up on Windows.
176+
pty.ExpectMatch(client.SessionToken())
177+
}
173178
pty.ExpectMatch("Welcome to Coder")
174179
<-doneChan
175180
})
@@ -193,6 +198,10 @@ func TestLogin(t *testing.T) {
193198

194199
pty.ExpectMatch("Paste your token here:")
195200
pty.WriteLine("an-invalid-token")
201+
if runtime.GOOS != "windows" {
202+
// For some reason, the match does not show up on Windows.
203+
pty.ExpectMatch("an-invalid-token")
204+
}
196205
pty.ExpectMatch("That's not a valid token!")
197206
cancelFunc()
198207
<-doneChan

cli/portforward_test.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,20 @@ import (
77
"net"
88
"sync"
99
"testing"
10+
"time"
1011

1112
"github.com/google/uuid"
1213
"github.com/pion/udp"
1314
"github.com/stretchr/testify/assert"
1415
"github.com/stretchr/testify/require"
1516

17+
"cdr.dev/slog"
18+
"cdr.dev/slog/sloggers/slogtest"
19+
"github.com/coder/coder/v2/agent"
1620
"github.com/coder/coder/v2/cli/clitest"
1721
"github.com/coder/coder/v2/coderd/coderdtest"
1822
"github.com/coder/coder/v2/codersdk"
23+
"github.com/coder/coder/v2/codersdk/agentsdk"
1924
"github.com/coder/coder/v2/provisioner/echo"
2025
"github.com/coder/coder/v2/pty/ptytest"
2126
"github.com/coder/coder/v2/testutil"
@@ -312,24 +317,23 @@ func runAgent(t *testing.T, client *codersdk.Client, userID uuid.UUID) codersdk.
312317
workspace := coderdtest.CreateWorkspace(t, client, orgID, template.ID)
313318
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
314319

315-
// Start workspace agent in a goroutine
316-
inv, root := clitest.New(t, "agent", "--agent-token", agentToken, "--agent-url", client.URL.String())
317-
clitest.SetupConfig(t, client, root)
318-
pty := ptytest.New(t)
319-
inv.Stdin = pty.Input()
320-
inv.Stdout = pty.Output()
321-
inv.Stderr = pty.Output()
322-
errC := make(chan error)
323-
agentCtx, agentCancel := context.WithCancel(ctx)
320+
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug).Named("agent")
321+
agentClient := agentsdk.New(client.URL)
322+
agentClient.SDK.SetLogger(logger)
323+
agentClient.SDK.SetSessionToken(agentToken)
324+
agnt := agent.New(agent.Options{
325+
Client: agentClient,
326+
Logger: logger,
327+
LogDir: t.TempDir(),
328+
ExchangeToken: func(ctx context.Context) (string, error) {
329+
return agentToken, nil
330+
},
331+
SSHMaxTimeout: time.Second * 60,
332+
})
324333
t.Cleanup(func() {
325-
agentCancel()
326-
err := <-errC
327-
require.NoError(t, err)
334+
err := agnt.Close()
335+
assert.NoError(t, err)
328336
})
329-
go func() {
330-
errC <- inv.WithContext(agentCtx).Run()
331-
}()
332-
333337
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
334338

335339
return workspace

cli/root_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ func TestDERPHeaders(t *testing.T) {
170170

171171
// Connect with the headers set as args.
172172
args := []string{
173+
"-v",
173174
"--no-feature-warning",
174175
"--no-version-warning",
175176
"ping", workspace.Name,

cli/server.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,8 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
10121012

10131013
autobuildTicker := time.NewTicker(vals.AutobuildPollInterval.Value())
10141014
defer autobuildTicker.Stop()
1015-
autobuildExecutor := autobuild.NewExecutor(ctx, options.Database, coderAPI.TemplateScheduleStore, logger, autobuildTicker.C)
1015+
autobuildExecutor := autobuild.NewExecutor(
1016+
ctx, options.Database, options.Pubsub, coderAPI.TemplateScheduleStore, logger, autobuildTicker.C)
10161017
autobuildExecutor.Run()
10171018

10181019
hangDetectorTicker := time.NewTicker(vals.JobHangDetectorInterval.Value())
@@ -1378,16 +1379,12 @@ func newProvisionerDaemon(
13781379
connector[string(database.ProvisionerTypeTerraform)] = sdkproto.NewDRPCProvisionerClient(terraformClient)
13791380
}
13801381

1381-
debounce := time.Second
13821382
return provisionerd.New(func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error) {
13831383
// This debounces calls to listen every second. Read the comment
13841384
// in provisionerdserver.go to learn more!
1385-
return coderAPI.CreateInMemoryProvisionerDaemon(ctx, debounce)
1385+
return coderAPI.CreateInMemoryProvisionerDaemon(ctx)
13861386
}, &provisionerd.Options{
13871387
Logger: logger.Named("provisionerd"),
1388-
JobPollInterval: cfg.Provisioner.DaemonPollInterval.Value(),
1389-
JobPollJitter: cfg.Provisioner.DaemonPollJitter.Value(),
1390-
JobPollDebounce: debounce,
13911388
UpdateInterval: time.Second,
13921389
ForceCancelInterval: cfg.Provisioner.ForceCancelInterval.Value(),
13931390
Connector: connector,

cli/testdata/coder_server_--help.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,10 @@ updating, and deleting workspace resources.
393393
Time to force cancel provisioning tasks that are stuck.
394394

395395
--provisioner-daemon-poll-interval duration, $CODER_PROVISIONER_DAEMON_POLL_INTERVAL (default: 1s)
396-
Time to wait before polling for a new job.
396+
Deprecated and ignored.
397397

398398
--provisioner-daemon-poll-jitter duration, $CODER_PROVISIONER_DAEMON_POLL_JITTER (default: 100ms)
399-
Random jitter added to the poll interval.
399+
Deprecated and ignored.
400400

401401
--provisioner-daemon-psk string, $CODER_PROVISIONER_DAEMON_PSK
402402
Pre-shared key to authenticate external provisioner daemons to Coder

cli/testdata/coder_templates_init_--help.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ USAGE:
66
Get started with a templated template.
77

88
OPTIONS:
9-
--id aws-ecs-container|aws-linux|aws-windows|azure-linux|do-linux|docker|docker-with-dotfiles|gcp-linux|gcp-vm-container|gcp-windows|kubernetes
9+
--id aws-ecs-container|aws-linux|aws-windows|azure-linux|do-linux|docker|docker-with-dotfiles|gcp-linux|gcp-vm-container|gcp-windows|kubernetes|nomad-docker
1010
Specify a given example template by ID.
1111

1212
———

cli/testdata/server-config.yaml.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,10 @@ provisioning:
348348
# tests.
349349
# (default: false, type: bool)
350350
daemonsEcho: false
351-
# Time to wait before polling for a new job.
351+
# Deprecated and ignored.
352352
# (default: 1s, type: duration)
353353
daemonPollInterval: 1s
354-
# Random jitter added to the poll interval.
354+
# Deprecated and ignored.
355355
# (default: 100ms, type: duration)
356356
daemonPollJitter: 100ms
357357
# Time to force cancel provisioning tasks that are stuck.

0 commit comments

Comments
 (0)