Skip to content

Commit c887031

Browse files
authored
Support autopilot when raft is for HA only (#11260)
1 parent 79734c5 commit c887031

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

vault/logical_system_raft.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ func (b *SystemBackend) handleStorageRaftSnapshotRead() framework.OperationFunc
402402

403403
func (b *SystemBackend) handleStorageRaftAutopilotState() framework.OperationFunc {
404404
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
405-
raftBackend, ok := b.Core.underlyingPhysical.(*raft.RaftBackend)
406-
if !ok {
405+
raftBackend := b.Core.getRaftBackend()
406+
if raftBackend == nil {
407407
return logical.ErrorResponse("raft storage is not in use"), logical.ErrInvalidRequest
408408
}
409409

@@ -431,12 +431,12 @@ func (b *SystemBackend) handleStorageRaftAutopilotState() framework.OperationFun
431431

432432
func (b *SystemBackend) handleStorageRaftAutopilotConfigRead() framework.OperationFunc {
433433
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
434-
raftStorage, ok := b.Core.underlyingPhysical.(*raft.RaftBackend)
435-
if !ok {
434+
raftBackend := b.Core.getRaftBackend()
435+
if raftBackend == nil {
436436
return logical.ErrorResponse("raft storage is not in use"), logical.ErrInvalidRequest
437437
}
438438

439-
config := raftStorage.AutopilotConfig()
439+
config := raftBackend.AutopilotConfig()
440440
if config == nil {
441441
return nil, nil
442442
}
@@ -456,8 +456,8 @@ func (b *SystemBackend) handleStorageRaftAutopilotConfigRead() framework.Operati
456456

457457
func (b *SystemBackend) handleStorageRaftAutopilotConfigUpdate() framework.OperationFunc {
458458
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
459-
raftStorage, ok := b.Core.underlyingPhysical.(*raft.RaftBackend)
460-
if !ok {
459+
raftBackend := b.Core.getRaftBackend()
460+
if raftBackend == nil {
461461
return logical.ErrorResponse("raft storage is not in use"), logical.ErrInvalidRequest
462462
}
463463

@@ -506,7 +506,7 @@ func (b *SystemBackend) handleStorageRaftAutopilotConfigUpdate() framework.Opera
506506
persist = true
507507
}
508508

509-
effectiveConf := raftStorage.AutopilotConfig()
509+
effectiveConf := raftBackend.AutopilotConfig()
510510
effectiveConf.Merge(config)
511511

512512
if effectiveConf.CleanupDeadServers && effectiveConf.MinQuorum < 3 {
@@ -525,7 +525,7 @@ func (b *SystemBackend) handleStorageRaftAutopilotConfigUpdate() framework.Opera
525525
}
526526

527527
// Set the effectiveConfig
528-
raftStorage.SetAutopilotConfig(effectiveConf)
528+
raftBackend.SetAutopilotConfig(effectiveConf)
529529

530530
return nil, nil
531531
}

vault/raft.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (c *Core) setupRaftActiveNode(ctx context.Context) error {
169169
c.logger.Error("failed to load autopilot config from storage when setting up cluster; continuing since autopilot falls back to default config", "error", err)
170170
}
171171
disableAutopilot := c.disableAutopilot
172-
if c.isRaftHAOnly() || c.IsDRSecondary() {
172+
if c.IsDRSecondary() {
173173
disableAutopilot = true
174174
}
175175
raftBackend.SetupAutopilot(c.activeContext, autopilotConfig, c.raftFollowerStates, disableAutopilot)

vault/request_forwarding_rpc.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
"sync/atomic"
88
"time"
99

10+
"github.com/hashicorp/vault/sdk/helper/consts"
11+
1012
"github.com/hashicorp/vault/helper/forwarding"
1113
"github.com/hashicorp/vault/physical/raft"
12-
"github.com/hashicorp/vault/sdk/helper/consts"
1314
"github.com/hashicorp/vault/vault/replication"
1415
)
1516

@@ -83,10 +84,8 @@ func (s *forwardedRequestRPCServer) Echo(ctx context.Context, in *EchoRequest) (
8384
}
8485

8586
if raftBackend := s.core.getRaftBackend(); raftBackend != nil {
86-
if !s.core.isRaftHAOnly() {
87-
reply.RaftAppliedIndex = raftBackend.AppliedIndex()
88-
reply.RaftNodeID = raftBackend.NodeID()
89-
}
87+
reply.RaftAppliedIndex = raftBackend.AppliedIndex()
88+
reply.RaftNodeID = raftBackend.NodeID()
9089
}
9190

9291
return reply, nil
@@ -114,12 +113,10 @@ func (c *forwardingClient) startHeartbeat() {
114113
}
115114

116115
if raftBackend := c.core.getRaftBackend(); raftBackend != nil {
117-
if !c.core.isRaftHAOnly() {
118-
req.RaftAppliedIndex = raftBackend.AppliedIndex()
119-
req.RaftNodeID = raftBackend.NodeID()
120-
req.RaftTerm = raftBackend.Term()
121-
req.RaftDesiredSuffrage = raftBackend.DesiredSuffrage()
122-
}
116+
req.RaftAppliedIndex = raftBackend.AppliedIndex()
117+
req.RaftNodeID = raftBackend.NodeID()
118+
req.RaftTerm = raftBackend.Term()
119+
req.RaftDesiredSuffrage = raftBackend.DesiredSuffrage()
123120
}
124121

125122
ctx, cancel := context.WithTimeout(c.echoContext, 2*time.Second)

0 commit comments

Comments
 (0)