From 7ab9082183f0434ccd42871fd5726d0228b421a8 Mon Sep 17 00:00:00 2001 From: Antonin Bas Date: Mon, 20 May 2024 22:10:03 -0700 Subject: [PATCH] Fix ExecInPod implementation for antctl check (#6349) The function was not returning the contents of stdout / stderr in case of a command error, making troubleshooting impossible. Signed-off-by: Antonin Bas --- pkg/antctl/raw/check/installation/command.go | 6 +++++- .../raw/check/installation/test_podtoserviceinternode.go | 2 +- .../raw/check/installation/test_podtoserviceintranode.go | 2 +- pkg/antctl/raw/check/util.go | 5 +---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/antctl/raw/check/installation/command.go b/pkg/antctl/raw/check/installation/command.go index 902da8e4d59..256124ef2a9 100644 --- a/pkg/antctl/raw/check/installation/command.go +++ b/pkg/antctl/raw/check/installation/command.go @@ -21,6 +21,7 @@ import ( "net" "os" "regexp" + "strings" "time" "github.com/fatih/color" @@ -353,7 +354,10 @@ func (t *testContext) runAgnhostConnect(ctx context.Context, clientPodName strin _, stderr, err := check.ExecInPod(ctx, t.client, t.config, t.namespace, clientPodName, container, cmd) if err != nil { // We log the contents of stderr here for troubleshooting purposes. - t.Log("/agnhost command failed - stderr: %s", stderr) + t.Log("/agnhost command '%s' failed: %v", strings.Join(cmd, " "), err) + if stderr != "" { + t.Log("/agnhost stderr: %s", stderr) + } } return err } diff --git a/pkg/antctl/raw/check/installation/test_podtoserviceinternode.go b/pkg/antctl/raw/check/installation/test_podtoserviceinternode.go index 29e2ff59fbe..8635e5c04a3 100644 --- a/pkg/antctl/raw/check/installation/test_podtoserviceinternode.go +++ b/pkg/antctl/raw/check/installation/test_podtoserviceinternode.go @@ -33,7 +33,7 @@ func (t *PodToServiceInterNodeConnectivityTest) Run(ctx context.Context, testCon for _, clientPod := range testContext.clientPods { testContext.Log("Validating from Pod %s to Service %s in Namespace %s...", clientPod.Name, service, testContext.namespace) if err := testContext.runAgnhostConnect(ctx, clientPod.Name, "", service, 80); err != nil { - return fmt.Errorf("client Pod %s was not able to communicate with Service %s", clientPod.Name, service) + return fmt.Errorf("client Pod %s was not able to communicate with Service %s: %w", clientPod.Name, service, err) } testContext.Log("client Pod %s was able to communicate with Service %s", clientPod.Name, service) } diff --git a/pkg/antctl/raw/check/installation/test_podtoserviceintranode.go b/pkg/antctl/raw/check/installation/test_podtoserviceintranode.go index 3a377c0c220..653bd78ef23 100644 --- a/pkg/antctl/raw/check/installation/test_podtoserviceintranode.go +++ b/pkg/antctl/raw/check/installation/test_podtoserviceintranode.go @@ -30,7 +30,7 @@ func (t *PodToServiceIntraNodeConnectivityTest) Run(ctx context.Context, testCon for _, clientPod := range testContext.clientPods { testContext.Log("Validating from Pod %s to Service %s in Namespace %s...", clientPod.Name, service, testContext.namespace) if err := testContext.runAgnhostConnect(ctx, clientPod.Name, "", service, 80); err != nil { - return fmt.Errorf("client Pod %s was not able to communicate with Service %s", clientPod.Name, service) + return fmt.Errorf("client Pod %s was not able to communicate with Service %s: %w", clientPod.Name, service, err) } testContext.Log("client Pod %s was able to communicate with Service %s", clientPod.Name, service) } diff --git a/pkg/antctl/raw/check/util.go b/pkg/antctl/raw/check/util.go index ba589a0ab26..d5f3aa92843 100644 --- a/pkg/antctl/raw/check/util.go +++ b/pkg/antctl/raw/check/util.go @@ -102,10 +102,7 @@ func ExecInPod(ctx context.Context, client kubernetes.Interface, config *rest.Co Stderr: &stderr, Tty: false, }) - if err != nil { - return "", "", fmt.Errorf("error in stream: %w", err) - } - return stdout.String(), stderr.String(), nil + return stdout.String(), stderr.String(), err } func NewDeployment(p DeploymentParameters) *appsv1.Deployment {