Skip to content

Commit

Permalink
Contact pod before starting port forward, to verify connectivity (ist…
Browse files Browse the repository at this point in the history
  • Loading branch information
esnible authored and istio-testing committed Aug 5, 2019
1 parent ca63ad6 commit 57e5bae
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions istioctl/pkg/kubernetes/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,21 @@ func (client *Client) BuildPortForwarder(podName string, ns string, localPort in
return nil, fmt.Errorf("failed establishing port-forward: %v", err)
}

// Run the same check as k8s.io/kubectl/pkg/cmd/portforward/portforward.go
// so that we will fail early if there is a problem contacting API server.
podGet := client.Get().Resource("pods").Namespace(ns).Name(podName)
obj, err := podGet.Do().Get()
if err != nil {
return nil, fmt.Errorf("failed retrieving pod: %v", err)
}
pod, ok := obj.(*v1.Pod)
if !ok {
return nil, fmt.Errorf("failed getting pod: %v", err)
}
if pod.Status.Phase != v1.PodRunning {
return nil, fmt.Errorf("pod is not running. Status=%v", pod.Status.Phase)
}

return &PortForward{
Forwarder: fw,
ReadyChannel: ready,
Expand Down

0 comments on commit 57e5bae

Please sign in to comment.