From fc1b8a0b3401e97d4c11e3624391156e56b78837 Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Wed, 6 Nov 2024 16:30:53 +0000 Subject: [PATCH 1/2] Fail TestRunOneShot if Run returns errors Signed-off-by: Richard Wall --- pkg/agent/run_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/agent/run_test.go b/pkg/agent/run_test.go index 69025950..3bd54773 100644 --- a/pkg/agent/run_test.go +++ b/pkg/agent/run_test.go @@ -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") From 53474d15f39233d117f4afcdff7da9c38922b8bd Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Wed, 6 Nov 2024 16:31:57 +0000 Subject: [PATCH 2/2] Append errgroup errors to Run return error Signed-off-by: Richard Wall --- pkg/agent/run.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/agent/run.go b/pkg/agent/run.go index 5d3ad52d..fc66da68 100644 --- a/pkg/agent/run.go +++ b/pkg/agent/run.go @@ -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( @@ -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), ) }