2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2017-12-18 21:16:23 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2022-08-17 16:26:34 +00:00
|
|
|
"github.com/hashicorp/nomad/helper/pointer"
|
2017-12-18 21:16:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type AutopilotConfig struct {
|
|
|
|
// CleanupDeadServers controls whether to remove dead servers when a new
|
|
|
|
// server is added to the Raft peers.
|
2019-04-04 18:16:08 +00:00
|
|
|
CleanupDeadServers *bool `hcl:"cleanup_dead_servers"`
|
2017-12-18 21:16:23 +00:00
|
|
|
|
|
|
|
// ServerStabilizationTime is the minimum amount of time a server must be
|
|
|
|
// in a stable, healthy state before it can be added to the cluster. Only
|
|
|
|
// applicable with Raft protocol version 3 or higher.
|
2019-04-04 18:16:08 +00:00
|
|
|
ServerStabilizationTime time.Duration
|
2019-04-25 18:54:20 +00:00
|
|
|
ServerStabilizationTimeHCL string `hcl:"server_stabilization_time" json:"-"`
|
2017-12-18 21:16:23 +00:00
|
|
|
|
|
|
|
// LastContactThreshold is the limit on the amount of time a server can go
|
|
|
|
// without leader contact before being considered unhealthy.
|
2019-04-04 18:16:08 +00:00
|
|
|
LastContactThreshold time.Duration
|
2019-04-25 18:54:20 +00:00
|
|
|
LastContactThresholdHCL string `hcl:"last_contact_threshold" json:"-"`
|
2017-12-18 21:16:23 +00:00
|
|
|
|
|
|
|
// MaxTrailingLogs is the amount of entries in the Raft Log that a server can
|
|
|
|
// be behind before being considered unhealthy.
|
2019-04-04 18:16:08 +00:00
|
|
|
MaxTrailingLogs int `hcl:"max_trailing_logs"`
|
2017-12-18 21:16:23 +00:00
|
|
|
|
2020-02-16 21:23:20 +00:00
|
|
|
// MinQuorum sets the minimum number of servers required in a cluster
|
|
|
|
// before autopilot can prune dead servers.
|
|
|
|
MinQuorum int `hcl:"min_quorum"`
|
|
|
|
|
2018-01-30 03:53:34 +00:00
|
|
|
// (Enterprise-only) EnableRedundancyZones specifies whether to enable redundancy zones.
|
2019-04-04 18:16:08 +00:00
|
|
|
EnableRedundancyZones *bool `hcl:"enable_redundancy_zones"`
|
2017-12-18 21:16:23 +00:00
|
|
|
|
|
|
|
// (Enterprise-only) DisableUpgradeMigration will disable Autopilot's upgrade migration
|
|
|
|
// strategy of waiting until enough newer-versioned servers have been added to the
|
|
|
|
// cluster before promoting them to voters.
|
2019-04-04 18:16:08 +00:00
|
|
|
DisableUpgradeMigration *bool `hcl:"disable_upgrade_migration"`
|
2017-12-18 21:16:23 +00:00
|
|
|
|
2018-01-30 03:53:34 +00:00
|
|
|
// (Enterprise-only) EnableCustomUpgrades specifies whether to enable using custom
|
|
|
|
// upgrade versions when performing migrations.
|
2019-04-04 18:16:08 +00:00
|
|
|
EnableCustomUpgrades *bool `hcl:"enable_custom_upgrades"`
|
|
|
|
|
|
|
|
// ExtraKeysHCL is used by hcl to surface unexpected keys
|
2019-04-25 18:54:20 +00:00
|
|
|
ExtraKeysHCL []string `hcl:",unusedKeys" json:"-"`
|
2017-12-18 21:16:23 +00:00
|
|
|
}
|
|
|
|
|
2021-08-30 09:08:12 +00:00
|
|
|
// DefaultAutopilotConfig returns the canonical defaults for the Nomad
|
2017-12-18 21:16:23 +00:00
|
|
|
// `autopilot` configuration.
|
|
|
|
func DefaultAutopilotConfig() *AutopilotConfig {
|
|
|
|
return &AutopilotConfig{
|
|
|
|
LastContactThreshold: 200 * time.Millisecond,
|
|
|
|
MaxTrailingLogs: 250,
|
|
|
|
ServerStabilizationTime: 10 * time.Second,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AutopilotConfig) Merge(b *AutopilotConfig) *AutopilotConfig {
|
|
|
|
result := a.Copy()
|
|
|
|
|
|
|
|
if b.CleanupDeadServers != nil {
|
2022-08-17 16:26:34 +00:00
|
|
|
result.CleanupDeadServers = pointer.Of(*b.CleanupDeadServers)
|
2017-12-18 21:16:23 +00:00
|
|
|
}
|
|
|
|
if b.ServerStabilizationTime != 0 {
|
|
|
|
result.ServerStabilizationTime = b.ServerStabilizationTime
|
|
|
|
}
|
2019-06-11 19:25:56 +00:00
|
|
|
if b.ServerStabilizationTimeHCL != "" {
|
|
|
|
result.ServerStabilizationTimeHCL = b.ServerStabilizationTimeHCL
|
|
|
|
}
|
2017-12-18 21:16:23 +00:00
|
|
|
if b.LastContactThreshold != 0 {
|
|
|
|
result.LastContactThreshold = b.LastContactThreshold
|
|
|
|
}
|
2019-06-11 19:25:56 +00:00
|
|
|
if b.LastContactThresholdHCL != "" {
|
|
|
|
result.LastContactThresholdHCL = b.LastContactThresholdHCL
|
|
|
|
}
|
2017-12-18 21:16:23 +00:00
|
|
|
if b.MaxTrailingLogs != 0 {
|
|
|
|
result.MaxTrailingLogs = b.MaxTrailingLogs
|
|
|
|
}
|
2020-02-16 21:23:20 +00:00
|
|
|
if b.MinQuorum != 0 {
|
|
|
|
result.MinQuorum = b.MinQuorum
|
|
|
|
}
|
2018-01-30 03:53:34 +00:00
|
|
|
if b.EnableRedundancyZones != nil {
|
|
|
|
result.EnableRedundancyZones = b.EnableRedundancyZones
|
2017-12-18 21:16:23 +00:00
|
|
|
}
|
|
|
|
if b.DisableUpgradeMigration != nil {
|
2022-08-17 16:26:34 +00:00
|
|
|
result.DisableUpgradeMigration = pointer.Of(*b.DisableUpgradeMigration)
|
2017-12-18 21:16:23 +00:00
|
|
|
}
|
2018-01-30 03:53:34 +00:00
|
|
|
if b.EnableCustomUpgrades != nil {
|
|
|
|
result.EnableCustomUpgrades = b.EnableCustomUpgrades
|
2017-12-18 21:16:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy returns a copy of this Autopilot config.
|
|
|
|
func (a *AutopilotConfig) Copy() *AutopilotConfig {
|
|
|
|
if a == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
nc := new(AutopilotConfig)
|
|
|
|
*nc = *a
|
|
|
|
|
|
|
|
// Copy the bools
|
|
|
|
if a.CleanupDeadServers != nil {
|
2022-08-17 16:26:34 +00:00
|
|
|
nc.CleanupDeadServers = pointer.Of(*a.CleanupDeadServers)
|
2017-12-18 21:16:23 +00:00
|
|
|
}
|
2018-01-30 03:53:34 +00:00
|
|
|
if a.EnableRedundancyZones != nil {
|
2022-08-17 16:26:34 +00:00
|
|
|
nc.EnableRedundancyZones = pointer.Of(*a.EnableRedundancyZones)
|
2018-01-30 03:53:34 +00:00
|
|
|
}
|
2017-12-18 21:16:23 +00:00
|
|
|
if a.DisableUpgradeMigration != nil {
|
2022-08-17 16:26:34 +00:00
|
|
|
nc.DisableUpgradeMigration = pointer.Of(*a.DisableUpgradeMigration)
|
2017-12-18 21:16:23 +00:00
|
|
|
}
|
2018-01-30 03:53:34 +00:00
|
|
|
if a.EnableCustomUpgrades != nil {
|
2022-08-17 16:26:34 +00:00
|
|
|
nc.EnableCustomUpgrades = pointer.Of(*a.EnableCustomUpgrades)
|
2018-01-30 03:53:34 +00:00
|
|
|
}
|
2017-12-18 21:16:23 +00:00
|
|
|
|
|
|
|
return nc
|
|
|
|
}
|