mirror of
https://github.com/hashicorp/vault.git
synced 2026-02-03 20:40:45 -05:00
Support autopilot when raft is for HA only (#11260)
This commit is contained in:
parent
79734c5222
commit
c8870314c1
3 changed files with 18 additions and 21 deletions
|
|
@ -402,8 +402,8 @@ func (b *SystemBackend) handleStorageRaftSnapshotRead() framework.OperationFunc
|
|||
|
||||
func (b *SystemBackend) handleStorageRaftAutopilotState() framework.OperationFunc {
|
||||
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
||||
raftBackend, ok := b.Core.underlyingPhysical.(*raft.RaftBackend)
|
||||
if !ok {
|
||||
raftBackend := b.Core.getRaftBackend()
|
||||
if raftBackend == nil {
|
||||
return logical.ErrorResponse("raft storage is not in use"), logical.ErrInvalidRequest
|
||||
}
|
||||
|
||||
|
|
@ -431,12 +431,12 @@ func (b *SystemBackend) handleStorageRaftAutopilotState() framework.OperationFun
|
|||
|
||||
func (b *SystemBackend) handleStorageRaftAutopilotConfigRead() framework.OperationFunc {
|
||||
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
||||
raftStorage, ok := b.Core.underlyingPhysical.(*raft.RaftBackend)
|
||||
if !ok {
|
||||
raftBackend := b.Core.getRaftBackend()
|
||||
if raftBackend == nil {
|
||||
return logical.ErrorResponse("raft storage is not in use"), logical.ErrInvalidRequest
|
||||
}
|
||||
|
||||
config := raftStorage.AutopilotConfig()
|
||||
config := raftBackend.AutopilotConfig()
|
||||
if config == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
@ -456,8 +456,8 @@ func (b *SystemBackend) handleStorageRaftAutopilotConfigRead() framework.Operati
|
|||
|
||||
func (b *SystemBackend) handleStorageRaftAutopilotConfigUpdate() framework.OperationFunc {
|
||||
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
||||
raftStorage, ok := b.Core.underlyingPhysical.(*raft.RaftBackend)
|
||||
if !ok {
|
||||
raftBackend := b.Core.getRaftBackend()
|
||||
if raftBackend == nil {
|
||||
return logical.ErrorResponse("raft storage is not in use"), logical.ErrInvalidRequest
|
||||
}
|
||||
|
||||
|
|
@ -506,7 +506,7 @@ func (b *SystemBackend) handleStorageRaftAutopilotConfigUpdate() framework.Opera
|
|||
persist = true
|
||||
}
|
||||
|
||||
effectiveConf := raftStorage.AutopilotConfig()
|
||||
effectiveConf := raftBackend.AutopilotConfig()
|
||||
effectiveConf.Merge(config)
|
||||
|
||||
if effectiveConf.CleanupDeadServers && effectiveConf.MinQuorum < 3 {
|
||||
|
|
@ -525,7 +525,7 @@ func (b *SystemBackend) handleStorageRaftAutopilotConfigUpdate() framework.Opera
|
|||
}
|
||||
|
||||
// Set the effectiveConfig
|
||||
raftStorage.SetAutopilotConfig(effectiveConf)
|
||||
raftBackend.SetAutopilotConfig(effectiveConf)
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ func (c *Core) setupRaftActiveNode(ctx context.Context) error {
|
|||
c.logger.Error("failed to load autopilot config from storage when setting up cluster; continuing since autopilot falls back to default config", "error", err)
|
||||
}
|
||||
disableAutopilot := c.disableAutopilot
|
||||
if c.isRaftHAOnly() || c.IsDRSecondary() {
|
||||
if c.IsDRSecondary() {
|
||||
disableAutopilot = true
|
||||
}
|
||||
raftBackend.SetupAutopilot(c.activeContext, autopilotConfig, c.raftFollowerStates, disableAutopilot)
|
||||
|
|
|
|||
|
|
@ -7,9 +7,10 @@ import (
|
|||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/vault/sdk/helper/consts"
|
||||
|
||||
"github.com/hashicorp/vault/helper/forwarding"
|
||||
"github.com/hashicorp/vault/physical/raft"
|
||||
"github.com/hashicorp/vault/sdk/helper/consts"
|
||||
"github.com/hashicorp/vault/vault/replication"
|
||||
)
|
||||
|
||||
|
|
@ -83,10 +84,8 @@ func (s *forwardedRequestRPCServer) Echo(ctx context.Context, in *EchoRequest) (
|
|||
}
|
||||
|
||||
if raftBackend := s.core.getRaftBackend(); raftBackend != nil {
|
||||
if !s.core.isRaftHAOnly() {
|
||||
reply.RaftAppliedIndex = raftBackend.AppliedIndex()
|
||||
reply.RaftNodeID = raftBackend.NodeID()
|
||||
}
|
||||
reply.RaftAppliedIndex = raftBackend.AppliedIndex()
|
||||
reply.RaftNodeID = raftBackend.NodeID()
|
||||
}
|
||||
|
||||
return reply, nil
|
||||
|
|
@ -114,12 +113,10 @@ func (c *forwardingClient) startHeartbeat() {
|
|||
}
|
||||
|
||||
if raftBackend := c.core.getRaftBackend(); raftBackend != nil {
|
||||
if !c.core.isRaftHAOnly() {
|
||||
req.RaftAppliedIndex = raftBackend.AppliedIndex()
|
||||
req.RaftNodeID = raftBackend.NodeID()
|
||||
req.RaftTerm = raftBackend.Term()
|
||||
req.RaftDesiredSuffrage = raftBackend.DesiredSuffrage()
|
||||
}
|
||||
req.RaftAppliedIndex = raftBackend.AppliedIndex()
|
||||
req.RaftNodeID = raftBackend.NodeID()
|
||||
req.RaftTerm = raftBackend.Term()
|
||||
req.RaftDesiredSuffrage = raftBackend.DesiredSuffrage()
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(c.echoContext, 2*time.Second)
|
||||
|
|
|
|||
Loading…
Reference in a new issue