adding grpc mutual tls
This commit is contained in:
@@ -3,29 +3,32 @@ package wdclient
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
||||
"github.com/chrislusf/seaweedfs/weed/util"
|
||||
"math/rand"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type MasterClient struct {
|
||||
ctx context.Context
|
||||
name string
|
||||
currentMaster string
|
||||
masters []string
|
||||
ctx context.Context
|
||||
name string
|
||||
currentMaster string
|
||||
masters []string
|
||||
grpcDialOption grpc.DialOption
|
||||
|
||||
vidMap
|
||||
}
|
||||
|
||||
func NewMasterClient(ctx context.Context, clientName string, masters []string) *MasterClient {
|
||||
func NewMasterClient(ctx context.Context, grpcDialOption grpc.DialOption, clientName string, masters []string) *MasterClient {
|
||||
return &MasterClient{
|
||||
ctx: ctx,
|
||||
name: clientName,
|
||||
masters: masters,
|
||||
vidMap: newVidMap(),
|
||||
ctx: ctx,
|
||||
name: clientName,
|
||||
masters: masters,
|
||||
grpcDialOption: grpcDialOption,
|
||||
vidMap: newVidMap(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +53,7 @@ func (mc *MasterClient) KeepConnectedToMaster() {
|
||||
func (mc *MasterClient) tryAllMasters() {
|
||||
for _, master := range mc.masters {
|
||||
glog.V(0).Infof("Connecting to master %v", master)
|
||||
gprcErr := withMasterClient(master, func(client master_pb.SeaweedClient) error {
|
||||
gprcErr := withMasterClient(master, mc.grpcDialOption, func(client master_pb.SeaweedClient) error {
|
||||
|
||||
stream, err := client.KeepConnected(context.Background())
|
||||
if err != nil {
|
||||
@@ -96,14 +99,14 @@ func (mc *MasterClient) tryAllMasters() {
|
||||
}
|
||||
}
|
||||
|
||||
func withMasterClient(master string, fn func(client master_pb.SeaweedClient) error) error {
|
||||
func withMasterClient(master string, grpcDialOption grpc.DialOption, fn func(client master_pb.SeaweedClient) error) error {
|
||||
|
||||
masterGrpcAddress, parseErr := util.ParseServerToGrpcAddress(master, 0)
|
||||
if parseErr != nil {
|
||||
return fmt.Errorf("failed to parse master grpc %v", master)
|
||||
}
|
||||
|
||||
grpcConnection, err := util.GrpcDial(masterGrpcAddress)
|
||||
grpcConnection, err := util.GrpcDial(masterGrpcAddress, grpcDialOption)
|
||||
if err != nil {
|
||||
return fmt.Errorf("fail to dial %s: %v", master, err)
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package wdclient
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type SeaweedClient struct {
|
||||
*MasterClient
|
||||
}
|
||||
|
||||
func NewSeaweedClient(ctx context.Context, clientName string, masters []string) *SeaweedClient {
|
||||
return &SeaweedClient{
|
||||
MasterClient: NewMasterClient(ctx, clientName, masters),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user