Skip to content

Commit 7e15671

Browse files
committed
Merge branch 'main' into workspace-searchbar-storage
2 parents 391648a + 1fd1c65 commit 7e15671

File tree

113 files changed

+4094
-2913
lines changed

Some content is hidden

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

113 files changed

+4094
-2913
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
@@ -1669,13 +1669,15 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
16691669
}
16701670

16711671
// Once for typing the command...
1672-
require.NoError(t, testutil.ReadUntil(ctx, t, netConn1, matchEchoCommand), "find echo command")
1672+
tr1 := testutil.NewTerminalReader(t, netConn1)
1673+
require.NoError(t, tr1.ReadUntil(ctx, matchEchoCommand), "find echo command")
16731674
// And another time for the actual output.
1674-
require.NoError(t, testutil.ReadUntil(ctx, t, netConn1, matchEchoOutput), "find echo output")
1675+
require.NoError(t, tr1.ReadUntil(ctx, matchEchoOutput), "find echo output")
16751676

16761677
// Same for the other connection.
1677-
require.NoError(t, testutil.ReadUntil(ctx, t, netConn2, matchEchoCommand), "find echo command")
1678-
require.NoError(t, testutil.ReadUntil(ctx, t, netConn2, matchEchoOutput), "find echo output")
1678+
tr2 := testutil.NewTerminalReader(t, netConn2)
1679+
require.NoError(t, tr2.ReadUntil(ctx, matchEchoCommand), "find echo command")
1680+
require.NoError(t, tr2.ReadUntil(ctx, matchEchoOutput), "find echo output")
16791681

16801682
_ = netConn1.Close()
16811683
_ = netConn2.Close()
@@ -1684,8 +1686,9 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
16841686
defer netConn3.Close()
16851687

16861688
// Same output again!
1687-
require.NoError(t, testutil.ReadUntil(ctx, t, netConn3, matchEchoCommand), "find echo command")
1688-
require.NoError(t, testutil.ReadUntil(ctx, t, netConn3, matchEchoOutput), "find echo output")
1689+
tr3 := testutil.NewTerminalReader(t, netConn3)
1690+
require.NoError(t, tr3.ReadUntil(ctx, matchEchoCommand), "find echo command")
1691+
require.NoError(t, tr3.ReadUntil(ctx, matchEchoOutput), "find echo output")
16891692

16901693
// Exit should cause the connection to close.
16911694
data, err = json.Marshal(codersdk.ReconnectingPTYRequest{
@@ -1696,19 +1699,20 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
16961699
require.NoError(t, err)
16971700

16981701
// Once for the input and again for the output.
1699-
require.NoError(t, testutil.ReadUntil(ctx, t, netConn3, matchExitCommand), "find exit command")
1700-
require.NoError(t, testutil.ReadUntil(ctx, t, netConn3, matchExitOutput), "find exit output")
1702+
require.NoError(t, tr3.ReadUntil(ctx, matchExitCommand), "find exit command")
1703+
require.NoError(t, tr3.ReadUntil(ctx, matchExitOutput), "find exit output")
17011704

17021705
// Wait for the connection to close.
1703-
require.ErrorIs(t, testutil.ReadUntil(ctx, t, netConn3, nil), io.EOF)
1706+
require.ErrorIs(t, tr3.ReadUntil(ctx, nil), io.EOF)
17041707

17051708
// Try a non-shell command. It should output then immediately exit.
17061709
netConn4, err := conn.ReconnectingPTY(ctx, uuid.New(), 80, 80, "echo test")
17071710
require.NoError(t, err)
17081711
defer netConn4.Close()
17091712

1710-
require.NoError(t, testutil.ReadUntil(ctx, t, netConn4, matchEchoOutput), "find echo output")
1711-
require.ErrorIs(t, testutil.ReadUntil(ctx, t, netConn3, nil), io.EOF)
1713+
tr4 := testutil.NewTerminalReader(t, netConn4)
1714+
require.NoError(t, tr4.ReadUntil(ctx, matchEchoOutput), "find echo output")
1715+
require.ErrorIs(t, tr4.ReadUntil(ctx, nil), io.EOF)
17121716
})
17131717
}
17141718
}

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/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/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.

cli/update_test.go

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -578,13 +578,15 @@ func TestUpdateValidateRichParameters(t *testing.T) {
578578
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
579579
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
580580

581+
// Create new workspace
581582
inv, root := clitest.New(t, "create", "my-workspace", "--yes", "--template", template.Name, "--parameter", fmt.Sprintf("%s=%s", stringParameterName, "2nd"))
582583
clitest.SetupConfig(t, client, root)
583584
err := inv.Run()
584585
require.NoError(t, err)
585586

586587
// Update template
587588
updatedTemplateParameters := []*proto.RichParameter{
589+
// The order of rich parameter options must be maintained because `cliui.Select` automatically selects the first option during tests.
588590
{Name: stringParameterName, Type: "string", Mutable: true, Required: true, Options: []*proto.RichParameterOption{
589591
{Name: "first_option", Description: "This is first option", Value: "1"},
590592
{Name: "second_option", Description: "This is second option", Value: "2"},
@@ -602,12 +604,16 @@ func TestUpdateValidateRichParameters(t *testing.T) {
602604
// Update the workspace
603605
inv, root = clitest.New(t, "update", "my-workspace")
604606
clitest.SetupConfig(t, client, root)
605-
607+
doneChan := make(chan struct{})
606608
pty := ptytest.New(t).Attach(inv)
607-
clitest.Start(t, inv)
609+
go func() {
610+
defer close(doneChan)
611+
err := inv.Run()
612+
assert.NoError(t, err)
613+
}()
608614

609615
matches := []string{
610-
stringParameterName, "second_option",
616+
// `cliui.Select` will automatically pick the first option
611617
"Planning workspace...", "",
612618
}
613619
for i := 0; i < len(matches); i += 2 {
@@ -619,6 +625,8 @@ func TestUpdateValidateRichParameters(t *testing.T) {
619625
pty.WriteLine(value)
620626
}
621627
}
628+
629+
<-doneChan
622630
})
623631

624632
t.Run("ParameterOptionDisappeared", func(t *testing.T) {
@@ -639,16 +647,19 @@ func TestUpdateValidateRichParameters(t *testing.T) {
639647
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
640648
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
641649

650+
// Create new workspace
642651
inv, root := clitest.New(t, "create", "my-workspace", "--yes", "--template", template.Name, "--parameter", fmt.Sprintf("%s=%s", stringParameterName, "2nd"))
643652
clitest.SetupConfig(t, client, root)
653+
ptytest.New(t).Attach(inv)
644654
err := inv.Run()
645655
require.NoError(t, err)
646656

647657
// Update template - 2nd option disappeared, 4th option added
648658
updatedTemplateParameters := []*proto.RichParameter{
659+
// The order of rich parameter options must be maintained because `cliui.Select` automatically selects the first option during tests.
649660
{Name: stringParameterName, Type: "string", Mutable: true, Required: true, Options: []*proto.RichParameterOption{
650-
{Name: "First option", Description: "This is first option", Value: "1st"},
651661
{Name: "Third option", Description: "This is third option", Value: "3rd"},
662+
{Name: "First option", Description: "This is first option", Value: "1st"},
652663
{Name: "Fourth option", Description: "This is fourth option", Value: "4th"},
653664
}},
654665
}
@@ -663,11 +674,16 @@ func TestUpdateValidateRichParameters(t *testing.T) {
663674
// Update the workspace
664675
inv, root = clitest.New(t, "update", "my-workspace")
665676
clitest.SetupConfig(t, client, root)
677+
doneChan := make(chan struct{})
666678
pty := ptytest.New(t).Attach(inv)
667-
clitest.Start(t, inv)
679+
go func() {
680+
defer close(doneChan)
681+
err := inv.Run()
682+
assert.NoError(t, err)
683+
}()
668684

669685
matches := []string{
670-
stringParameterName, "Third option",
686+
// `cliui.Select` will automatically pick the first option
671687
"Planning workspace...", "",
672688
}
673689
for i := 0; i < len(matches); i += 2 {
@@ -679,6 +695,8 @@ func TestUpdateValidateRichParameters(t *testing.T) {
679695
pty.WriteLine(value)
680696
}
681697
}
698+
699+
<-doneChan
682700
})
683701

684702
t.Run("ImmutableRequiredParameterExists_MutableRequiredParameterAdded", func(t *testing.T) {
@@ -742,6 +760,7 @@ func TestUpdateValidateRichParameters(t *testing.T) {
742760
pty.WriteLine(value)
743761
}
744762
}
763+
745764
<-doneChan
746765
})
747766

@@ -771,10 +790,11 @@ func TestUpdateValidateRichParameters(t *testing.T) {
771790
// Update template: add required, immutable parameter
772791
updatedTemplateParameters := []*proto.RichParameter{
773792
templateParameters[0],
793+
// The order of rich parameter options must be maintained because `cliui.Select` automatically selects the first option during tests.
774794
{Name: immutableParameterName, Type: "string", Mutable: false, Required: true, Options: []*proto.RichParameterOption{
795+
{Name: "thi", Description: "This is third option for immutable parameter", Value: "III"},
775796
{Name: "fir", Description: "This is first option for immutable parameter", Value: "I"},
776797
{Name: "sec", Description: "This is second option for immutable parameter", Value: "II"},
777-
{Name: "thi", Description: "This is third option for immutable parameter", Value: "III"},
778798
}},
779799
}
780800

@@ -797,7 +817,7 @@ func TestUpdateValidateRichParameters(t *testing.T) {
797817
}()
798818

799819
matches := []string{
800-
immutableParameterName, "thi",
820+
// `cliui.Select` will automatically pick the first option
801821
"Planning workspace...", "",
802822
}
803823
for i := 0; i < len(matches); i += 2 {
@@ -809,6 +829,7 @@ func TestUpdateValidateRichParameters(t *testing.T) {
809829
pty.WriteLine(value)
810830
}
811831
}
832+
812833
<-doneChan
813834
})
814835
}

coderd/activitybump_internal_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
134134
TemplateID: template.ID,
135135
Ttl: sql.NullInt64{Valid: true, Int64: int64(tt.workspaceTTL)},
136136
})
137-
job = dbgen.ProvisionerJob(t, db, database.ProvisionerJob{
137+
job = dbgen.ProvisionerJob(t, db, nil, database.ProvisionerJob{
138138
OrganizationID: org.ID,
139139
CompletedAt: tt.jobCompletedAt,
140140
})
@@ -225,7 +225,7 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
225225
func insertPrevWorkspaceBuild(t *testing.T, db database.Store, orgID, tvID, workspaceID uuid.UUID, transition database.WorkspaceTransition, buildNumber int32) {
226226
t.Helper()
227227

228-
job := dbgen.ProvisionerJob(t, db, database.ProvisionerJob{
228+
job := dbgen.ProvisionerJob(t, db, nil, database.ProvisionerJob{
229229
OrganizationID: orgID,
230230
})
231231
_ = dbgen.WorkspaceResource(t, db, database.WorkspaceResource{

coderd/apidoc/docs.go

Lines changed: 10 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 11 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)