app/platform: move failover config initialization to platform (#21281)

This commit is contained in:
Ibrahim Serdar Acikgoz
2022-10-07 13:53:13 +03:00
committed by GitHub
parent 5a4cac43a8
commit e99eba33ff
3 changed files with 16 additions and 27 deletions
-9
View File
@@ -36,15 +36,6 @@ type ServiceConfig struct {
Cluster einterfaces.ClusterInterface
}
func (c *ServiceConfig) validate() error {
// Mandatory fields need to be checked here
if c.ConfigStore == nil {
return errors.New("ConfigStore is required")
}
return nil
}
// ensure the config wrapper implements `product.ConfigService`
var _ product.ConfigService = (*PlatformService)(nil)
+15 -4
View File
@@ -97,10 +97,6 @@ type PlatformService struct {
// New creates a new PlatformService.
func New(sc ServiceConfig, options ...Option) (*PlatformService, error) {
if err := sc.validate(); err != nil {
return nil, err
}
// Step 0: Create the PlatformService.
// ConfigStore is and should be handled on a upper level.
ps := &PlatformService{
@@ -138,6 +134,21 @@ func New(sc ServiceConfig, options ...Option) (*PlatformService, error) {
}
}
// the config store is not set, we need to create a new one
if ps.configStore == nil {
innerStore, err := config.NewFileStore("config.json", true)
if err != nil {
return nil, fmt.Errorf("failed to load config from file: %w", err)
}
configStore, err := config.NewStoreFromBacking(innerStore, nil, false)
if err != nil {
return nil, fmt.Errorf("failed to load config from file: %w", err)
}
ps.configStore = configStore
}
// Step 2: Start logging.
if err := ps.initLogging(); err != nil {
return nil, fmt.Errorf("failed to initialize logging: %w", err)
+1 -14
View File
@@ -201,20 +201,7 @@ func NewServer(options ...Option) (*Server, error) {
//
// Step 1: Platform.
if s.platform == nil {
innerStore, err := config.NewFileStore("config.json", true)
if err != nil {
return nil, errors.Wrap(err, "failed to load config")
}
configStore, err := config.NewStoreFromBacking(innerStore, nil, false)
if err != nil {
return nil, errors.Wrap(err, "failed to load config")
}
platformCfg := platform.ServiceConfig{
ConfigStore: configStore,
}
ps, sErr := platform.New(platformCfg, s.platformOptions...)
ps, sErr := platform.New(platform.ServiceConfig{}, s.platformOptions...)
if sErr != nil {
return nil, errors.Wrap(sErr, "failed to initialize platform")
}