@@ -16,7 +16,6 @@ import (
16
16
"github.com/golang/protobuf/ptypes/any"
17
17
"google.golang.org/protobuf/types/known/anypb"
18
18
19
- "github.com/openservicemesh/osm/pkg/configurator"
20
19
"github.com/openservicemesh/osm/pkg/constants"
21
20
"github.com/openservicemesh/osm/pkg/envoy"
22
21
"github.com/openservicemesh/osm/pkg/errcode"
@@ -115,8 +114,8 @@ func BuildValidationSecret() (*xds_discovery.DiscoveryResponse, error) {
115
114
}, nil
116
115
}
117
116
118
- // BuildFromConfig builds and returns an Envoy Bootstrap object from the given config
119
- func BuildFromConfig ( config Config ) (* xds_bootstrap.Bootstrap , error ) {
117
+ // Build builds and returns an Envoy Bootstrap object from the given config
118
+ func ( b * Builder ) Build ( ) (* xds_bootstrap.Bootstrap , error ) {
120
119
httpProtocolOptions := & xds_upstream_http.HttpProtocolOptions {
121
120
UpstreamProtocolOptions : & xds_upstream_http.HttpProtocolOptions_ExplicitHttpConfig_ {
122
121
ExplicitHttpConfig : & xds_upstream_http.HttpProtocolOptions_ExplicitHttpConfig {
@@ -139,8 +138,8 @@ func BuildFromConfig(config Config) (*xds_bootstrap.Bootstrap, error) {
139
138
return nil , err
140
139
}
141
140
142
- minVersionInt := xds_transport_sockets .TlsParameters_TlsProtocol_value [config .TLSMinProtocolVersion ]
143
- maxVersionInt := xds_transport_sockets .TlsParameters_TlsProtocol_value [config .TLSMaxProtocolVersion ]
141
+ minVersionInt := xds_transport_sockets .TlsParameters_TlsProtocol_value [b .TLSMinProtocolVersion ]
142
+ maxVersionInt := xds_transport_sockets .TlsParameters_TlsProtocol_value [b .TLSMaxProtocolVersion ]
144
143
tlsMinVersion := xds_transport_sockets .TlsParameters_TlsProtocol (minVersionInt )
145
144
tlsMaxVersion := xds_transport_sockets .TlsParameters_TlsProtocol (maxVersionInt )
146
145
@@ -162,8 +161,8 @@ func BuildFromConfig(config Config) (*xds_bootstrap.Bootstrap, error) {
162
161
TlsParams : & xds_transport_sockets.TlsParameters {
163
162
TlsMinimumProtocolVersion : tlsMinVersion ,
164
163
TlsMaximumProtocolVersion : tlsMaxVersion ,
165
- CipherSuites : config .CipherSuites ,
166
- EcdhCurves : config .ECDHCurves ,
164
+ CipherSuites : b .CipherSuites ,
165
+ EcdhCurves : b .ECDHCurves ,
167
166
},
168
167
TlsCertificateSdsSecretConfigs : []* xds_transport_sockets.SdsSecretConfig {
169
168
{
@@ -186,7 +185,7 @@ func BuildFromConfig(config Config) (*xds_bootstrap.Bootstrap, error) {
186
185
187
186
bootstrap := & xds_bootstrap.Bootstrap {
188
187
Node : & xds_core.Node {
189
- Id : config .NodeID ,
188
+ Id : b .NodeID ,
190
189
},
191
190
Admin : & xds_bootstrap.Admin {
192
191
AccessLog : []* xds_accesslog_config.AccessLog {
@@ -202,7 +201,7 @@ func BuildFromConfig(config Config) (*xds_bootstrap.Bootstrap, error) {
202
201
SocketAddress : & xds_core.SocketAddress {
203
202
Address : constants .LocalhostIPAddress ,
204
203
PortSpecifier : & xds_core.SocketAddress_PortValue {
205
- PortValue : config . AdminPort ,
204
+ PortValue : constants . EnvoyAdminPort ,
206
205
},
207
206
},
208
207
},
@@ -216,7 +215,7 @@ func BuildFromConfig(config Config) (*xds_bootstrap.Bootstrap, error) {
216
215
{
217
216
TargetSpecifier : & xds_core.GrpcService_EnvoyGrpc_ {
218
217
EnvoyGrpc : & xds_core.GrpcService_EnvoyGrpc {
219
- ClusterName : config . XDSClusterName ,
218
+ ClusterName : constants . OSMControllerName ,
220
219
},
221
220
},
222
221
},
@@ -239,7 +238,7 @@ func BuildFromConfig(config Config) (*xds_bootstrap.Bootstrap, error) {
239
238
StaticResources : & xds_bootstrap.Bootstrap_StaticResources {
240
239
Clusters : []* xds_cluster.Cluster {
241
240
{
242
- Name : config . XDSClusterName ,
241
+ Name : constants . OSMControllerName ,
243
242
ClusterDiscoveryType : & xds_cluster.Cluster_Type {
244
243
Type : xds_cluster .Cluster_LOGICAL_DNS ,
245
244
},
@@ -254,7 +253,7 @@ func BuildFromConfig(config Config) (*xds_bootstrap.Bootstrap, error) {
254
253
},
255
254
LbPolicy : xds_cluster .Cluster_ROUND_ROBIN ,
256
255
LoadAssignment : & xds_endpoint.ClusterLoadAssignment {
257
- ClusterName : config . XDSClusterName ,
256
+ ClusterName : constants . OSMControllerName ,
258
257
Endpoints : []* xds_endpoint.LocalityLbEndpoints {
259
258
{
260
259
LbEndpoints : []* xds_endpoint.LbEndpoint {
@@ -264,9 +263,9 @@ func BuildFromConfig(config Config) (*xds_bootstrap.Bootstrap, error) {
264
263
Address : & xds_core.Address {
265
264
Address : & xds_core.Address_SocketAddress {
266
265
SocketAddress : & xds_core.SocketAddress {
267
- Address : config .XDSHost ,
266
+ Address : b .XDSHost ,
268
267
PortSpecifier : & xds_core.SocketAddress_PortValue {
269
- PortValue : config . XDSPort ,
268
+ PortValue : constants . ADSServerPort ,
270
269
},
271
270
},
272
271
},
@@ -283,35 +282,14 @@ func BuildFromConfig(config Config) (*xds_bootstrap.Bootstrap, error) {
283
282
},
284
283
}
285
284
286
- return bootstrap , nil
287
- }
288
-
289
- // GenerateEnvoyConfig generates an envoy bootstrap configuration from the given metadata.
290
- func GenerateEnvoyConfig (config EnvoyBootstrapConfigMeta , cfg configurator.Configurator ) (* xds_bootstrap.Bootstrap , error ) {
291
- bootstrapConfig , err := BuildFromConfig (Config {
292
- NodeID : config .NodeID ,
293
- AdminPort : constants .EnvoyAdminPort ,
294
- XDSClusterName : constants .OSMControllerName ,
295
- XDSHost : config .XDSHost ,
296
- XDSPort : config .XDSPort ,
297
- TLSMinProtocolVersion : config .TLSMinProtocolVersion ,
298
- TLSMaxProtocolVersion : config .TLSMaxProtocolVersion ,
299
- CipherSuites : config .CipherSuites ,
300
- ECDHCurves : config .ECDHCurves ,
301
- })
302
- if err != nil {
303
- log .Error ().Err (err ).Msgf ("Error building Envoy boostrap config" )
304
- return nil , err
305
- }
306
-
307
- probeListeners , probeClusters , err := getProbeResources (config )
285
+ probeListeners , probeClusters , err := b .getProbeResources ()
308
286
if err != nil {
309
287
return nil , err
310
288
}
311
- bootstrapConfig .StaticResources .Listeners = append (bootstrapConfig .StaticResources .Listeners , probeListeners ... )
312
- bootstrapConfig .StaticResources .Clusters = append (bootstrapConfig .StaticResources .Clusters , probeClusters ... )
289
+ bootstrap .StaticResources .Listeners = append (bootstrap .StaticResources .Listeners , probeListeners ... )
290
+ bootstrap .StaticResources .Clusters = append (bootstrap .StaticResources .Clusters , probeClusters ... )
313
291
314
- return bootstrapConfig , nil
292
+ return bootstrap , nil
315
293
}
316
294
317
295
// GetTLSSDSConfigYAML returns the statically used TLS SDS config YAML.
@@ -353,42 +331,42 @@ func GetValidationContextSDSConfigYAML() ([]byte, error) {
353
331
// These will not change during the lifetime of the Pod.
354
332
// If the original probe defined a TCPSocket action, listener and cluster objects are not configured
355
333
// to serve that probe.
356
- func getProbeResources ( config EnvoyBootstrapConfigMeta ) ([]* xds_listener.Listener , []* xds_cluster.Cluster , error ) {
334
+ func ( b * Builder ) getProbeResources ( ) ([]* xds_listener.Listener , []* xds_cluster.Cluster , error ) {
357
335
// This slice is the list of listeners for liveness, readiness, startup IF these have been configured in the Pod Spec
358
336
var listeners []* xds_listener.Listener
359
337
var clusters []* xds_cluster.Cluster
360
338
361
339
// Is there a liveness probe in the Pod Spec?
362
- if config .OriginalHealthProbes .Liveness != nil && ! config .OriginalHealthProbes .Liveness .IsTCPSocket {
363
- listener , err := getLivenessListener (config .OriginalHealthProbes .Liveness )
340
+ if b .OriginalHealthProbes .Liveness != nil && ! b .OriginalHealthProbes .Liveness .IsTCPSocket {
341
+ listener , err := getLivenessListener (b .OriginalHealthProbes .Liveness )
364
342
if err != nil {
365
343
log .Error ().Err (err ).Msgf ("Error getting liveness listener" )
366
344
return nil , nil , err
367
345
}
368
346
listeners = append (listeners , listener )
369
- clusters = append (clusters , getLivenessCluster (config .OriginalHealthProbes .Liveness ))
347
+ clusters = append (clusters , getLivenessCluster (b .OriginalHealthProbes .Liveness ))
370
348
}
371
349
372
350
// Is there a readiness probe in the Pod Spec?
373
- if config .OriginalHealthProbes .Readiness != nil && ! config .OriginalHealthProbes .Readiness .IsTCPSocket {
374
- listener , err := getReadinessListener (config .OriginalHealthProbes .Readiness )
351
+ if b .OriginalHealthProbes .Readiness != nil && ! b .OriginalHealthProbes .Readiness .IsTCPSocket {
352
+ listener , err := getReadinessListener (b .OriginalHealthProbes .Readiness )
375
353
if err != nil {
376
354
log .Error ().Err (err ).Msgf ("Error getting readiness listener" )
377
355
return nil , nil , err
378
356
}
379
357
listeners = append (listeners , listener )
380
- clusters = append (clusters , getReadinessCluster (config .OriginalHealthProbes .Readiness ))
358
+ clusters = append (clusters , getReadinessCluster (b .OriginalHealthProbes .Readiness ))
381
359
}
382
360
383
361
// Is there a startup probe in the Pod Spec?
384
- if config .OriginalHealthProbes .Startup != nil && ! config .OriginalHealthProbes .Startup .IsTCPSocket {
385
- listener , err := getStartupListener (config .OriginalHealthProbes .Startup )
362
+ if b .OriginalHealthProbes .Startup != nil && ! b .OriginalHealthProbes .Startup .IsTCPSocket {
363
+ listener , err := getStartupListener (b .OriginalHealthProbes .Startup )
386
364
if err != nil {
387
365
log .Error ().Err (err ).Msgf ("Error getting startup listener" )
388
366
return nil , nil , err
389
367
}
390
368
listeners = append (listeners , listener )
391
- clusters = append (clusters , getStartupCluster (config .OriginalHealthProbes .Startup ))
369
+ clusters = append (clusters , getStartupCluster (b .OriginalHealthProbes .Startup ))
392
370
}
393
371
394
372
return listeners , clusters , nil
0 commit comments