@@ -30,7 +30,6 @@ import (
3030	"net/url" 
3131	"time" 
3232
33- 	"google.golang.org/grpc" 
3433	"google.golang.org/grpc/grpclog" 
3534	"google.golang.org/grpc/internal/envconfig" 
3635	"google.golang.org/grpc/internal/googlecloud" 
@@ -39,9 +38,6 @@ import (
3938	"google.golang.org/grpc/resolver" 
4039	"google.golang.org/grpc/xds/internal/xdsclient" 
4140	"google.golang.org/grpc/xds/internal/xdsclient/bootstrap" 
42- 	"google.golang.org/protobuf/types/known/structpb" 
43- 
44- 	v3corepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3" 
4541
4642	_ "google.golang.org/grpc/xds"  // To register xds resolvers and balancers. 
4743)
@@ -106,26 +102,21 @@ func (c2pResolverBuilder) Build(t resolver.Target, cc resolver.ClientConn, opts
106102	if  balancerName  ==  ""  {
107103		balancerName  =  tdURL 
108104	}
109- 	serverConfig , err  :=  bootstrap .ServerConfigFromJSON ([]byte (fmt .Sprintf (` 
105+ 
106+ 	node  :=  newNode (<- zoneCh , <- ipv6CapableCh )
107+ 	xdsServer  :=  newXdsServer (balancerName )
108+ 	authorities  :=  newAuthorities (xdsServer )
109+ 
110+ 	config , err  :=  bootstrap .NewConfigFromContents ([]byte (fmt .Sprintf (` 
110111	{ 
111- 		"server_uri": "%s", 
112- 		"channel_creds": [{"type": "google_default"}], 
113- 		"server_features": ["xds_v3", "ignore_resource_deletion", "xds.config.resource-in-sotw"] 
114- 	}` , balancerName )))
112+ 		"xds_servers": [%s], 
113+ 	    "authorities": %s, 
114+ 		"node": %s 
115+ 	}` , xdsServer , authorities , node )))
116+ 
115117	if  err  !=  nil  {
116118		return  nil , fmt .Errorf ("failed to build bootstrap configuration: %v" , err )
117119	}
118- 	config  :=  & bootstrap.Config {
119- 		XDSServer : serverConfig ,
120- 		ClientDefaultListenerResourceNameTemplate : "%s" ,
121- 		Authorities : map [string ]* bootstrap.Authority {
122- 			c2pAuthority : {
123- 				XDSServer :                          serverConfig ,
124- 				ClientListenerResourceNameTemplate : fmt .Sprintf ("xdstp://%s/envoy.config.listener.v3.Listener/%%s" , c2pAuthority ),
125- 			},
126- 		},
127- 		NodeProto : newNode (<- zoneCh , <- ipv6CapableCh ),
128- 	}
129120
130121	// Create singleton xds client with this config. The xds client will be 
131122	// used by the xds resolver later. 
@@ -166,30 +157,41 @@ func (r *c2pResolver) Close() {
166157	r .clientCloseFunc ()
167158}
168159
169- var  ipv6EnabledMetadata  =  & structpb.Struct {
170- 	Fields : map [string ]* structpb.Value {
171- 		ipv6CapableMetadataName : structpb .NewBoolValue (true ),
172- 	},
173- }
174- 
175160var  id  =  fmt .Sprintf ("C2P-%d" , grpcrand .Int ())
176161
177- // newNode makes a copy of defaultNode, and populate it's Metadata and 
178- // Locality fields. 
179- func  newNode (zone  string , ipv6Capable  bool ) * v3corepb.Node  {
180- 	ret  :=  & v3corepb.Node {
181- 		// Not all required fields are set in defaultNote. Metadata will be set 
182- 		// if ipv6 is enabled. Locality will be set to the value from metadata. 
183- 		Id :                   id ,
184- 		UserAgentName :        gRPCUserAgentName ,
185- 		UserAgentVersionType : & v3corepb.Node_UserAgentVersion {UserAgentVersion : grpc .Version },
186- 		ClientFeatures :       []string {clientFeatureNoOverprovisioning },
187- 	}
188- 	ret .Locality  =  & v3corepb.Locality {Zone : zone }
162+ func  newNode (zone  string , ipv6Capable  bool ) string  {
163+ 	metadata  :=  "" 
189164	if  ipv6Capable  {
190- 		ret . Metadata  =  ipv6EnabledMetadata 
165+ 		metadata  =  fmt . Sprintf ( `, "metadata":  { "%s": true }` ,  ipv6CapableMetadataName ) 
191166	}
192- 	return  ret 
167+ 
168+ 	return  fmt .Sprintf (` 
169+ 	{ 
170+ 		"id": "%s", 
171+ 		"locality": { 
172+ 			"zone": "%s" 
173+ 		} 
174+ 		%s 
175+ 	}` , id , zone , metadata )
176+ }
177+ 
178+ func  newAuthorities (xdsServer  string ) string  {
179+ 	return  fmt .Sprintf (` 
180+ 	{ 
181+ 		"%s": { 
182+ 			"xds_servers": [%s] 
183+ 		} 
184+ 	} 
185+ 	` , c2pAuthority , xdsServer )
186+ }
187+ 
188+ func  newXdsServer (balancerName  string ) string  {
189+ 	return  fmt .Sprintf (` 
190+ 	{ 
191+ 		"server_uri": "%s", 
192+ 		"channel_creds": [{"type": "google_default"}], 
193+ 		"server_features": ["xds_v3", "ignore_resource_deletion"] 
194+ 	}` , balancerName )
193195}
194196
195197// runDirectPath returns whether this resolver should use direct path. 
0 commit comments