github.com/hernad/nomad@v1.6.112/nomad/structs/config/autopilot.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package config 5 6 import ( 7 "time" 8 9 "github.com/hernad/nomad/helper/pointer" 10 ) 11 12 type AutopilotConfig struct { 13 // CleanupDeadServers controls whether to remove dead servers when a new 14 // server is added to the Raft peers. 15 CleanupDeadServers *bool `hcl:"cleanup_dead_servers"` 16 17 // ServerStabilizationTime is the minimum amount of time a server must be 18 // in a stable, healthy state before it can be added to the cluster. Only 19 // applicable with Raft protocol version 3 or higher. 20 ServerStabilizationTime time.Duration 21 ServerStabilizationTimeHCL string `hcl:"server_stabilization_time" json:"-"` 22 23 // LastContactThreshold is the limit on the amount of time a server can go 24 // without leader contact before being considered unhealthy. 25 LastContactThreshold time.Duration 26 LastContactThresholdHCL string `hcl:"last_contact_threshold" json:"-"` 27 28 // MaxTrailingLogs is the amount of entries in the Raft Log that a server can 29 // be behind before being considered unhealthy. 30 MaxTrailingLogs int `hcl:"max_trailing_logs"` 31 32 // MinQuorum sets the minimum number of servers required in a cluster 33 // before autopilot can prune dead servers. 34 MinQuorum int `hcl:"min_quorum"` 35 36 // (Enterprise-only) EnableRedundancyZones specifies whether to enable redundancy zones. 37 EnableRedundancyZones *bool `hcl:"enable_redundancy_zones"` 38 39 // (Enterprise-only) DisableUpgradeMigration will disable Autopilot's upgrade migration 40 // strategy of waiting until enough newer-versioned servers have been added to the 41 // cluster before promoting them to voters. 42 DisableUpgradeMigration *bool `hcl:"disable_upgrade_migration"` 43 44 // (Enterprise-only) EnableCustomUpgrades specifies whether to enable using custom 45 // upgrade versions when performing migrations. 46 EnableCustomUpgrades *bool `hcl:"enable_custom_upgrades"` 47 48 // ExtraKeysHCL is used by hcl to surface unexpected keys 49 ExtraKeysHCL []string `hcl:",unusedKeys" json:"-"` 50 } 51 52 // DefaultAutopilotConfig returns the canonical defaults for the Nomad 53 // `autopilot` configuration. 54 func DefaultAutopilotConfig() *AutopilotConfig { 55 return &AutopilotConfig{ 56 LastContactThreshold: 200 * time.Millisecond, 57 MaxTrailingLogs: 250, 58 ServerStabilizationTime: 10 * time.Second, 59 } 60 } 61 62 func (a *AutopilotConfig) Merge(b *AutopilotConfig) *AutopilotConfig { 63 result := a.Copy() 64 65 if b.CleanupDeadServers != nil { 66 result.CleanupDeadServers = pointer.Of(*b.CleanupDeadServers) 67 } 68 if b.ServerStabilizationTime != 0 { 69 result.ServerStabilizationTime = b.ServerStabilizationTime 70 } 71 if b.ServerStabilizationTimeHCL != "" { 72 result.ServerStabilizationTimeHCL = b.ServerStabilizationTimeHCL 73 } 74 if b.LastContactThreshold != 0 { 75 result.LastContactThreshold = b.LastContactThreshold 76 } 77 if b.LastContactThresholdHCL != "" { 78 result.LastContactThresholdHCL = b.LastContactThresholdHCL 79 } 80 if b.MaxTrailingLogs != 0 { 81 result.MaxTrailingLogs = b.MaxTrailingLogs 82 } 83 if b.MinQuorum != 0 { 84 result.MinQuorum = b.MinQuorum 85 } 86 if b.EnableRedundancyZones != nil { 87 result.EnableRedundancyZones = b.EnableRedundancyZones 88 } 89 if b.DisableUpgradeMigration != nil { 90 result.DisableUpgradeMigration = pointer.Of(*b.DisableUpgradeMigration) 91 } 92 if b.EnableCustomUpgrades != nil { 93 result.EnableCustomUpgrades = b.EnableCustomUpgrades 94 } 95 96 return result 97 } 98 99 // Copy returns a copy of this Autopilot config. 100 func (a *AutopilotConfig) Copy() *AutopilotConfig { 101 if a == nil { 102 return nil 103 } 104 105 nc := new(AutopilotConfig) 106 *nc = *a 107 108 // Copy the bools 109 if a.CleanupDeadServers != nil { 110 nc.CleanupDeadServers = pointer.Of(*a.CleanupDeadServers) 111 } 112 if a.EnableRedundancyZones != nil { 113 nc.EnableRedundancyZones = pointer.Of(*a.EnableRedundancyZones) 114 } 115 if a.DisableUpgradeMigration != nil { 116 nc.DisableUpgradeMigration = pointer.Of(*a.DisableUpgradeMigration) 117 } 118 if a.EnableCustomUpgrades != nil { 119 nc.EnableCustomUpgrades = pointer.Of(*a.EnableCustomUpgrades) 120 } 121 122 return nc 123 }