Skip to content

Commit 4ce96c0

Browse files
authored
[VC-35738] Append errgroup errors to the error returned by Agent.Run (#606)
* Append errgroup errors to Run return error * Fail TestRunOneShot if Run returns errors
1 parent 61d64e4 commit 4ce96c0

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

pkg/agent/run.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var Flags AgentCmdFlags
5050
const schemaVersion string = "v2.0.0"
5151

5252
// Run starts the agent process
53-
func Run(cmd *cobra.Command, args []string) error {
53+
func Run(cmd *cobra.Command, args []string) (returnErr error) {
5454
logs.Log.Printf("Preflight agent version: %s (%s)", version.PreflightVersion, version.Commit)
5555
ctx, cancel := context.WithCancel(
5656
klog.NewContext(
@@ -85,8 +85,8 @@ func Run(cmd *cobra.Command, args []string) error {
8585
defer func() {
8686
cancel()
8787
if groupErr := group.Wait(); groupErr != nil {
88-
err = multierror.Append(
89-
err,
88+
returnErr = multierror.Append(
89+
returnErr,
9090
fmt.Errorf("failed to wait for controller-runtime component to stop: %v", groupErr),
9191
)
9292
}

pkg/agent/run_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ func TestRunOneShot(t *testing.T) {
4444
require.NoError(t, err)
4545

4646
logs.Initialize()
47-
Run(c, nil)
48-
klog.Flush()
47+
defer klog.Flush()
48+
49+
runErr := Run(c, nil)
50+
require.NoError(t, runErr, "Run returned an unexpected error")
51+
4952
return
5053
}
5154
t.Log("Running child process")

0 commit comments

Comments
 (0)