Support customizing full scheduler config

This commit is contained in:
Mahmood Ali
2020-01-28 11:09:36 -05:00
parent 744c9a485d
commit 31025d6cac
6 changed files with 70 additions and 36 deletions

View File

@@ -323,10 +323,8 @@ func convertServerConfig(agentConfig *Config) (*nomad.Config, error) {
}
// handle system scheduler preemption default
if agentConfig.Server.SystemSchedulerPreemptionEnabledDefault != nil {
conf.SystemSchedulerPreemptionEnabledDefault = *agentConfig.Server.SystemSchedulerPreemptionEnabledDefault
} else {
conf.SystemSchedulerPreemptionEnabledDefault = true
if agentConfig.Server.DefaultSchedulerConfig != nil {
conf.DefaultSchedulerConfig = *agentConfig.Server.DefaultSchedulerConfig
}
// Add the Consul and Vault configs

View File

@@ -1,7 +1,6 @@
package agent
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
@@ -277,18 +276,51 @@ func TestAgent_ServerConfig(t *testing.T) {
func TestAgent_ServerConfig_SchedulerFlags(t *testing.T) {
cases := []struct {
input *bool
expected bool
name string
input *structs.SchedulerConfiguration
expected structs.SchedulerConfiguration
}{
{nil, true},
{helper.BoolToPtr(false), false},
{helper.BoolToPtr(true), true},
{
"default case",
nil,
structs.SchedulerConfiguration{
PreemptionConfig: structs.PreemptionConfig{
SystemSchedulerEnabled: true,
},
},
},
{
"empty value: preemption is disabled",
&structs.SchedulerConfiguration{},
structs.SchedulerConfiguration{
PreemptionConfig: structs.PreemptionConfig{
SystemSchedulerEnabled: false,
},
},
},
{
"all explicitly set",
&structs.SchedulerConfiguration{
PreemptionConfig: structs.PreemptionConfig{
SystemSchedulerEnabled: true,
BatchSchedulerEnabled: true,
ServiceSchedulerEnabled: true,
},
},
structs.SchedulerConfiguration{
PreemptionConfig: structs.PreemptionConfig{
SystemSchedulerEnabled: true,
BatchSchedulerEnabled: true,
ServiceSchedulerEnabled: true,
},
},
},
}
for _, c := range cases {
t.Run(fmt.Sprintf("case: %v", c.input), func(t *testing.T) {
t.Run(c.name, func(t *testing.T) {
conf := DefaultConfig()
conf.Server.SystemSchedulerPreemptionEnabledDefault = c.input
conf.Server.DefaultSchedulerConfig = c.input
a := &Agent{config: conf}
conf.AdvertiseAddrs.Serf = "127.0.0.1:4000"
@@ -299,7 +331,7 @@ func TestAgent_ServerConfig_SchedulerFlags(t *testing.T) {
out, err := a.serverConfig()
require.NoError(t, err)
require.Equal(t, c.expected, out.SystemSchedulerPreemptionEnabledDefault)
require.Equal(t, c.expected, out.DefaultSchedulerConfig)
})
}
}

View File

@@ -444,8 +444,10 @@ type ServerConfig struct {
// ServerJoin contains information that is used to attempt to join servers
ServerJoin *ServerJoin `hcl:"server_join"`
// SystemSchedulerPreemptionEnabledDefault is used to determin whether to enable system preemption by default in a new cluster
SystemSchedulerPreemptionEnabledDefault *bool `hcl:"system_scheduler_preemption_enabled_default"`
// DefaultSchedulerConfig configures the initial scheduler config to be persisted in Raft.
// Once the cluster is bootstrapped, and Raft persists the config (from here or through API),
// This value is ignored.
DefaultSchedulerConfig *structs.SchedulerConfiguration `hcl:"default_scheduler_config"`
// ExtraKeysHCL is used by hcl to surface unexpected keys
ExtraKeysHCL []string `hcl:",unusedKeys" json:"-"`
@@ -1340,6 +1342,11 @@ func (a *ServerConfig) Merge(b *ServerConfig) *ServerConfig {
result.ServerJoin = result.ServerJoin.Merge(b.ServerJoin)
}
if b.DefaultSchedulerConfig != nil {
c := *b.DefaultSchedulerConfig
result.DefaultSchedulerConfig = &c
}
// Add the schedulers
result.EnabledSchedulers = append(result.EnabledSchedulers, b.EnabledSchedulers...)