Skip to content

Commit

Permalink
Merge pull request #211 from martinkunc/use-default-config
Browse files Browse the repository at this point in the history
Take default support instead of rely on existence of config
  • Loading branch information
openshift-merge-robot authored Oct 13, 2020
2 parents 7a0fff4 + 4576d64 commit 94bb271
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ type Serialized struct {
Impersonate string `json:"impersonate"`
}

func (s *Serialized) ToController() (*Controller, error) {
cfg := Controller{
Report: s.Report,
StoragePath: s.StoragePath,
Endpoint: s.Endpoint,
ReportEndpoint: s.PullReport.Endpoint,
Impersonate: s.Impersonate,
func (s *Serialized) ToController(cfg *Controller) (*Controller, error) {
if cfg == nil {
cfg = &Controller{}
}
cfg.Report = s.Report
cfg.StoragePath = s.StoragePath
cfg.Endpoint = s.Endpoint
cfg.Impersonate = s.Impersonate

if len(s.Interval) > 0 {
d, err := time.ParseDuration(s.Interval)
if err != nil {
Expand All @@ -40,6 +41,10 @@ func (s *Serialized) ToController() (*Controller, error) {
return nil, fmt.Errorf("interval must be a non-negative duration")
}

if len(s.PullReport.Endpoint) > 0 {
cfg.ReportEndpoint = s.PullReport.Endpoint
}

if len(s.PullReport.Delay) > 0 {
d, err := time.ParseDuration(s.PullReport.Delay)
if err != nil {
Expand Down Expand Up @@ -79,7 +84,7 @@ func (s *Serialized) ToController() (*Controller, error) {
if len(cfg.StoragePath) == 0 {
return nil, fmt.Errorf("storagePath must point to a directory where snapshots can be stored")
}
return &cfg, nil
return cfg, nil
}

// Controller defines the standard config for this operator.
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (s *Support) LoadConfig(obj map[string]interface{}) error {
return fmt.Errorf("unable to load config: %v", err)
}

controller, err := cfg.ToController()
controller, err := cfg.ToController(&s.Controller)
if err != nil {
return err
}
Expand Down

0 comments on commit 94bb271

Please sign in to comment.