Skip to content

Commit 6841107

Browse files
authored
Plugin: Improve error handling. (#13102)
1 parent 8aca34b commit 6841107

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cmd/plugin/kubectl/kubectl.go

+6-1
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)