Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resmgr,agent: propagate startup config error back to CR. #416

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TemplateConfigInterface() ConfigInterface {
}

// NotifyFn is a function to call when the effective configuration changes.
type NotifyFn func(cfg interface{}) error
type NotifyFn func(cfg interface{}) (bool, error)

var (
// Our logger instance for the agent.
Expand Down Expand Up @@ -544,12 +544,17 @@ func (a *Agent) updateConfig(cfg metav1.Object) {
}
}

err := a.notifyFn(cfg)
fatal, err := a.notifyFn(cfg)
a.patchConfigStatus(a.currentCfg, cfg, err)

if err != nil {
log.Errorf("failed to apply configuration: %v", err)
if fatal {
log.Fatalf("failed to apply configuration: %v", err)
} else {
log.Errorf("failed to apply configuration: %v", err)
}
}

a.patchConfigStatus(a.currentCfg, cfg, err)
a.currentCfg = cfg
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/resmgr/resource-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,17 @@ func (m *resmgr) Start() error {
return nil
}

func (m *resmgr) updateConfig(newCfg interface{}) error {
func (m *resmgr) updateConfig(newCfg interface{}) (bool, error) {
if newCfg == nil {
return fmt.Errorf("can't run without effective configuration...")
return false, fmt.Errorf("can't run without effective configuration...")
}

cfg, ok := newCfg.(cfgapi.ResmgrConfig)
if !ok {
if !m.running {
log.Fatalf("got initial configuration of unexpected type %T", newCfg)
return true, fmt.Errorf("got initial configuration of unexpected type %T", newCfg)
} else {
return fmt.Errorf("got configuration of unexpected type %T", newCfg)
return false, fmt.Errorf("got configuration of unexpected type %T", newCfg)
}
}

Expand All @@ -151,17 +151,17 @@ func (m *resmgr) updateConfig(newCfg interface{}) error {
log.InfoBlock(" <initial config> ", "%s", dump)

if err := m.start(cfg); err != nil {
log.Fatalf("failed to start with initial configuration: %v", err)
return true, fmt.Errorf("failed to start with initial configuration: %v", err)
}

m.running = true
return nil
return false, nil
}

log.Infof("configuration update %s (generation %d):", meta.GetName(), meta.GetGeneration())
log.InfoBlock(" <updated config> ", "%s", dump)

return m.reconfigure(cfg)
return false, m.reconfigure(cfg)
}

// Start resource management once we acquired initial configuration.
Expand Down
Loading