@@ -4,12 +4,14 @@ import (
44 "context"
55 "io"
66
7+ "github.com/pkg/errors"
78 corev1 "k8s.io/api/core/v1"
89 "k8s.io/client-go/kubernetes/scheme"
910 corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
1011 restclient "k8s.io/client-go/rest"
1112 "k8s.io/client-go/tools/clientcmd"
1213 "k8s.io/client-go/tools/remotecommand"
14+ "k8s.io/client-go/util/retry"
1315)
1416
1517type Client struct {
@@ -64,16 +66,26 @@ func (c *Client) Exec(ctx context.Context, pod *corev1.Pod, containerName string
6466
6567 exec , err := remotecommand .NewSPDYExecutor (c .restconfig , "POST" , req .URL ())
6668 if err != nil {
67- return err
69+ return errors . Wrap ( err , "failed to create executor" )
6870 }
6971
70- // Connect this process' std{in,out,err} to the remote shell process.
71- return exec .StreamWithContext (ctx , remotecommand.StreamOptions {
72- Stdin : stdin ,
73- Stdout : stdout ,
74- Stderr : stderr ,
75- Tty : tty ,
72+ retryErr := retry .OnError (retry .DefaultRetry , func (err error ) bool {
73+ return true // Retry on all errors
74+ }, func () error {
75+ // Connect this process' std{in,out,err} to the remote shell process.
76+ return exec .StreamWithContext (ctx , remotecommand.StreamOptions {
77+ Stdin : stdin ,
78+ Stdout : stdout ,
79+ Stderr : stderr ,
80+ Tty : tty ,
81+ })
7682 })
83+
84+ if retryErr != nil {
85+ return errors .Wrap (retryErr , "failed to execute command in pod" )
86+ }
87+
88+ return nil
7789}
7890
7991func (c * Client ) REST () restclient.Interface {
0 commit comments