Skip to content

Commit

Permalink
[VC-35738] Append errgroup errors to the error returned by Agent.Run (#…
Browse files Browse the repository at this point in the history
…606)

* Append errgroup errors to Run return error
* Fail TestRunOneShot if Run returns errors
  • Loading branch information
wallrj authored Nov 7, 2024
1 parent 61d64e4 commit 4ce96c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pkg/agent/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var Flags AgentCmdFlags
const schemaVersion string = "v2.0.0"

// Run starts the agent process
func Run(cmd *cobra.Command, args []string) error {
func Run(cmd *cobra.Command, args []string) (returnErr error) {
logs.Log.Printf("Preflight agent version: %s (%s)", version.PreflightVersion, version.Commit)
ctx, cancel := context.WithCancel(
klog.NewContext(
Expand Down Expand Up @@ -85,8 +85,8 @@ func Run(cmd *cobra.Command, args []string) error {
defer func() {
cancel()
if groupErr := group.Wait(); groupErr != nil {
err = multierror.Append(
err,
returnErr = multierror.Append(
returnErr,
fmt.Errorf("failed to wait for controller-runtime component to stop: %v", groupErr),
)
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/agent/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ func TestRunOneShot(t *testing.T) {
require.NoError(t, err)

logs.Initialize()
Run(c, nil)
klog.Flush()
defer klog.Flush()

runErr := Run(c, nil)
require.NoError(t, runErr, "Run returned an unexpected error")

return
}
t.Log("Running child process")
Expand Down

0 comments on commit 4ce96c0

Please sign in to comment.