()
| 305 | } |
| 306 | |
| 307 | func (c *Controller) initController() { |
| 308 | c.initClients() |
| 309 | c.controllerID = os.Getenv("CONTROLLER_ID") |
| 310 | |
| 311 | if configObjectName := os.Getenv("POSTGRES_OPERATOR_CONFIGURATION_OBJECT"); configObjectName != "" { |
| 312 | if c.opConfig.EnableCRDRegistration != nil && *c.opConfig.EnableCRDRegistration { |
| 313 | if err := c.createConfigurationCRD(); err != nil { |
| 314 | c.logger.Fatalf("could not register Operator Configuration CustomResourceDefinition: %v", err) |
| 315 | } |
| 316 | } |
| 317 | if cfg, err := c.readOperatorConfigurationFromCRD(spec.GetOperatorNamespace(), configObjectName); err != nil { |
| 318 | c.logger.Fatalf("unable to read operator configuration: %v", err) |
| 319 | } else { |
| 320 | c.opConfig = c.importConfigurationFromCRD(&cfg.Configuration) |
| 321 | } |
| 322 | } else { |
| 323 | c.initOperatorConfig() |
| 324 | } |
| 325 | c.initPodServiceAccount() |
| 326 | c.initRoleBinding() |
| 327 | |
| 328 | c.modifyConfigFromEnvironment() |
| 329 | |
| 330 | if c.opConfig.EnableCRDRegistration != nil && *c.opConfig.EnableCRDRegistration { |
| 331 | if err := c.createPostgresCRD(); err != nil { |
| 332 | c.logger.Fatalf("could not register Postgres CustomResourceDefinition: %v", err) |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | c.initSharedInformers() |
| 337 | |
| 338 | c.pgTeamMap = teams.PostgresTeamMap{} |
| 339 | if c.opConfig.EnablePostgresTeamCRD { |
| 340 | c.loadPostgresTeams() |
| 341 | } |
| 342 | |
| 343 | if c.opConfig.DebugLogging { |
| 344 | c.logger.Logger.Level = logrus.DebugLevel |
| 345 | } |
| 346 | |
| 347 | logMultiLineConfig(c.logger, c.opConfig.MustMarshal()) |
| 348 | |
| 349 | roleDefs := c.getInfrastructureRoleDefinitions() |
| 350 | if infraRoles, err := c.getInfrastructureRoles(roleDefs); err != nil { |
| 351 | c.logger.Warningf("could not get infrastructure roles: %v", err) |
| 352 | } else { |
| 353 | c.config.InfrastructureRoles = infraRoles |
| 354 | } |
| 355 | |
| 356 | c.clusterEventQueues = make([]*cache.FIFO, c.opConfig.Workers) |
| 357 | c.workerLogs = make(map[uint32]ringlog.RingLogger, c.opConfig.Workers) |
| 358 | for i := range c.clusterEventQueues { |
| 359 | c.clusterEventQueues[i] = cache.NewFIFO(func(obj interface{}) (string, error) { |
| 360 | e, ok := obj.(ClusterEvent) |
| 361 | if !ok { |
| 362 | return "", fmt.Errorf("could not cast to ClusterEvent") |
| 363 | } |
| 364 |
no test coverage detected