app/platform: move failover config initialization to platform (#21281)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
5a4cac43a8
Коммит
e99eba33ff
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user