NewServer creates a new Server instance based on the provided arguments.
(args *PilotArgs, initFuncs ...func(*Server))
| 232 | |
| 233 | // NewServer creates a new Server instance based on the provided arguments. |
| 234 | func 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) |
searching dependent graphs…