MCPcopy
hub / github.com/istio/istio / NewServer

Function NewServer

pilot/pkg/bootstrap/server.go:234–436  ·  view source on GitHub ↗

NewServer creates a new Server instance based on the provided arguments.

(args *PilotArgs, initFuncs ...func(*Server))

Source from the content-addressed store, hash-verified

232
233// NewServer creates a new Server instance based on the provided arguments.
234func NewServer(args *PilotArgs, initFuncs ...func(*Server)) (*Server, error) {
235 e := model.NewEnvironment()
236 e.DomainSuffix = args.RegistryOptions.KubeOptions.DomainSuffix
237
238 ac := aggregate.NewController(aggregate.Options{
239 MeshHolder: e,
240 ConfigClusterID: getClusterID(args),
241 })
242 e.ServiceDiscovery = ac
243
244 exporter, err := monitoring.RegisterPrometheusExporter(nil, nil)
245 if err != nil {
246 return nil, fmt.Errorf("could not set up prometheus exporter: %v", err)
247 }
248 s := &Server{
249 clusterID: getClusterID(args),
250 environment: e,
251 fileWatcher: filewatcher.NewWatcher(),
252 httpMux: http.NewServeMux(),
253 monitoringMux: http.NewServeMux(),
254 readinessProbes: make(map[string]readinessProbe),
255 readinessFlags: &readinessFlags{},
256 server: server.New(),
257 shutdownDuration: args.ShutdownDuration,
258 internalStop: make(chan struct{}),
259 istiodCertBundleWatcher: keycertbundle.NewWatcher(),
260 webhookInfo: &webhookInfo{},
261 metricsExporter: exporter,
262 krtDebugger: args.KrtDebugger,
263 }
264
265 // Apply custom initialization functions.
266 for _, fn := range initFuncs {
267 fn(s)
268 }
269 // Initialize workload Trust Bundle before XDS Server
270 s.XDSServer = xds.NewDiscoveryServer(e, args.RegistryOptions.KubeOptions.ClusterAliases, args.KrtDebugger)
271 configGen := core.NewConfigGenerator(s.XDSServer.Cache)
272
273 grpcprom.EnableHandlingTimeHistogram()
274
275 // make sure we have a readiness probe before serving HTTP to avoid marking ready too soon
276 s.initReadinessProbes()
277
278 s.initServers(args)
279 if err := s.initIstiodAdminServer(args, s.webhookInfo.GetTemplates); err != nil {
280 return nil, fmt.Errorf("error initializing debug server: %v", err)
281 }
282 if err := s.serveHTTP(); err != nil {
283 return nil, fmt.Errorf("error serving http: %v", err)
284 }
285
286 // Apply the arguments to the configuration.
287 if err := s.initKubeClient(args); err != nil {
288 return nil, fmt.Errorf("error initializing kube client: %v", err)
289 }
290
291 s.initMeshConfiguration(args, s.fileWatcher)

Callers 8

newDiscoveryCommandFunction · 0.92
FuzzNewBootstrapServerFunction · 0.92
TestNewServerCertInitFunction · 0.70
TestNewServerFunction · 0.70
TestMultiplexFunction · 0.70
TestIstiodCipherSuitesFunction · 0.70
TestIstiodMinTLSVersionFunction · 0.70

Calls 15

initReadinessProbesMethod · 0.95
initServersMethod · 0.95
initIstiodAdminServerMethod · 0.95
serveHTTPMethod · 0.95
initKubeClientMethod · 0.95
initMeshConfigurationMethod · 0.95
initMeshNetworksMethod · 0.95
initMeshHandlersMethod · 0.95
maybeCreateCAMethod · 0.95
initControllersMethod · 0.95
GetDiscoveryAddressMethod · 0.95

Tested by 6

TestNewServerCertInitFunction · 0.56
TestNewServerFunction · 0.56
TestMultiplexFunction · 0.56
TestIstiodCipherSuitesFunction · 0.56
TestIstiodMinTLSVersionFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…