github.com/emate/nomad@v0.8.2-wo-binpacking/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 `mapstructure:"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 `mapstructure:"server_stabilization_time"`
    18  
    19  	// LastContactThreshold is the limit on the amount of time a server can go
    20  	// without leader contact before being considered unhealthy.
    21  	LastContactThreshold time.Duration `mapstructure:"last_contact_threshold"`
    22  
    23  	// MaxTrailingLogs is the amount of entries in the Raft Log that a server can
    24  	// be behind before being considered unhealthy.
    25  	MaxTrailingLogs int `mapstructure:"max_trailing_logs"`
    26  
    27  	// (Enterprise-only) EnableRedundancyZones specifies whether to enable redundancy zones.
    28  	EnableRedundancyZones *bool `mapstructure:"enable_redundancy_zones"`
    29  
    30  	// (Enterprise-only) DisableUpgradeMigration will disable Autopilot's upgrade migration
    31  	// strategy of waiting until enough newer-versioned servers have been added to the
    32  	// cluster before promoting them to voters.
    33  	DisableUpgradeMigration *bool `mapstructure:"disable_upgrade_migration"`
    34  
    35  	// (Enterprise-only) EnableCustomUpgrades specifies whether to enable using custom
    36  	// upgrade versions when performing migrations.
    37  	EnableCustomUpgrades *bool `mapstructure:"enable_custom_upgrades"`
    38  }
    39  
    40  // DefaultAutopilotConfig() returns the canonical defaults for the Nomad
    41  // `autopilot` configuration.
    42  func DefaultAutopilotConfig() *AutopilotConfig {
    43  	return &AutopilotConfig{
    44  		LastContactThreshold:    200 * time.Millisecond,
    45  		MaxTrailingLogs:         250,
    46  		ServerStabilizationTime: 10 * time.Second,
    47  	}
    48  }
    49  
    50  func (a *AutopilotConfig) Merge(b *AutopilotConfig) *AutopilotConfig {
    51  	result := a.Copy()
    52  
    53  	if b.CleanupDeadServers != nil {
    54  		result.CleanupDeadServers = helper.BoolToPtr(*b.CleanupDeadServers)
    55  	}
    56  	if b.ServerStabilizationTime != 0 {
    57  		result.ServerStabilizationTime = b.ServerStabilizationTime
    58  	}
    59  	if b.LastContactThreshold != 0 {
    60  		result.LastContactThreshold = b.LastContactThreshold
    61  	}
    62  	if b.MaxTrailingLogs != 0 {
    63  		result.MaxTrailingLogs = b.MaxTrailingLogs
    64  	}
    65  	if b.EnableRedundancyZones != nil {
    66  		result.EnableRedundancyZones = b.EnableRedundancyZones
    67  	}
    68  	if b.DisableUpgradeMigration != nil {
    69  		result.DisableUpgradeMigration = helper.BoolToPtr(*b.DisableUpgradeMigration)
    70  	}
    71  	if b.EnableCustomUpgrades != nil {
    72  		result.EnableCustomUpgrades = b.EnableCustomUpgrades
    73  	}
    74  
    75  	return result
    76  }
    77  
    78  // Copy returns a copy of this Autopilot config.
    79  func (a *AutopilotConfig) Copy() *AutopilotConfig {
    80  	if a == nil {
    81  		return nil
    82  	}
    83  
    84  	nc := new(AutopilotConfig)
    85  	*nc = *a
    86  
    87  	// Copy the bools
    88  	if a.CleanupDeadServers != nil {
    89  		nc.CleanupDeadServers = helper.BoolToPtr(*a.CleanupDeadServers)
    90  	}
    91  	if a.EnableRedundancyZones != nil {
    92  		nc.EnableRedundancyZones = helper.BoolToPtr(*a.EnableRedundancyZones)
    93  	}
    94  	if a.DisableUpgradeMigration != nil {
    95  		nc.DisableUpgradeMigration = helper.BoolToPtr(*a.DisableUpgradeMigration)
    96  	}
    97  	if a.EnableCustomUpgrades != nil {
    98  		nc.EnableCustomUpgrades = helper.BoolToPtr(*a.EnableCustomUpgrades)
    99  	}
   100  
   101  	return nc
   102  }