@@ -4,12 +4,14 @@ import (
4
4
"context"
5
5
"io"
6
6
7
+ "github.com/pkg/errors"
7
8
corev1 "k8s.io/api/core/v1"
8
9
"k8s.io/client-go/kubernetes/scheme"
9
10
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
10
11
restclient "k8s.io/client-go/rest"
11
12
"k8s.io/client-go/tools/clientcmd"
12
13
"k8s.io/client-go/tools/remotecommand"
14
+ "k8s.io/client-go/util/retry"
13
15
)
14
16
15
17
type Client struct {
@@ -64,16 +66,26 @@ func (c *Client) Exec(ctx context.Context, pod *corev1.Pod, containerName string
64
66
65
67
exec , err := remotecommand .NewSPDYExecutor (c .restconfig , "POST" , req .URL ())
66
68
if err != nil {
67
- return err
69
+ return errors . Wrap ( err , "failed to create executor" )
68
70
}
69
71
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
+ })
76
82
})
83
+
84
+ if retryErr != nil {
85
+ return errors .Wrap (retryErr , "failed to execute command in pod" )
86
+ }
87
+
88
+ return nil
77
89
}
78
90
79
91
func (c * Client ) REST () restclient.Interface {
0 commit comments