Skip to content

Commit

Permalink
Merge pull request #796 from klihub/fixes/crash/nil-policy-rebalance
Browse files Browse the repository at this point in the history
crash fix: don't try to rebalance/deliver events/trigger post-update hooks with nil policy.
  • Loading branch information
klihub committed Mar 24, 2022
2 parents 5f0d88c + fd9e60d commit 0382249
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions pkg/cri/resource-manager/requests.go
Expand Up @@ -689,7 +689,7 @@ func (m *resmgr) RebalanceContainers() error {

// rebalance triggers a policy-specific rebalancing cycle of containers.
func (m *resmgr) rebalance(method string) error {
if m.policy == nil {
if m.policy == nil || m.policy.Bypassed() {
return nil
}

Expand All @@ -714,6 +714,10 @@ func (m *resmgr) DeliverPolicyEvent(e *events.Policy) error {
m.Lock()
defer m.Unlock()

if m.policy == nil || m.policy.Bypassed() {
return nil
}

if e.Source == "" {
e.Source = "unspecified"
}
Expand Down Expand Up @@ -759,15 +763,17 @@ func (m *resmgr) setConfig(v interface{}) error {
return resmgrError("configuration rejected: %v", err)
}

// synchronize state of controllers with new configuration
if err = m.control.StartStopControllers(m.cache, m.relay.Client()); err != nil {
m.Error("failed to synchronize controllers with new configuration: %v", err)
return resmgrError("failed to synchronize controllers with new configuration: %v", err)
}
if !(m.policy == nil || m.policy.Bypassed()) {
// synchronize state of controllers with new configuration
if err = m.control.StartStopControllers(m.cache, m.relay.Client()); err != nil {
m.Error("failed to synchronize controllers with new configuration: %v", err)
return resmgrError("failed to synchronize controllers with new configuration: %v", err)
}

if err = m.runPostUpdateHooks(context.Background(), "setConfig"); err != nil {
m.Error("failed to run post-update hooks after reconfiguration: %v", err)
return resmgrError("failed to run post-update hooks after reconfiguration: %v", err)
if err = m.runPostUpdateHooks(context.Background(), "setConfig"); err != nil {
m.Error("failed to run post-update hooks after reconfiguration: %v", err)
return resmgrError("failed to run post-update hooks after reconfiguration: %v", err)
}
}

// if we managed to activate a configuration from the agent, store it in the cache
Expand Down

0 comments on commit 0382249

Please sign in to comment.