From 5d46e1bff67060345e6a63538fe180fe4623c8aa Mon Sep 17 00:00:00 2001 From: Easwar Swaminathan Date: Mon, 14 Oct 2019 23:15:54 +0000 Subject: [PATCH 1/3] Add new fields to resolver.BuildOption struct. These fields will be used by resolver implementations which need to talk to a remote name resolver. --- resolver/resolver.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/resolver/resolver.go b/resolver/resolver.go index 147e2314c33..ab3c1a7d2d5 100644 --- a/resolver/resolver.go +++ b/resolver/resolver.go @@ -21,6 +21,10 @@ package resolver import ( + "context" + "net" + + "google.golang.org/grpc/credentials" "google.golang.org/grpc/serviceconfig" ) @@ -105,8 +109,22 @@ type Address struct { // BuildOption includes additional information for the builder to create // the resolver. type BuildOption struct { - // DisableServiceConfig indicates whether resolver should fetch service config data. + // DisableServiceConfig indicates whether a resolver implementation should + // fetch service config data. DisableServiceConfig bool + // DialCreds is the transport credentials that a resolver implementation + // can use to dial a remote name resolution server. Resolver + // implementations which do not need to talk to another party securely can + // safely ignore this field. + DialCreds credentials.TransportCredentials + // CredsBundle is the credentials bundle that a resolver implementation can + // use while dialing a remote name resolution server. If both DialCreds and + // CredsBundle are set, the former takes precedence. + CredsBundle credentials.Bundle + // Dialer is the custom dialer that a resolver implementation can use to + // dial a remote name resolution server. Resolver implementations which do + // not need to talk to another party securely can safely ignore this field. + Dialer func(context.Context, string) (net.Conn, error) } // State contains the current Resolver state relevant to the ClientConn. From 5af9c01dc10c1e61067caf5d8d5f4f3bfe65a0bd Mon Sep 17 00:00:00 2001 From: Easwar Swaminathan Date: Tue, 15 Oct 2019 18:21:06 +0000 Subject: [PATCH 2/3] Add code to populate the newly added fields. --- resolver_conn_wrapper.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/resolver_conn_wrapper.go b/resolver_conn_wrapper.go index 33198007b13..16033fbf111 100644 --- a/resolver_conn_wrapper.go +++ b/resolver_conn_wrapper.go @@ -25,6 +25,7 @@ import ( "time" "google.golang.org/grpc/balancer" + "google.golang.org/grpc/credentials" "google.golang.org/grpc/grpclog" "google.golang.org/grpc/internal/channelz" "google.golang.org/grpc/internal/grpcsync" @@ -90,13 +91,24 @@ func newCCResolverWrapper(cc *ClientConn) (*ccResolverWrapper, error) { done: grpcsync.NewEvent(), } + var credsClone credentials.TransportCredentials + if creds := cc.dopts.copts.TransportCredentials; creds != nil { + credsClone = creds.Clone() + } + rbo := resolver.BuildOption{ + DisableServiceConfig: cc.dopts.disableServiceConfig, + DialCreds: credsClone, + CredsBundle: cc.dopts.copts.CredsBundle, + Dialer: cc.dopts.copts.Dialer, + } + var err error // We need to hold the lock here while we assign to the ccr.resolver field // to guard against a data race caused by the following code path, // rb.Build-->ccr.ReportError-->ccr.poll-->ccr.resolveNow, would end up // accessing ccr.resolver which is being assigned here. ccr.resolverMu.Lock() - ccr.resolver, err = rb.Build(cc.parsedTarget, ccr, resolver.BuildOption{DisableServiceConfig: cc.dopts.disableServiceConfig}) + ccr.resolver, err = rb.Build(cc.parsedTarget, ccr, rbo) if err != nil { return nil, err } From e9477578a301cc19680d1c595c7c1818720bd722 Mon Sep 17 00:00:00 2001 From: Easwar Swaminathan Date: Fri, 1 Nov 2019 20:30:11 +0000 Subject: [PATCH 3/3] Review comments. --- resolver/resolver.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/resolver/resolver.go b/resolver/resolver.go index ab3c1a7d2d5..4c5423ba0fb 100644 --- a/resolver/resolver.go +++ b/resolver/resolver.go @@ -112,18 +112,23 @@ type BuildOption struct { // DisableServiceConfig indicates whether a resolver implementation should // fetch service config data. DisableServiceConfig bool - // DialCreds is the transport credentials that a resolver implementation - // can use to dial a remote name resolution server. Resolver - // implementations which do not need to talk to another party securely can - // safely ignore this field. + // DialCreds is the transport credentials used by the ClientConn for + // communicating with the target gRPC service (set via + // WithTransportCredentials). In cases where a name resolution service + // requires the same credentials, the resolver may use this field. In most + // cases though, it is not appropriate, and this field may be ignored. DialCreds credentials.TransportCredentials - // CredsBundle is the credentials bundle that a resolver implementation can - // use while dialing a remote name resolution server. If both DialCreds and - // CredsBundle are set, the former takes precedence. + // CredsBundle is the credentials bundle used by the ClientConn for + // communicating with the target gRPC service (set via + // WithCredentialsBundle). In cases where a name resolution service + // requires the same credentials, the resolver may use this field. In most + // cases though, it is not appropriate, and this field may be ignored. CredsBundle credentials.Bundle - // Dialer is the custom dialer that a resolver implementation can use to - // dial a remote name resolution server. Resolver implementations which do - // not need to talk to another party securely can safely ignore this field. + // Dialer is the custom dialer used by the ClientConn for dialling the + // target gRPC service (set via WithDialer). In cases where a name + // resolution service requires the same dialer, the resolver may use this + // field. In most cases though, it is not appropriate, and this field may + // be ignored. Dialer func(context.Context, string) (net.Conn, error) }