forked from linkerd/linkerd2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
51 lines (43 loc) · 1.28 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package destination
import (
"context"
pb "github.com/linkerd/linkerd2-proxy-api/go/destination"
"github.com/linkerd/linkerd2/pkg/k8s"
"go.opencensus.io/plugin/ocgrpc"
"google.golang.org/grpc"
)
const (
destinationPort = 8086
destinationDeployment = "linkerd-destination"
)
// NewClient creates a client for the control plane Destination API that
// implements the Destination service.
func NewClient(addr string) (pb.DestinationClient, *grpc.ClientConn, error) {
conn, err := grpc.Dial(addr, grpc.WithInsecure(), grpc.WithStatsHandler(&ocgrpc.ClientHandler{}))
if err != nil {
return nil, nil, err
}
return pb.NewDestinationClient(conn), conn, nil
}
// NewExternalClient creates a client for the control plane Destination API
// to run from outside a Kubernetes cluster.
func NewExternalClient(ctx context.Context, controlPlaneNamespace string, kubeAPI *k8s.KubernetesAPI) (pb.DestinationClient, *grpc.ClientConn, error) {
portforward, err := k8s.NewPortForward(
ctx,
kubeAPI,
controlPlaneNamespace,
destinationDeployment,
"localhost",
0,
destinationPort,
false,
)
if err != nil {
return nil, nil, err
}
destinationAddress := portforward.AddressAndPort()
if err = portforward.Init(); err != nil {
return nil, nil, err
}
return NewClient(destinationAddress)
}