From 59204598c8365655a289234f70d5c48fd9812071 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 26 Nov 2021 17:57:55 -0500 Subject: [PATCH] ca: clean up unnecessary raft.Apply response checking In d2ab767fef21244e9fe3b9887ea70fc177912381 raftApply was changed to handle this check in a single place, instad of having every caller check it. It looks like these few places were missed when I did that clean up. This commit removes the remaining resp.(error) checks, since they are all no-ops now. --- agent/consul/leader_connect_ca.go | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/agent/consul/leader_connect_ca.go b/agent/consul/leader_connect_ca.go index 180f488cb8..e208694213 100644 --- a/agent/consul/leader_connect_ca.go +++ b/agent/consul/leader_connect_ca.go @@ -240,12 +240,9 @@ func (c *CAManager) initializeCAConfig() (*structs.CAConfiguration, error) { Op: structs.CAOpSetConfig, Config: config, } - if resp, err := c.delegate.ApplyCARequest(&req); err != nil { + if _, err := c.delegate.ApplyCARequest(&req); err != nil { return nil, err - } else if respErr, ok := resp.(error); ok { - return nil, respErr } - return config, nil } @@ -564,17 +561,13 @@ func (c *CAManager) primaryInitialize(provider ca.Provider, conf *structs.CAConf } // Store the root cert in raft - resp, err := c.delegate.ApplyCARequest(&structs.CARequest{ + _, err = c.delegate.ApplyCARequest(&structs.CARequest{ Op: structs.CAOpSetRoots, Index: idx, Roots: []*structs.CARoot{rootCA}, }) if err != nil { - c.logger.Error("Raft apply failed", "error", err) - return err - } - if respErr, ok := resp.(error); ok { - return respErr + return fmt.Errorf("raft apply failed: %w", err) } c.setCAProvider(provider, rootCA) @@ -776,9 +769,6 @@ func (c *CAManager) persistNewRootAndConfig(provider ca.Provider, newActiveRoot if err != nil { return err } - if respErr, ok := resp.(error); ok { - return respErr - } if respOk, ok := resp.(bool); ok && !respOk { return fmt.Errorf("could not atomically update roots and config") } @@ -917,13 +907,10 @@ func (c *CAManager) primaryUpdateRootCA(newProvider ca.Provider, args *structs.C // If the root didn't change, just update the config and return. if root != nil && root.ID == newActiveRoot.ID { args.Op = structs.CAOpSetConfig - resp, err := c.delegate.ApplyCARequest(args) + _, err := c.delegate.ApplyCARequest(args) if err != nil { return err } - if respErr, ok := resp.(error); ok { - return respErr - } // If the config has been committed, update the local provider instance c.setCAProvider(newProvider, newActiveRoot) @@ -1021,9 +1008,6 @@ func (c *CAManager) primaryUpdateRootCA(newProvider ca.Provider, args *structs.C if err != nil { return err } - if respErr, ok := resp.(error); ok { - return respErr - } if respOk, ok := resp.(bool); ok && !respOk { return fmt.Errorf("could not atomically update roots and config") }