Plugin: Improve error handling. (#13112)
Co-authored-by: morguldir <morguldir@protonmail.com>
This commit is contained in:
parent
ddfe1d84df
commit
89f2934d78
1 changed files with 6 additions and 1 deletions
|
|
@ -32,7 +32,7 @@ import (
|
||||||
// PodExecString takes a pod and a command, uses kubectl exec to run the command in the pod
|
// PodExecString takes a pod and a command, uses kubectl exec to run the command in the pod
|
||||||
// and returns stdout as a string
|
// and returns stdout as a string
|
||||||
func PodExecString(flags *genericclioptions.ConfigFlags, pod *apiv1.Pod, container string, args []string) (string, error) {
|
func PodExecString(flags *genericclioptions.ConfigFlags, pod *apiv1.Pod, container string, args []string) (string, error) {
|
||||||
args = append([]string{"exec", "-n", pod.Namespace, "-c", container, pod.Name}, args...)
|
args = append([]string{"exec", "-n", pod.Namespace, "-c", container, pod.Name, "--"}, args...)
|
||||||
return ExecToString(flags, args)
|
return ExecToString(flags, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,6 +73,8 @@ func execToWriter(args []string, writer io.Writer) error {
|
||||||
//nolint:gosec // Ignore G204 error
|
//nolint:gosec // Ignore G204 error
|
||||||
cmd := exec.Command(args[0], args[1:]...)
|
cmd := exec.Command(args[0], args[1:]...)
|
||||||
|
|
||||||
|
var stderr bytes.Buffer
|
||||||
|
cmd.Stderr = &stderr
|
||||||
op, err := cmd.StdoutPipe()
|
op, err := cmd.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -83,6 +85,9 @@ func execToWriter(args []string, writer io.Writer) error {
|
||||||
}()
|
}()
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if _, ok := err.(*exec.ExitError); ok {
|
||||||
|
println(stderr.String())
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue