mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
handle upgrade path and defaults
Ensure that `""` Scheduler Algorithm gets explicitly set to binpack on upgrades or on API handling when user misses the value. The scheduler already treats `""` value as binpack. This PR merely ensures that the operator API returns the effective value.
This commit is contained in:
@@ -285,6 +285,8 @@ func (c *Command) readConfig() *Config {
|
||||
config.PluginDir = filepath.Join(config.DataDir, "plugins")
|
||||
}
|
||||
|
||||
config.Server.DefaultSchedulerConfig.Canonicalize()
|
||||
|
||||
if !c.isValidConfig(config, cmdConfig) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1120,6 +1120,8 @@ func (n *nomadFSM) applySchedulerConfigUpdate(buf []byte, index uint64) interfac
|
||||
}
|
||||
defer metrics.MeasureSince([]string{"nomad", "fsm", "apply_scheduler_config"}, time.Now())
|
||||
|
||||
req.Config.Canonicalize()
|
||||
|
||||
if req.CAS {
|
||||
applied, err := n.state.SchedulerCASConfig(index, req.Config.ModifyIndex, &req.Config)
|
||||
if err != nil {
|
||||
@@ -1417,6 +1419,7 @@ func (n *nomadFSM) Restore(old io.ReadCloser) error {
|
||||
if err := dec.Decode(schedConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
schedConfig.Canonicalize()
|
||||
if err := restore.SchedulerConfigRestore(schedConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2823,6 +2823,7 @@ func TestFSM_SnapshotRestore_SchedulerConfiguration(t *testing.T) {
|
||||
fsm := testFSM(t)
|
||||
state := fsm.State()
|
||||
schedConfig := &structs.SchedulerConfiguration{
|
||||
SchedulerAlgorithm: "spread",
|
||||
PreemptionConfig: structs.PreemptionConfig{
|
||||
SystemSchedulerEnabled: true,
|
||||
},
|
||||
|
||||
@@ -162,6 +162,12 @@ func (s *SchedulerConfiguration) EffectiveSchedulerAlgorithm() SchedulerAlgorith
|
||||
return s.SchedulerAlgorithm
|
||||
}
|
||||
|
||||
func (s *SchedulerConfiguration) Canonicalize() {
|
||||
if s != nil && s.SchedulerAlgorithm == "" {
|
||||
s.SchedulerAlgorithm = SchedulerAlgorithmBinpack
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SchedulerConfiguration) Validate() error {
|
||||
if s == nil {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user