Skip to content

Commit

Permalink
feat: export default GRPC dial options for the client
Browse files Browse the repository at this point in the history
Export GRPC dial options from a public function, so it can be imported by other projects.

Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com>
  • Loading branch information
utkuozdemir committed Apr 15, 2024
1 parent 7a767fa commit ca662d2
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,7 @@ func (client *Client) Run(ctx context.Context, logger *zap.Logger, notifyCh chan
if discoveryConn == nil {
var err error

opts := []grpc.DialOption{
grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: max(10*time.Second, client.options.TTL/10),
}),
}

if client.options.Insecure {
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
} else {
opts = append(opts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})))
}
opts := GRPCDialOptions(client.options)

discoveryConn, err = grpc.DialContext(ctx, client.options.Endpoint, opts...)
if err != nil {
Expand Down Expand Up @@ -587,3 +577,20 @@ func watch(ctx context.Context, client serverpb.ClusterClient, clusterID string)

return ch
}

// GRPCDialOptions returns gRPC dial options for the given client options.
func GRPCDialOptions(options Options) []grpc.DialOption {
opts := []grpc.DialOption{
grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: max(10*time.Second, options.TTL/10),
}),
}

if options.Insecure {
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
} else {
opts = append(opts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})))
}

return opts
}

0 comments on commit ca662d2

Please sign in to comment.