(pod corev1.Pod)
| 245 | } |
| 246 | |
| 247 | func (w *workload) connect(pod corev1.Pod) (err error) { |
| 248 | defer func() { |
| 249 | if err != nil { |
| 250 | _ = w.disconnect() |
| 251 | } |
| 252 | }() |
| 253 | |
| 254 | // Create a forwarder to the command port of the app. |
| 255 | if err = retry.UntilSuccess(func() error { |
| 256 | w.forwarder, err = w.cluster.NewPortForwarder(pod.Name, pod.Namespace, "", 0, int(w.grpcPort)) |
| 257 | if err != nil { |
| 258 | return fmt.Errorf("failed creating new port forwarder for pod %s/%s: %v", |
| 259 | pod.Namespace, pod.Name, err) |
| 260 | } |
| 261 | if err = w.forwarder.Start(); err != nil { |
| 262 | return fmt.Errorf("failed starting port forwarder for pod %s/%s: %v", |
| 263 | pod.Namespace, pod.Name, err) |
| 264 | } |
| 265 | return nil |
| 266 | }, retry.BackoffDelay(100*time.Millisecond), retry.Timeout(10*time.Second)); err != nil { |
| 267 | return err |
| 268 | } |
| 269 | |
| 270 | // Create a gRPC client to this workload. |
| 271 | w.client, err = echoClient.New(w.forwarder.Address(), w.tls) |
| 272 | if err != nil { |
| 273 | return fmt.Errorf("failed connecting to grpc client to pod %s/%s : %v", |
| 274 | pod.Namespace, pod.Name, err) |
| 275 | } |
| 276 | |
| 277 | if w.hasSidecar { |
| 278 | w.sidecar = newSidecar(pod, w.cluster) |
| 279 | } |
| 280 | |
| 281 | return nil |
| 282 | } |
| 283 | |
| 284 | func (w *workload) disconnect() (err error) { |
| 285 | if w.client != nil { |
no test coverage detected