1package autopilot
2
3import (
4	"time"
5
6	"github.com/hashicorp/raft"
7)
8
9// PromoteStableServers is a basic autopilot promotion policy that promotes any
10// server which has been healthy and stable for the duration specified in the
11// given Autopilot config.
12func PromoteStableServers(autopilotConfig *Config, health OperatorHealthReply, servers []raft.Server) []raft.Server {
13	// Find any non-voters eligible for promotion.
14	now := time.Now()
15	var promotions []raft.Server
16	for _, server := range servers {
17		if !IsPotentialVoter(server.Suffrage) {
18			health := health.ServerHealth(string(server.ID))
19			if health.IsStable(now, autopilotConfig) {
20				promotions = append(promotions, server)
21			}
22		}
23	}
24
25	return promotions
26}
27