Avoid raft change when no config is provided on CAmanager

- This avoids a change to the raft store when no roots or config
are provided to persistNewRootAndConfig
This commit is contained in:
Jorge Marey 2022-02-09 17:46:42 +01:00
parent c60e04e086
commit 2ca00df0d8
1 changed files with 12 additions and 1 deletions

View File

@ -693,7 +693,7 @@ func (c *CAManager) persistNewRootAndConfig(provider ca.Provider, newActiveRoot
return fmt.Errorf("local CA not initialized yet") return fmt.Errorf("local CA not initialized yet")
} }
// Exit early if the change is a no-op. // Exit early if the change is a no-op.
if newActiveRoot == nil && config != nil && config.Provider == storedConfig.Provider && reflect.DeepEqual(config.Config, storedConfig.Config) { if !shouldPersistNewRootAndConfig(newActiveRoot, storedConfig, config) {
return nil return nil
} }
@ -758,6 +758,17 @@ func (c *CAManager) persistNewRootAndConfig(provider ca.Provider, newActiveRoot
return nil return nil
} }
func shouldPersistNewRootAndConfig(newActiveRoot *structs.CARoot, oldConfig, newConfig *structs.CAConfiguration) bool {
if newActiveRoot != nil {
return true
}
if newConfig == nil {
return false
}
return newConfig.Provider == oldConfig.Provider && reflect.DeepEqual(newConfig.Config, oldConfig.Config)
}
func (c *CAManager) UpdateConfiguration(args *structs.CARequest) (reterr error) { func (c *CAManager) UpdateConfiguration(args *structs.CARequest) (reterr error) {
// Attempt to update the state first. // Attempt to update the state first.
oldState, err := c.setState(caStateReconfig, true) oldState, err := c.setState(caStateReconfig, true)