From 4375dd24091d171d48e32629f221b0361923212d Mon Sep 17 00:00:00 2001 From: Jorge Marey Date: Wed, 9 Feb 2022 17:46:42 +0100 Subject: [PATCH] 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 --- agent/consul/leader_connect_ca.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/agent/consul/leader_connect_ca.go b/agent/consul/leader_connect_ca.go index 35b4f343eb..ed5587ff57 100644 --- a/agent/consul/leader_connect_ca.go +++ b/agent/consul/leader_connect_ca.go @@ -693,7 +693,7 @@ func (c *CAManager) persistNewRootAndConfig(provider ca.Provider, newActiveRoot return fmt.Errorf("local CA not initialized yet") } // 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 } @@ -758,6 +758,17 @@ func (c *CAManager) persistNewRootAndConfig(provider ca.Provider, newActiveRoot 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) { // Attempt to update the state first. oldState, err := c.setState(caStateReconfig, true)