Skip to content

Commit bb4a681

Browse files
authored
fix: don't check buildinfo or entitlements in agent (coder#3956)
1 parent 6a3876d commit bb4a681

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

cli/root.go

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli
22

33
import (
4+
"context"
45
"flag"
56
"fmt"
67
"net/url"
@@ -110,10 +111,17 @@ func Root(subcommands []*cobra.Command) *cobra.Command {
110111
return
111112
}
112113

113-
// Login handles checking the versions itself since it
114-
// has a handle to an unauthenticated client.
115-
// Server is skipped for obvious reasons.
116-
if cmd.Name() == "login" || cmd.Name() == "server" || cmd.Name() == "gitssh" {
114+
// login handles checking the versions itself since it has a handle
115+
// to an unauthenticated client.
116+
//
117+
// server is skipped for obvious reasons.
118+
//
119+
// agent is skipped because these checks use the global coder config
120+
// and not the agent URL and token from the environment.
121+
//
122+
// gitssh is skipped because it's usually not called by users
123+
// directly.
124+
if cmd.Name() == "login" || cmd.Name() == "server" || cmd.Name() == "agent" || cmd.Name() == "gitssh" {
117125
return
118126
}
119127

@@ -123,6 +131,7 @@ func Root(subcommands []*cobra.Command) *cobra.Command {
123131
if err != nil {
124132
return
125133
}
134+
126135
err = checkVersions(cmd, client)
127136
if err != nil {
128137
// Just log the error here. We never want to fail a command
@@ -131,7 +140,14 @@ func Root(subcommands []*cobra.Command) *cobra.Command {
131140
cliui.Styles.Warn.Render("check versions error: %s"), err)
132141
_, _ = fmt.Fprintln(cmd.ErrOrStderr())
133142
}
134-
checkWarnings(cmd, client)
143+
144+
err = checkWarnings(cmd, client)
145+
if err != nil {
146+
// Same as above
147+
_, _ = fmt.Fprintf(cmd.ErrOrStderr(),
148+
cliui.Styles.Warn.Render("check entitlement warnings error: %s"), err)
149+
_, _ = fmt.Fprintln(cmd.ErrOrStderr())
150+
}
135151
},
136152
Example: formatExamples(
137153
example{
@@ -468,9 +484,11 @@ func checkVersions(cmd *cobra.Command, client *codersdk.Client) error {
468484
return nil
469485
}
470486

471-
clientVersion := buildinfo.Version()
487+
ctx, cancel := context.WithTimeout(cmd.Context(), 10*time.Second)
488+
defer cancel()
472489

473-
info, err := client.BuildInfo(cmd.Context())
490+
clientVersion := buildinfo.Version()
491+
info, err := client.BuildInfo(ctx)
474492
// Avoid printing errors that are connection-related.
475493
if codersdk.IsConnectionErr(err) {
476494
return nil
@@ -494,15 +512,21 @@ download the server version with: 'curl -L https://coder.com/install.sh | sh -s
494512
return nil
495513
}
496514

497-
func checkWarnings(cmd *cobra.Command, client *codersdk.Client) {
515+
func checkWarnings(cmd *cobra.Command, client *codersdk.Client) error {
498516
if cliflag.IsSetBool(cmd, varNoFeatureWarning) {
499-
return
517+
return nil
500518
}
501-
entitlements, err := client.Entitlements(cmd.Context())
519+
520+
ctx, cancel := context.WithTimeout(cmd.Context(), 10*time.Second)
521+
defer cancel()
522+
523+
entitlements, err := client.Entitlements(ctx)
502524
if err != nil {
503-
return
525+
return xerrors.Errorf("get entitlements to show warnings: %w", err)
504526
}
505527
for _, w := range entitlements.Warnings {
506528
_, _ = fmt.Fprintln(cmd.ErrOrStderr(), cliui.Styles.Warn.Render(w))
507529
}
530+
531+
return nil
508532
}

0 commit comments

Comments
 (0)