github.com/bigcommerce/nomad@v0.9.3-bc/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  	// (Enterprise-only) EnableRedundancyZones specifies whether to enable redundancy zones.
    30  	EnableRedundancyZones *bool `hcl:"enable_redundancy_zones"`
    31  
    32  	// (Enterprise-only) DisableUpgradeMigration will disable Autopilot's upgrade migration
    33  	// strategy of waiting until enough newer-versioned servers have been added to the
    34  	// cluster before promoting them to voters.
    35  	DisableUpgradeMigration *bool `hcl:"disable_upgrade_migration"`
    36  
    37  	// (Enterprise-only) EnableCustomUpgrades specifies whether to enable using custom
    38  	// upgrade versions when performing migrations.
    39  	EnableCustomUpgrades *bool `hcl:"enable_custom_upgrades"`
    40  
    41  	// ExtraKeysHCL is used by hcl to surface unexpected keys
    42  	ExtraKeysHCL []string `hcl:",unusedKeys" json:"-"`
    43  }
    44  
    45  // DefaultAutopilotConfig() returns the canonical defaults for the Nomad
    46  // `autopilot` configuration.
    47  func DefaultAutopilotConfig() *AutopilotConfig {
    48  	return &AutopilotConfig{
    49  		LastContactThreshold:    200 * time.Millisecond,
    50  		MaxTrailingLogs:         250,
    51  		ServerStabilizationTime: 10 * time.Second,
    52  	}
    53  }
    54  
    55  func (a *AutopilotConfig) Merge(b *AutopilotConfig) *AutopilotConfig {
    56  	result := a.Copy()
    57  
    58  	if b.CleanupDeadServers != nil {
    59  		result.CleanupDeadServers = helper.BoolToPtr(*b.CleanupDeadServers)
    60  	}
    61  	if b.ServerStabilizationTime != 0 {
    62  		result.ServerStabilizationTime = b.ServerStabilizationTime
    63  	}
    64  	if b.ServerStabilizationTimeHCL != "" {
    65  		result.ServerStabilizationTimeHCL = b.ServerStabilizationTimeHCL
    66  	}
    67  	if b.LastContactThreshold != 0 {
    68  		result.LastContactThreshold = b.LastContactThreshold
    69  	}
    70  	if b.LastContactThresholdHCL != "" {
    71  		result.LastContactThresholdHCL = b.LastContactThresholdHCL
    72  	}
    73  	if b.MaxTrailingLogs != 0 {
    74  		result.MaxTrailingLogs = b.MaxTrailingLogs
    75  	}
    76  	if b.EnableRedundancyZones != nil {
    77  		result.EnableRedundancyZones = b.EnableRedundancyZones
    78  	}
    79  	if b.DisableUpgradeMigration != nil {
    80  		result.DisableUpgradeMigration = helper.BoolToPtr(*b.DisableUpgradeMigration)
    81  	}
    82  	if b.EnableCustomUpgrades != nil {
    83  		result.EnableCustomUpgrades = b.EnableCustomUpgrades
    84  	}
    85  
    86  	return result
    87  }
    88  
    89  // Copy returns a copy of this Autopilot config.
    90  func (a *AutopilotConfig) Copy() *AutopilotConfig {
    91  	if a == nil {
    92  		return nil
    93  	}
    94  
    95  	nc := new(AutopilotConfig)
    96  	*nc = *a
    97  
    98  	// Copy the bools
    99  	if a.CleanupDeadServers != nil {
   100  		nc.CleanupDeadServers = helper.BoolToPtr(*a.CleanupDeadServers)
   101  	}
   102  	if a.EnableRedundancyZones != nil {
   103  		nc.EnableRedundancyZones = helper.BoolToPtr(*a.EnableRedundancyZones)
   104  	}
   105  	if a.DisableUpgradeMigration != nil {
   106  		nc.DisableUpgradeMigration = helper.BoolToPtr(*a.DisableUpgradeMigration)
   107  	}
   108  	if a.EnableCustomUpgrades != nil {
   109  		nc.EnableCustomUpgrades = helper.BoolToPtr(*a.EnableCustomUpgrades)
   110  	}
   111  
   112  	return nc
   113  }