Skip to content

Commit 5dff164

Browse files
committed
fix: fix error output of cli action tracker
Before we started a reboot/shutdown/reset/upgrade action with the action tracker (`--wait`), we were setting a flag to prevent cobra from printing the returned error from the command. This was to prevent the error from being printed twice, as the reporter of the action tracker already prints any errors occurred during the action execution. But if the error happens too early - i.e. before we even started the status printer goroutine, then that error wouldn't be printed at all, as we have suppressed the errors. This PR moves the suppression flag to be set after the status printer is started - so we still do not double-print the errors, but neither do we suppress any early-stage error from being printed. Closes #7900. Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com>
1 parent ef50561 commit 5dff164

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
lines changed

cmd/talosctl/cmd/talos/reboot.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
"github.com/spf13/cobra"
1212

13-
"github.com/siderolabs/talos/cmd/talosctl/cmd/common"
1413
"github.com/siderolabs/talos/cmd/talosctl/pkg/talos/action"
1514
"github.com/siderolabs/talos/cmd/talosctl/pkg/talos/helpers"
1615
"github.com/siderolabs/talos/pkg/machinery/client"
@@ -57,8 +56,6 @@ var rebootCmd = &cobra.Command{
5756
})
5857
}
5958

60-
common.SuppressErrors = true
61-
6259
return action.NewTracker(
6360
&GlobalArgs,
6461
action.MachineReadyEventFn,

cmd/talosctl/cmd/talos/reset.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/siderolabs/gen/maps"
1414
"github.com/spf13/cobra"
1515

16-
"github.com/siderolabs/talos/cmd/talosctl/cmd/common"
1716
"github.com/siderolabs/talos/cmd/talosctl/pkg/talos/action"
1817
"github.com/siderolabs/talos/cmd/talosctl/pkg/talos/helpers"
1918
machineapi "github.com/siderolabs/talos/pkg/machinery/api/machine"
@@ -140,8 +139,6 @@ var resetCmd = &cobra.Command{
140139
}
141140
}
142141

143-
common.SuppressErrors = true
144-
145142
return action.NewTracker(
146143
&GlobalArgs,
147144
action.StopAllServicesEventFn,

cmd/talosctl/cmd/talos/shutdown.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
"github.com/spf13/cobra"
1212

13-
"github.com/siderolabs/talos/cmd/talosctl/cmd/common"
1413
"github.com/siderolabs/talos/cmd/talosctl/pkg/talos/action"
1514
"github.com/siderolabs/talos/cmd/talosctl/pkg/talos/helpers"
1615
"github.com/siderolabs/talos/pkg/machinery/client"
@@ -50,8 +49,6 @@ var shutdownCmd = &cobra.Command{
5049
})
5150
}
5251

53-
common.SuppressErrors = true
54-
5552
return action.NewTracker(
5653
&GlobalArgs,
5754
action.StopAllServicesEventFn,

cmd/talosctl/cmd/talos/upgrade.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"google.golang.org/grpc"
2020
"google.golang.org/grpc/peer"
2121

22-
"github.com/siderolabs/talos/cmd/talosctl/cmd/common"
2322
"github.com/siderolabs/talos/cmd/talosctl/pkg/talos/action"
2423
"github.com/siderolabs/talos/cmd/talosctl/pkg/talos/helpers"
2524
"github.com/siderolabs/talos/pkg/cli"
@@ -73,8 +72,6 @@ var upgradeCmd = &cobra.Command{
7372
return runUpgradeNoWait(opts)
7473
}
7574

76-
common.SuppressErrors = true
77-
7875
return action.NewTracker(
7976
&GlobalArgs,
8077
action.MachineReadyEventFn,

cmd/talosctl/pkg/talos/action/tracker.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"google.golang.org/grpc"
2424
"google.golang.org/grpc/backoff"
2525

26+
"github.com/siderolabs/talos/cmd/talosctl/cmd/common"
2627
"github.com/siderolabs/talos/cmd/talosctl/pkg/talos/global"
2728
"github.com/siderolabs/talos/cmd/talosctl/pkg/talos/helpers"
2829
machineapi "github.com/siderolabs/talos/pkg/machinery/api/machine"
@@ -155,6 +156,10 @@ func (a *Tracker) Run() error {
155156
return a.runReporter(ctx)
156157
})
157158

159+
// Reporter is started, it will print the errors if there is any.
160+
// So from here on we can suppress the command error to be printed to avoid it being printed twice.
161+
common.SuppressErrors = true
162+
158163
var trackEg errgroup.Group
159164

160165
for _, node := range a.cliContext.Nodes {

internal/integration/cli/reboot.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package cli
99

1010
import (
1111
"fmt"
12+
"path/filepath"
1213
"strings"
1314
"testing"
1415

@@ -82,6 +83,32 @@ func (suite *RebootSuite) TestReboot() {
8283
)
8384
}
8485

86+
// TestRebootEarlyFailPrintsOutput tests the action tracker used by reboot command to track reboot status
87+
// does not suppress the stderr output if there is an error occurring at an early stage, i.e. before the
88+
// action status reporting starts.
89+
func (suite *RebootSuite) TestRebootEarlyFailPrintsOutput() {
90+
controlPlaneNode := suite.RandomDiscoveredNodeInternalIP(machine.TypeControlPlane)
91+
invalidTalosconfig := filepath.Join(suite.T().TempDir(), "talosconfig.yaml")
92+
93+
suite.T().Logf("attempting to reboot node %q using talosconfig %q", controlPlaneNode, invalidTalosconfig)
94+
95+
suite.RunCLI([]string{"--talosconfig", invalidTalosconfig, "reboot", "-n", controlPlaneNode},
96+
base.ShouldFail(),
97+
base.StdoutEmpty(),
98+
base.StderrNotEmpty(),
99+
base.StderrMatchFunc(func(stdout string) error {
100+
if strings.Contains(stdout, "method is not supported") {
101+
suite.T().Skip("reboot is not supported")
102+
}
103+
104+
if !strings.Contains(stdout, "failed to determine endpoints") {
105+
return fmt.Errorf("expected to find 'failed to determine endpoints' in stderr")
106+
}
107+
108+
return nil
109+
}))
110+
}
111+
85112
func init() {
86113
allSuites = append(allSuites, new(RebootSuite))
87114
}

0 commit comments

Comments
 (0)