Skip to content

Commit 52b87a2

Browse files
authored
fix: stop printing warnings on external provisioner daemon command (coder#11309)
fixes coder#11307
1 parent db9104c commit 52b87a2

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

cli/root.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,11 @@ func addTelemetryHeader(client *codersdk.Client, inv *clibase.Invocation) {
515515
// InitClient sets client to a new client.
516516
// It reads from global configuration files if flags are not set.
517517
func (r *RootCmd) InitClient(client *codersdk.Client) clibase.MiddlewareFunc {
518-
return r.initClientInternal(client, false)
518+
return clibase.Chain(
519+
r.initClientInternal(client, false),
520+
// By default, we should print warnings in addition to initializing the client
521+
r.PrintWarnings(client),
522+
)
519523
}
520524

521525
func (r *RootCmd) InitClientMissingTokenOK(client *codersdk.Client) clibase.MiddlewareFunc {
@@ -575,7 +579,20 @@ func (r *RootCmd) initClientInternal(client *codersdk.Client, allowTokenMissing
575579
client.SetLogBodies(true)
576580
}
577581
client.DisableDirectConnections = r.disableDirect
582+
return next(inv)
583+
}
584+
}
585+
}
578586

587+
func (r *RootCmd) PrintWarnings(client *codersdk.Client) clibase.MiddlewareFunc {
588+
if client == nil {
589+
panic("client is nil")
590+
}
591+
if r == nil {
592+
panic("root is nil")
593+
}
594+
return func(next clibase.HandlerFunc) clibase.HandlerFunc {
595+
return func(inv *clibase.Invocation) error {
579596
// We send these requests in parallel to minimize latency.
580597
var (
581598
versionErr = make(chan error)
@@ -591,14 +608,14 @@ func (r *RootCmd) initClientInternal(client *codersdk.Client, allowTokenMissing
591608
close(warningErr)
592609
}()
593610

594-
if err = <-versionErr; err != nil {
611+
if err := <-versionErr; err != nil {
595612
// Just log the error here. We never want to fail a command
596613
// due to a pre-run.
597614
pretty.Fprintf(inv.Stderr, cliui.DefaultStyles.Warn, "check versions error: %s", err)
598615
_, _ = fmt.Fprintln(inv.Stderr)
599616
}
600617

601-
if err = <-warningErr; err != nil {
618+
if err := <-warningErr; err != nil {
602619
// Same as above
603620
pretty.Fprintf(inv.Stderr, cliui.DefaultStyles.Warn, "check entitlement warnings error: %s", err)
604621
_, _ = fmt.Fprintln(inv.Stderr)

enterprise/cli/provisionerdaemons.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ func (r *RootCmd) provisionerDaemonStart() *clibase.Cmd {
7373
Use: "start",
7474
Short: "Run a provisioner daemon",
7575
Middleware: clibase.Chain(
76+
// disable checks and warnings because this command starts a daemon; it is
77+
// not meant for humans typing commands. Furthermore, the checks are
78+
// incompatible with PSK auth that this command uses
7679
r.InitClientMissingTokenOK(client),
7780
),
7881
Handler: func(inv *clibase.Invocation) error {

enterprise/cli/provisionerdaemons_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestProvisionerDaemon_PSK(t *testing.T) {
3636
ctx, cancel := context.WithTimeout(inv.Context(), testutil.WaitLong)
3737
defer cancel()
3838
clitest.Start(t, inv)
39-
pty.ExpectMatchContext(ctx, "starting provisioner daemon")
39+
pty.ExpectNoMatchBefore(ctx, "check entitlement", "starting provisioner daemon")
4040
pty.ExpectMatchContext(ctx, "matt-daemon")
4141

4242
var daemons []codersdk.ProvisionerDaemon

0 commit comments

Comments
 (0)