Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit342b03d

Browse files
committed
Fix requested changes
1 parent9ad326b commit342b03d

File tree

7 files changed

+75
-13
lines changed

7 files changed

+75
-13
lines changed

‎cli/cliui/agent.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cliui
33
import (
44
"context"
55
"fmt"
6+
"sync"
67
"time"
78

89
"github.com/briandowns/spinner"
@@ -19,13 +20,15 @@ type AgentOptions struct {
1920
WarnInterval time.Duration
2021
}
2122

23+
// Agent displays a spinning indicator that waits for a workspace agent to connect.
2224
funcAgent(cmd*cobra.Command,optsAgentOptions)error {
2325
ifopts.FetchInterval==0 {
2426
opts.FetchInterval=500*time.Millisecond
2527
}
2628
ifopts.WarnInterval==0 {
2729
opts.WarnInterval=30*time.Second
2830
}
31+
varresourceMutex sync.Mutex
2932
resource,err:=opts.Fetch(cmd.Context())
3033
iferr!=nil {
3134
returnxerrors.Errorf("fetch: %w",err)
@@ -52,6 +55,8 @@ func Agent(cmd *cobra.Command, opts AgentOptions) error {
5255
return
5356
case<-timer.C:
5457
}
58+
resourceMutex.Lock()
59+
deferresourceMutex.Unlock()
5560
message:="Don't panic, your workspace is booting up!"
5661
ifresource.Agent.Status==codersdk.WorkspaceAgentDisconnected {
5762
message="The workspace agent lost connection! Wait for it to reconnect or run: "+Styles.Code.Render("coder workspaces rebuild "+opts.WorkspaceName)
@@ -67,13 +72,16 @@ func Agent(cmd *cobra.Command, opts AgentOptions) error {
6772
returncmd.Context().Err()
6873
case<-ticker.C:
6974
}
75+
resourceMutex.Lock()
7076
resource,err=opts.Fetch(cmd.Context())
7177
iferr!=nil {
7278
returnxerrors.Errorf("fetch: %w",err)
7379
}
7480
ifresource.Agent.Status!=codersdk.WorkspaceAgentConnected {
81+
resourceMutex.Unlock()
7582
continue
7683
}
84+
resourceMutex.Unlock()
7785
returnnil
7886
}
7987
}

‎cli/cliui/agent_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package cliui_test
2+
3+
import (
4+
"context"
5+
"testing"
6+
"time"
7+
8+
"github.com/spf13/cobra"
9+
"github.com/stretchr/testify/require"
10+
"go.uber.org/atomic"
11+
12+
"github.com/coder/coder/cli/cliui"
13+
"github.com/coder/coder/codersdk"
14+
"github.com/coder/coder/pty/ptytest"
15+
)
16+
17+
funcTestAgent(t*testing.T) {
18+
t.Parallel()
19+
vardisconnected atomic.Bool
20+
ptty:=ptytest.New(t)
21+
cmd:=&cobra.Command{
22+
RunE:func(cmd*cobra.Command,args []string)error {
23+
err:=cliui.Agent(cmd, cliui.AgentOptions{
24+
WorkspaceName:"example",
25+
Fetch:func(ctx context.Context) (codersdk.WorkspaceResource,error) {
26+
resource:= codersdk.WorkspaceResource{
27+
Agent:&codersdk.WorkspaceAgent{
28+
Status:codersdk.WorkspaceAgentDisconnected,
29+
},
30+
}
31+
ifdisconnected.Load() {
32+
resource.Agent.Status=codersdk.WorkspaceAgentConnected
33+
}
34+
returnresource,nil
35+
},
36+
FetchInterval:time.Millisecond,
37+
WarnInterval:10*time.Millisecond,
38+
})
39+
returnerr
40+
},
41+
}
42+
cmd.SetOutput(ptty.Output())
43+
cmd.SetIn(ptty.Input())
44+
done:=make(chanstruct{})
45+
gofunc() {
46+
deferclose(done)
47+
err:=cmd.Execute()
48+
require.NoError(t,err)
49+
}()
50+
ptty.ExpectMatch("lost connection")
51+
disconnected.Store(true)
52+
<-done
53+
}

‎cli/start.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@ import (
1616
"path/filepath"
1717
"time"
1818

19+
"github.com/briandowns/spinner"
20+
"github.com/coreos/go-systemd/daemon"
21+
"github.com/spf13/cobra"
22+
"golang.org/x/xerrors"
23+
"google.golang.org/api/idtoken"
24+
"google.golang.org/api/option"
25+
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
26+
1927
"cdr.dev/slog"
2028
"cdr.dev/slog/sloggers/sloghuman"
21-
"github.com/briandowns/spinner"
2229
"github.com/coder/coder/cli/cliflag"
2330
"github.com/coder/coder/cli/cliui"
2431
"github.com/coder/coder/cli/config"
@@ -31,12 +38,6 @@ import (
3138
"github.com/coder/coder/provisionerd"
3239
"github.com/coder/coder/provisionersdk"
3340
"github.com/coder/coder/provisionersdk/proto"
34-
"github.com/coreos/go-systemd/daemon"
35-
"github.com/spf13/cobra"
36-
"golang.org/x/xerrors"
37-
"google.golang.org/api/idtoken"
38-
"google.golang.org/api/option"
39-
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
4041
)
4142

4243
funcstart()*cobra.Command {

‎coderd/coderd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import (
99
"github.com/go-chi/chi/v5"
1010
"google.golang.org/api/idtoken"
1111

12+
chitrace"gopkg.in/DataDog/dd-trace-go.v1/contrib/go-chi/chi.v5"
13+
1214
"cdr.dev/slog"
1315
"github.com/coder/coder/coderd/awsidentity"
1416
"github.com/coder/coder/coderd/database"
1517
"github.com/coder/coder/coderd/httpapi"
1618
"github.com/coder/coder/coderd/httpmw"
1719
"github.com/coder/coder/site"
18-
chitrace"gopkg.in/DataDog/dd-trace-go.v1/contrib/go-chi/chi.v5"
1920
)
2021

2122
// Options are requires parameters for Coder to start.

‎coderd/coderdtest/coderdtest.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ func AwaitWorkspaceAgents(t *testing.T, client *codersdk.Client, build uuid.UUID
258258
ifresource.Agent==nil {
259259
continue
260260
}
261-
// fmt.Printf("resources: %+v\n", resource.Agent)
262261
ifresource.Agent.FirstConnectedAt==nil {
263262
returnfalse
264263
}

‎examples/gcp-linux/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ terraform {
88
}
99

1010
variable"service_account" {
11-
description=<<EOT
11+
description=<<EOF
1212
Coder requires a Google Cloud Service Account to provision workspaces.
1313
1414
1. Create a service account:
@@ -19,7 +19,7 @@ Coder requires a Google Cloud Service Account to provision workspaces.
1919
3. Click on the created key, and navigate to the "Keys" tab.
2020
4. Click "Add key", then "Create new key".
2121
5. Generate a JSON private key, and paste the contents in \'\' quotes below.
22-
EOT
22+
EOF
2323
sensitive=true
2424
}
2525

‎examples/gcp-windows/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ terraform {
88
}
99

1010
variable"service_account" {
11-
description=<<EOT
11+
description=<<EOF
1212
Coder requires a Google Cloud Service Account to provision workspaces.
1313
1414
1. Create a service account:
@@ -19,7 +19,7 @@ Coder requires a Google Cloud Service Account to provision workspaces.
1919
3. Click on the created key, and navigate to the "Keys" tab.
2020
4. Click "Add key", then "Create new key".
2121
5. Generate a JSON private key, and paste the contents in \'\' quotes below.
22-
EOT
22+
EOF
2323
sensitive=true
2424
}
2525

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp