@@ -30,7 +30,6 @@ import (
30
30
"net/url"
31
31
"time"
32
32
33
- "google.golang.org/grpc"
34
33
"google.golang.org/grpc/grpclog"
35
34
"google.golang.org/grpc/internal/envconfig"
36
35
"google.golang.org/grpc/internal/googlecloud"
@@ -39,9 +38,6 @@ import (
39
38
"google.golang.org/grpc/resolver"
40
39
"google.golang.org/grpc/xds/internal/xdsclient"
41
40
"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"
45
41
46
42
_ "google.golang.org/grpc/xds" // To register xds resolvers and balancers.
47
43
)
@@ -106,26 +102,21 @@ func (c2pResolverBuilder) Build(t resolver.Target, cc resolver.ClientConn, opts
106
102
if balancerName == "" {
107
103
balancerName = tdURL
108
104
}
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 (`
110
111
{
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
+
115
117
if err != nil {
116
118
return nil , fmt .Errorf ("failed to build bootstrap configuration: %v" , err )
117
119
}
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
- }
129
120
130
121
// Create singleton xds client with this config. The xds client will be
131
122
// used by the xds resolver later.
@@ -166,30 +157,41 @@ func (r *c2pResolver) Close() {
166
157
r .clientCloseFunc ()
167
158
}
168
159
169
- var ipv6EnabledMetadata = & structpb.Struct {
170
- Fields : map [string ]* structpb.Value {
171
- ipv6CapableMetadataName : structpb .NewBoolValue (true ),
172
- },
173
- }
174
-
175
160
var id = fmt .Sprintf ("C2P-%d" , grpcrand .Int ())
176
161
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 := ""
189
164
if ipv6Capable {
190
- ret . Metadata = ipv6EnabledMetadata
165
+ metadata = fmt . Sprintf ( `, "metadata": { "%s": true }` , ipv6CapableMetadataName )
191
166
}
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 )
193
195
}
194
196
195
197
// runDirectPath returns whether this resolver should use direct path.
0 commit comments