Skip to content

Commit 9d78ba6

Browse files
Plugin: Improve error handling. (#13113)
Co-authored-by: morguldir <[email protected]>
1 parent db385c1 commit 9d78ba6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cmd/plugin/kubectl/kubectl.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
// PodExecString takes a pod and a command, uses kubectl exec to run the command in the pod
3333
// and returns stdout as a string
3434
func PodExecString(flags *genericclioptions.ConfigFlags, pod *apiv1.Pod, container string, args []string) (string, error) {
35-
args = append([]string{"exec", "-n", pod.Namespace, "-c", container, pod.Name}, args...)
35+
args = append([]string{"exec", "-n", pod.Namespace, "-c", container, pod.Name, "--"}, args...)
3636
return ExecToString(flags, args)
3737
}
3838

@@ -73,6 +73,8 @@ func execToWriter(args []string, writer io.Writer) error {
7373
//nolint:gosec // Ignore G204 error
7474
cmd := exec.Command(args[0], args[1:]...)
7575

76+
var stderr bytes.Buffer
77+
cmd.Stderr = &stderr
7678
op, err := cmd.StdoutPipe()
7779
if err != nil {
7880
return err
@@ -83,6 +85,9 @@ func execToWriter(args []string, writer io.Writer) error {
8385
}()
8486
err = cmd.Run()
8587
if err != nil {
88+
if _, ok := err.(*exec.ExitError); ok {
89+
println(stderr.String())
90+
}
8691
return err
8792
}
8893

0 commit comments

Comments
 (0)