From 1186d77133ce132276160b53c43cbb6e0e15628d Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Tue, 4 Jun 2019 15:41:40 -0700 Subject: [PATCH] nomad: disable service+batch preemption by default Enterprise only. Disable preemption for service and batch jobs by default. Maintain backward compatibility in a x.y.Z release. Consider switching the default for new clusters in the future. --- command/agent/operator_endpoint_test.go | 6 ++++-- internal/testing/apitests/operator_test.go | 25 ++++++++++++++++++---- nomad/leader.go | 4 ++-- website/source/api/operator.html.md | 20 ++++++++--------- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/command/agent/operator_endpoint_test.go b/command/agent/operator_endpoint_test.go index 2c5222334..3ad499c14 100644 --- a/command/agent/operator_endpoint_test.go +++ b/command/agent/operator_endpoint_test.go @@ -271,9 +271,11 @@ func TestOperator_SchedulerGetConfiguration(t *testing.T) { require.Equal(200, resp.Code) out, ok := obj.(structs.SchedulerConfigurationResponse) require.True(ok) + + // Only system jobs can preempt other jobs by default. require.True(out.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled) - require.True(out.SchedulerConfig.PreemptionConfig.BatchSchedulerEnabled) - require.True(out.SchedulerConfig.PreemptionConfig.ServiceSchedulerEnabled) + require.False(out.SchedulerConfig.PreemptionConfig.BatchSchedulerEnabled) + require.False(out.SchedulerConfig.PreemptionConfig.ServiceSchedulerEnabled) }) } diff --git a/internal/testing/apitests/operator_test.go b/internal/testing/apitests/operator_test.go index 95104b40e..c381922ef 100644 --- a/internal/testing/apitests/operator_test.go +++ b/internal/testing/apitests/operator_test.go @@ -22,9 +22,17 @@ func TestAPI_OperatorSchedulerGetSetConfiguration(t *testing.T) { r.Check(err) }) require.True(config.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled) + require.False(config.SchedulerConfig.PreemptionConfig.BatchSchedulerEnabled) + require.False(config.SchedulerConfig.PreemptionConfig.ServiceSchedulerEnabled) // Change a config setting - newConf := &api.SchedulerConfiguration{PreemptionConfig: api.PreemptionConfig{SystemSchedulerEnabled: false, BatchSchedulerEnabled: false}} + newConf := &api.SchedulerConfiguration{ + PreemptionConfig: api.PreemptionConfig{ + SystemSchedulerEnabled: false, + BatchSchedulerEnabled: true, + ServiceSchedulerEnabled: true, + }, + } resp, wm, err := operator.SchedulerSetConfiguration(newConf, nil) require.Nil(err) require.NotZero(wm.LastIndex) @@ -33,7 +41,8 @@ func TestAPI_OperatorSchedulerGetSetConfiguration(t *testing.T) { config, _, err = operator.SchedulerGetConfiguration(nil) require.Nil(err) require.False(config.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled) - require.False(config.SchedulerConfig.PreemptionConfig.BatchSchedulerEnabled) + require.True(config.SchedulerConfig.PreemptionConfig.BatchSchedulerEnabled) + require.True(config.SchedulerConfig.PreemptionConfig.ServiceSchedulerEnabled) } func TestAPI_OperatorSchedulerCASConfiguration(t *testing.T) { @@ -50,11 +59,13 @@ func TestAPI_OperatorSchedulerCASConfiguration(t *testing.T) { r.Check(err) }) require.True(config.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled) + require.False(config.SchedulerConfig.PreemptionConfig.BatchSchedulerEnabled) + require.False(config.SchedulerConfig.PreemptionConfig.ServiceSchedulerEnabled) // Pass an invalid ModifyIndex { newConf := &api.SchedulerConfiguration{ - PreemptionConfig: api.PreemptionConfig{SystemSchedulerEnabled: false, BatchSchedulerEnabled: false}, + PreemptionConfig: api.PreemptionConfig{SystemSchedulerEnabled: false, BatchSchedulerEnabled: true}, ModifyIndex: config.SchedulerConfig.ModifyIndex - 1, } resp, wm, err := operator.SchedulerCASConfiguration(newConf, nil) @@ -66,7 +77,7 @@ func TestAPI_OperatorSchedulerCASConfiguration(t *testing.T) { // Pass a valid ModifyIndex { newConf := &api.SchedulerConfiguration{ - PreemptionConfig: api.PreemptionConfig{SystemSchedulerEnabled: false, BatchSchedulerEnabled: false}, + PreemptionConfig: api.PreemptionConfig{SystemSchedulerEnabled: false, BatchSchedulerEnabled: true}, ModifyIndex: config.SchedulerConfig.ModifyIndex, } resp, wm, err := operator.SchedulerCASConfiguration(newConf, nil) @@ -74,4 +85,10 @@ func TestAPI_OperatorSchedulerCASConfiguration(t *testing.T) { require.NotZero(wm.LastIndex) require.True(resp.Updated) } + + config, _, err := operator.SchedulerGetConfiguration(nil) + require.Nil(err) + require.False(config.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled) + require.True(config.SchedulerConfig.PreemptionConfig.BatchSchedulerEnabled) + require.False(config.SchedulerConfig.PreemptionConfig.ServiceSchedulerEnabled) } diff --git a/nomad/leader.go b/nomad/leader.go index 9ead8a221..6a27c78dd 100644 --- a/nomad/leader.go +++ b/nomad/leader.go @@ -48,8 +48,8 @@ var minSchedulerConfigVersion = version.Must(version.NewVersion("0.9.0")) var defaultSchedulerConfig = &structs.SchedulerConfiguration{ PreemptionConfig: structs.PreemptionConfig{ SystemSchedulerEnabled: true, - BatchSchedulerEnabled: true, - ServiceSchedulerEnabled: true, + BatchSchedulerEnabled: false, + ServiceSchedulerEnabled: false, }, } diff --git a/website/source/api/operator.html.md b/website/source/api/operator.html.md index e2e35d4e5..c2651e4a5 100644 --- a/website/source/api/operator.html.md +++ b/website/source/api/operator.html.md @@ -364,8 +364,8 @@ $ curl \ "ModifyIndex": 5, "PreemptionConfig": { "SystemSchedulerEnabled": true, - "BatchSchedulerEnabled": true, - "ServiceSchedulerEnabled": true, + "BatchSchedulerEnabled": false, + "ServiceSchedulerEnabled": false } } } @@ -381,10 +381,10 @@ $ curl \ - `PreemptionConfig` `(PreemptionConfig)` - Options to enable preemption for various schedulers. - `SystemSchedulerEnabled` `(bool: true)` - Specifies whether preemption for system jobs is enabled. Note that this defaults to true. - - `BatchSchedulerEnabled` 0.9.2 `(bool: true)` (Enterprise Only) - Specifies whether preemption for batch jobs is enabled. Note that - this defaults to true. - - `ServiceSchedulerEnabled` 0.9.2 `(bool: true)` (Enterprise Only) - Specifies whether preemption for service jobs is enabled. Note that - this defaults to true. + - `BatchSchedulerEnabled` 0.9.2 `(bool: false)` (Enterprise Only) - Specifies whether preemption for batch jobs is enabled. Note that + this defaults to false and must be explicitly enabled. + - `ServiceSchedulerEnabled` 0.9.2 `(bool: false)` (Enterprise Only) - Specifies whether preemption for service jobs is enabled. Note that + this defaults to false and must be explicitly enabled. - `CreateIndex` - The Raft index at which the config was created. - `ModifyIndex` - The Raft index at which the config was modified. @@ -415,9 +415,9 @@ The table below shows this endpoint's support for ```json { "PreemptionConfig": { - "SystemSchedulerEnabled": false, + "SystemSchedulerEnabled": true, "BatchSchedulerEnabled": false, - "ServiceSchedulerEnabled": true, + "ServiceSchedulerEnabled": true } } ``` @@ -425,7 +425,7 @@ The table below shows this endpoint's support for - `PreemptionConfig` `(PreemptionConfig)` - Options to enable preemption for various schedulers. - `SystemSchedulerEnabled` `(bool: true)` - Specifies whether preemption for system jobs is enabled. Note that if this is set to true, then system jobs can preempt any other jobs. - - `BatchSchedulerEnabled` 0.9.2 `(bool: true)` (Enterprise Only) - Specifies whether preemption for batch jobs is enabled. Note that + - `BatchSchedulerEnabled` 0.9.2 `(bool: false)` (Enterprise Only) - Specifies whether preemption for batch jobs is enabled. Note that if this is set to true, then batch jobs can preempt any other jobs. - - `ServiceSchedulerEnabled` 0.9.2 `(bool: true)` (Enterprise Only) - Specifies whether preemption for service jobs is enabled. Note that + - `ServiceSchedulerEnabled` 0.9.2 `(bool: false)` (Enterprise Only) - Specifies whether preemption for service jobs is enabled. Note that if this is set to true, then service jobs can preempt any other jobs.