Skip to content

Commit

Permalink
Fix ExecInPod implementation for antctl check (#6349)
Browse files Browse the repository at this point in the history
The function was not returning the contents of stdout / stderr in case
of a command error, making troubleshooting impossible.

Signed-off-by: Antonin Bas <[email protected]>
  • Loading branch information
antoninbas authored May 21, 2024
1 parent e65c1b4 commit 7ab9082
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
6 changes: 5 additions & 1 deletion pkg/antctl/raw/check/installation/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net"
"os"
"regexp"
"strings"
"time"

"github.com/fatih/color"
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/antctl/raw/check/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7ab9082

Please sign in to comment.