Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update consul vendor and add MinQuorum flag #7171

Merged
merged 3 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/operator_autopilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ type AutopilotConfiguration struct {
// be behind before being considered unhealthy.
MaxTrailingLogs uint64

// MinQuorum sets the minimum number of servers allowed in a cluster before
// autopilot can prune dead servers.
MinQuorum uint

// 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.
Expand Down
2 changes: 1 addition & 1 deletion client/allocrunner/groupservice_hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

consulapi "github.com/hashicorp/consul/api"
ctestutil "github.com/hashicorp/consul/testutil"
ctestutil "github.com/hashicorp/consul/sdk/testutil"
"github.com/hashicorp/nomad/client/allocrunner/interfaces"
"github.com/hashicorp/nomad/client/consul"
"github.com/hashicorp/nomad/client/taskenv"
Expand Down
2 changes: 1 addition & 1 deletion client/allocrunner/taskrunner/envoybootstrap_hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"testing"

consulapi "github.com/hashicorp/consul/api"
consultest "github.com/hashicorp/consul/testutil"
consultest "github.com/hashicorp/consul/sdk/testutil"
"github.com/hashicorp/nomad/client/allocdir"
"github.com/hashicorp/nomad/client/allocrunner/interfaces"
"github.com/hashicorp/nomad/client/taskenv"
Expand Down
2 changes: 1 addition & 1 deletion client/allocrunner/taskrunner/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"testing"
"time"

ctestutil "github.com/hashicorp/consul/testutil"
ctestutil "github.com/hashicorp/consul/sdk/testutil"
"github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/nomad/client/taskenv"
"github.com/hashicorp/nomad/helper"
Expand Down
3 changes: 3 additions & 0 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ func convertServerConfig(agentConfig *Config) (*nomad.Config, error) {
if agentConfig.Autopilot.MaxTrailingLogs != 0 {
conf.AutopilotConfig.MaxTrailingLogs = uint64(agentConfig.Autopilot.MaxTrailingLogs)
}
if agentConfig.Autopilot.MinQuorum != 0 {
conf.AutopilotConfig.MinQuorum = uint(agentConfig.Autopilot.MinQuorum)
}
if agentConfig.Autopilot.EnableRedundancyZones != nil {
conf.AutopilotConfig.EnableRedundancyZones = *agentConfig.Autopilot.EnableRedundancyZones
}
Expand Down
1 change: 1 addition & 0 deletions command/agent/config_parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ var basicConfig = &Config{
LastContactThreshold: 12705 * time.Second,
LastContactThresholdHCL: "12705s",
MaxTrailingLogs: 17849,
MinQuorum: 3,
EnableRedundancyZones: &trueValue,
DisableUpgradeMigration: &trueValue,
EnableCustomUpgrades: &trueValue,
Expand Down
2 changes: 2 additions & 0 deletions command/agent/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func TestConfig_Merge(t *testing.T) {
ServerStabilizationTime: 1 * time.Second,
LastContactThreshold: 1 * time.Second,
MaxTrailingLogs: 1,
MinQuorum: 1,
EnableRedundancyZones: &falseValue,
DisableUpgradeMigration: &falseValue,
EnableCustomUpgrades: &falseValue,
Expand Down Expand Up @@ -365,6 +366,7 @@ func TestConfig_Merge(t *testing.T) {
ServerStabilizationTime: 2 * time.Second,
LastContactThreshold: 2 * time.Second,
MaxTrailingLogs: 2,
MinQuorum: 2,
EnableRedundancyZones: &trueValue,
DisableUpgradeMigration: &trueValue,
EnableCustomUpgrades: &trueValue,
Expand Down
2 changes: 1 addition & 1 deletion command/agent/consul/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/hashicorp/consul/api"
consulapi "github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/testutil"
"github.com/hashicorp/consul/sdk/testutil"
"github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"
Expand Down
2 changes: 1 addition & 1 deletion command/agent/consul/int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"

consulapi "github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/testutil"
"github.com/hashicorp/consul/sdk/testutil"
log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/nomad/client/allocdir"
"github.com/hashicorp/nomad/client/allocrunner/taskrunner"
Expand Down
2 changes: 2 additions & 0 deletions command/agent/operator_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func (s *HTTPServer) OperatorAutopilotConfiguration(resp http.ResponseWriter, re
CleanupDeadServers: reply.CleanupDeadServers,
LastContactThreshold: reply.LastContactThreshold,
MaxTrailingLogs: reply.MaxTrailingLogs,
MinQuorum: reply.MinQuorum,
ServerStabilizationTime: reply.ServerStabilizationTime,
EnableRedundancyZones: reply.EnableRedundancyZones,
DisableUpgradeMigration: reply.DisableUpgradeMigration,
Expand All @@ -131,6 +132,7 @@ func (s *HTTPServer) OperatorAutopilotConfiguration(resp http.ResponseWriter, re
CleanupDeadServers: conf.CleanupDeadServers,
LastContactThreshold: conf.LastContactThreshold,
MaxTrailingLogs: conf.MaxTrailingLogs,
MinQuorum: conf.MinQuorum,
ServerStabilizationTime: conf.ServerStabilizationTime,
EnableRedundancyZones: conf.EnableRedundancyZones,
DisableUpgradeMigration: conf.DisableUpgradeMigration,
Expand Down
2 changes: 1 addition & 1 deletion command/agent/operator_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
"time"

"github.com/hashicorp/consul/testutil/retry"
"github.com/hashicorp/consul/sdk/testutil/retry"
"github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/stretchr/testify/assert"
Expand Down
1 change: 1 addition & 0 deletions command/agent/testdata/basic.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ autopilot {
disable_upgrade_migration = true
last_contact_threshold = "12705s"
max_trailing_logs = 17849
min_quorum = 3
enable_redundancy_zones = true
server_stabilization_time = "23057s"
enable_custom_upgrades = true
Expand Down
1 change: 1 addition & 0 deletions command/agent/testdata/basic.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"enable_redundancy_zones": true,
"last_contact_threshold": "12705s",
"max_trailing_logs": 17849,
"min_quorum": 3,
"server_stabilization_time": "23057s"
}
],
Expand Down
1 change: 1 addition & 0 deletions command/operator_autopilot_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (c *OperatorAutopilotGetCommand) Run(args []string) int {
c.Ui.Output(fmt.Sprintf("CleanupDeadServers = %v", config.CleanupDeadServers))
c.Ui.Output(fmt.Sprintf("LastContactThreshold = %v", config.LastContactThreshold.String()))
c.Ui.Output(fmt.Sprintf("MaxTrailingLogs = %v", config.MaxTrailingLogs))
c.Ui.Output(fmt.Sprintf("MinQuorum = %v", config.MinQuorum))
c.Ui.Output(fmt.Sprintf("ServerStabilizationTime = %v", config.ServerStabilizationTime.String()))
c.Ui.Output(fmt.Sprintf("EnableRedundancyZones = %v", config.EnableRedundancyZones))
c.Ui.Output(fmt.Sprintf("DisableUpgradeMigration = %v", config.DisableUpgradeMigration))
Expand Down
7 changes: 7 additions & 0 deletions command/operator_autopilot_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (c *OperatorAutopilotSetCommand) Name() string { return "operator autopilot
func (c *OperatorAutopilotSetCommand) Run(args []string) int {
var cleanupDeadServers flags.BoolValue
var maxTrailingLogs flags.UintValue
var minQuorum flags.UintValue
var lastContactThreshold flags.DurationValue
var serverStabilizationTime flags.DurationValue
var enableRedundancyZones flags.BoolValue
Expand All @@ -50,6 +51,7 @@ func (c *OperatorAutopilotSetCommand) Run(args []string) int {
f.Var(&enableRedundancyZones, "enable-redundancy-zones", "")
f.Var(&disableUpgradeMigration, "disable-upgrade-migration", "")
f.Var(&enableCustomUpgrades, "enable-custom-upgrades", "")
f.Var(&minQuorum, "min-quorum", "")

if err := f.Parse(args); err != nil {
c.Ui.Error(fmt.Sprintf("Failed to parse args: %v", err))
Expand Down Expand Up @@ -80,6 +82,7 @@ func (c *OperatorAutopilotSetCommand) Run(args []string) int {
trailing := uint(conf.MaxTrailingLogs)
maxTrailingLogs.Merge(&trailing)
conf.MaxTrailingLogs = uint64(trailing)
minQuorum.Merge(&conf.MinQuorum)
lastContactThreshold.Merge(&conf.LastContactThreshold)
serverStabilizationTime.Merge(&conf.ServerStabilizationTime)

Expand Down Expand Up @@ -131,6 +134,10 @@ Set Config Options:
Controls the maximum number of log entries that a server can trail
the leader by before being considered unhealthy.

-min-quorum=<value>
Controls the minimum number of servers required in a cluster
before autopilot can prune dead servers.

-redundancy-zone-tag=<value>
(Enterprise-only) Controls the node_meta tag name used for
separating servers into different redundancy zones.
Expand Down
2 changes: 2 additions & 0 deletions command/operator_autopilot_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestOperatorAutopilotSetConfigCommand(t *testing.T) {
"-address=" + addr,
"-cleanup-dead-servers=false",
"-max-trailing-logs=99",
"-min-quorum=3",
"-last-contact-threshold=123ms",
"-server-stabilization-time=123ms",
"-enable-redundancy-zones=true",
Expand All @@ -46,6 +47,7 @@ func TestOperatorAutopilotSetConfigCommand(t *testing.T) {

require.False(conf.CleanupDeadServers)
require.EqualValues(99, conf.MaxTrailingLogs)
require.EqualValues(3, conf.MinQuorum)
require.EqualValues(123*time.Millisecond, conf.LastContactThreshold)
require.EqualValues(123*time.Millisecond, conf.ServerStabilizationTime)
require.True(conf.EnableRedundancyZones)
Expand Down
2 changes: 1 addition & 1 deletion helper/freeport/freeport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sync"
"testing"

"github.com/hashicorp/consul/testutil/retry"
"github.com/hashicorp/consul/sdk/testutil/retry"
)

// reset will reverse the setup from initialize() and then redo it (for tests)
Expand Down
2 changes: 1 addition & 1 deletion internal/testing/apitests/operator_autopilot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"fmt"

"github.com/hashicorp/consul/testutil/retry"
"github.com/hashicorp/consul/sdk/testutil/retry"
"github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/testutil"
"github.com/stretchr/testify/require"
Expand Down
2 changes: 1 addition & 1 deletion internal/testing/apitests/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package apitests
import (
"testing"

"github.com/hashicorp/consul/testutil/retry"
"github.com/hashicorp/consul/sdk/testutil/retry"
"github.com/hashicorp/nomad/api"
"github.com/stretchr/testify/require"
)
Expand Down
8 changes: 7 additions & 1 deletion nomad/autopilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (d *AutopilotDelegate) AutopilotConfig() *autopilot.Config {
CleanupDeadServers: c.CleanupDeadServers,
LastContactThreshold: c.LastContactThreshold,
MaxTrailingLogs: c.MaxTrailingLogs,
MinQuorum: c.MinQuorum,
ServerStabilizationTime: c.ServerStabilizationTime,
DisableUpgradeMigration: c.DisableUpgradeMigration,
ModifyIndex: c.ModifyIndex,
Expand Down Expand Up @@ -96,6 +97,11 @@ func (d *AutopilotDelegate) Raft() *raft.Raft {
return d.server.raft
}

func (d *AutopilotDelegate) Serf() *serf.Serf {
func (d *AutopilotDelegate) SerfLAN() *serf.Serf {
return d.server.serf
}

func (d *AutopilotDelegate) SerfWAN() *serf.Serf {
// serf WAN isn't supported in nomad yet
return nil
}
2 changes: 1 addition & 1 deletion nomad/autopilot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"

"github.com/hashicorp/consul/agent/consul/autopilot"
"github.com/hashicorp/consul/testutil/retry"
"github.com/hashicorp/consul/sdk/testutil/retry"
"github.com/hashicorp/nomad/testutil"
"github.com/hashicorp/raft"
"github.com/hashicorp/serf/serf"
Expand Down
4 changes: 4 additions & 0 deletions nomad/fsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3033,6 +3033,7 @@ func TestFSM_Autopilot(t *testing.T) {
CleanupDeadServers: true,
LastContactThreshold: 10 * time.Second,
MaxTrailingLogs: 300,
MinQuorum: 3,
},
}
buf, err := structs.Encode(structs.AutopilotRequestType, req)
Expand All @@ -3058,6 +3059,9 @@ func TestFSM_Autopilot(t *testing.T) {
if config.MaxTrailingLogs != req.Config.MaxTrailingLogs {
t.Fatalf("bad: %v", config.MaxTrailingLogs)
}
if config.MinQuorum != req.Config.MinQuorum {
t.Fatalf("bad: %v", config.MinQuorum)
}

// Now use CAS and provide an old index
req.CAS = true
Expand Down
2 changes: 1 addition & 1 deletion nomad/leader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"
"time"

"github.com/hashicorp/consul/testutil/retry"
"github.com/hashicorp/consul/sdk/testutil/retry"
"github.com/hashicorp/go-hclog"
memdb "github.com/hashicorp/go-memdb"
"github.com/hashicorp/go-version"
Expand Down
3 changes: 1 addition & 2 deletions nomad/server_setup_oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ package nomad

import (
"github.com/hashicorp/consul/agent/consul/autopilot"
log "github.com/hashicorp/go-hclog"
)

type EnterpriseState struct{}

func (s *Server) setupEnterprise(config *Config) error {
// Set up the OSS version of autopilot
apDelegate := &AutopilotDelegate{s}
s.autopilot = autopilot.NewAutopilot(s.logger.StandardLoggerIntercept(&log.StandardLoggerOptions{InferLevels: true}), apDelegate, config.AutopilotInterval, config.ServerHealthInterval)
s.autopilot = autopilot.NewAutopilot(s.logger, apDelegate, config.AutopilotInterval, config.ServerHealthInterval)

return nil
}
Expand Down
1 change: 1 addition & 0 deletions nomad/state/autopilot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func TestStateStore_Autopilot(t *testing.T) {
CleanupDeadServers: true,
LastContactThreshold: 5 * time.Second,
MaxTrailingLogs: 500,
MinQuorum: 3,
ServerStabilizationTime: 100 * time.Second,
EnableRedundancyZones: true,
DisableUpgradeMigration: true,
Expand Down
7 changes: 7 additions & 0 deletions nomad/structs/config/autopilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ type AutopilotConfig struct {
// be behind before being considered unhealthy.
MaxTrailingLogs int `hcl:"max_trailing_logs"`

// MinQuorum sets the minimum number of servers required in a cluster
// before autopilot can prune dead servers.
MinQuorum int `hcl:"min_quorum"`

// (Enterprise-only) EnableRedundancyZones specifies whether to enable redundancy zones.
EnableRedundancyZones *bool `hcl:"enable_redundancy_zones"`

Expand Down Expand Up @@ -73,6 +77,9 @@ func (a *AutopilotConfig) Merge(b *AutopilotConfig) *AutopilotConfig {
if b.MaxTrailingLogs != 0 {
result.MaxTrailingLogs = b.MaxTrailingLogs
}
if b.MinQuorum != 0 {
result.MinQuorum = b.MinQuorum
}
if b.EnableRedundancyZones != nil {
result.EnableRedundancyZones = b.EnableRedundancyZones
}
Expand Down
3 changes: 3 additions & 0 deletions nomad/structs/config/autopilot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func TestAutopilotConfig_Merge(t *testing.T) {
ServerStabilizationTime: 1 * time.Second,
LastContactThreshold: 1 * time.Second,
MaxTrailingLogs: 1,
MinQuorum: 1,
EnableRedundancyZones: &trueValue,
DisableUpgradeMigration: &falseValue,
EnableCustomUpgrades: &trueValue,
Expand All @@ -24,6 +25,7 @@ func TestAutopilotConfig_Merge(t *testing.T) {
ServerStabilizationTime: 2 * time.Second,
LastContactThreshold: 2 * time.Second,
MaxTrailingLogs: 2,
MinQuorum: 2,
EnableRedundancyZones: nil,
DisableUpgradeMigration: nil,
EnableCustomUpgrades: nil,
Expand All @@ -34,6 +36,7 @@ func TestAutopilotConfig_Merge(t *testing.T) {
ServerStabilizationTime: 2 * time.Second,
LastContactThreshold: 2 * time.Second,
MaxTrailingLogs: 2,
MinQuorum: 2,
EnableRedundancyZones: &trueValue,
DisableUpgradeMigration: &falseValue,
EnableCustomUpgrades: &trueValue,
Expand Down
4 changes: 4 additions & 0 deletions nomad/structs/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ type AutopilotConfig struct {
// be behind before being considered unhealthy.
MaxTrailingLogs uint64

// MinQuorum sets the minimum number of servers required in a cluster
// before autopilot can prune dead servers.
MinQuorum uint

// (Enterprise-only) EnableRedundancyZones specifies whether to enable redundancy zones.
EnableRedundancyZones bool

Expand Down
Loading