| // Copyright 2017 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| // Dialer dials Kubernetes pods. |
| func NewDialer(kc *Client) *Dialer { |
| func (d *Dialer) Dial(ctx context.Context, podName string, port int) (net.Conn, error) { |
| status, err := d.kc.PodStatus(ctx, podName) |
| return nil, fmt.Errorf("PodStatus of %q: %v", podName, err) |
| if status.Phase != "Running" { |
| return nil, fmt.Errorf("pod %q in state %q", podName, status.Phase) |
| return dialer.DialContext(ctx, "tcp", net.JoinHostPort(status.PodIP, strconv.Itoa(port))) |