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