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

Add config to disable preemption for batch/service jobs #5628

Merged
merged 2 commits into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions api/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ type SchedulerSetConfigurationResponse struct {
// PreemptionConfig specifies whether preemption is enabled based on scheduler type
type PreemptionConfig struct {
SystemSchedulerEnabled bool
BatchEnabled bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be Batch/ServiceSchedulerEnabled so as to match the SystemScheduledEnabled option?

ServiceEnabled bool
}

// SchedulerGetConfiguration is used to query the current Scheduler configuration.
Expand Down
5 changes: 4 additions & 1 deletion command/agent/operator_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ func (s *HTTPServer) schedulerUpdateConfig(resp http.ResponseWriter, req *http.R
}

args.Config = structs.SchedulerConfiguration{
PreemptionConfig: structs.PreemptionConfig{SystemSchedulerEnabled: conf.PreemptionConfig.SystemSchedulerEnabled},
PreemptionConfig: structs.PreemptionConfig{
SystemSchedulerEnabled: conf.PreemptionConfig.SystemSchedulerEnabled,
BatchEnabled: conf.PreemptionConfig.BatchEnabled,
ServiceEnabled: conf.PreemptionConfig.ServiceEnabled},
}

// Check for cas value
Expand Down
17 changes: 13 additions & 4 deletions command/agent/operator_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ func TestOperator_SchedulerGetConfiguration(t *testing.T) {
out, ok := obj.(structs.SchedulerConfigurationResponse)
require.True(ok)
require.True(out.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled)
require.True(out.SchedulerConfig.PreemptionConfig.BatchEnabled)
require.True(out.SchedulerConfig.PreemptionConfig.ServiceEnabled)
})
}

Expand All @@ -280,7 +282,8 @@ func TestOperator_SchedulerSetConfiguration(t *testing.T) {
httpTest(t, nil, func(s *TestAgent) {
require := require.New(t)
body := bytes.NewBuffer([]byte(`{"PreemptionConfig": {
"SystemSchedulerEnabled": true
"SystemSchedulerEnabled": true,
"ServiceEnabled": true
}}`))
req, _ := http.NewRequest("PUT", "/v1/operator/scheduler/configuration", body)
resp := httptest.NewRecorder()
Expand All @@ -301,6 +304,7 @@ func TestOperator_SchedulerSetConfiguration(t *testing.T) {
err = s.RPC("Operator.SchedulerGetConfiguration", &args, &reply)
require.Nil(err)
require.True(reply.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled)
require.True(reply.SchedulerConfig.PreemptionConfig.ServiceEnabled)
})
}

Expand All @@ -309,7 +313,8 @@ func TestOperator_SchedulerCASConfiguration(t *testing.T) {
httpTest(t, nil, func(s *TestAgent) {
require := require.New(t)
body := bytes.NewBuffer([]byte(`{"PreemptionConfig": {
"SystemSchedulerEnabled": true
"SystemSchedulerEnabled": true,
"BatchEnabled":true
}}`))
req, _ := http.NewRequest("PUT", "/v1/operator/scheduler/configuration", body)
resp := httptest.NewRecorder()
Expand All @@ -331,11 +336,13 @@ func TestOperator_SchedulerCASConfiguration(t *testing.T) {
t.Fatalf("err: %v", err)
}
require.True(reply.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled)
require.True(reply.SchedulerConfig.PreemptionConfig.BatchEnabled)

// Create a CAS request, bad index
{
buf := bytes.NewBuffer([]byte(`{"PreemptionConfig": {
"SystemSchedulerEnabled": false
"SystemSchedulerEnabled": false,
"BatchEnabled":true
}}`))
req, _ := http.NewRequest("PUT", fmt.Sprintf("/v1/operator/scheduler/configuration?cas=%d", reply.QueryMeta.Index-1), buf)
resp := httptest.NewRecorder()
Expand All @@ -351,7 +358,8 @@ func TestOperator_SchedulerCASConfiguration(t *testing.T) {
// Create a CAS request, good index
{
buf := bytes.NewBuffer([]byte(`{"PreemptionConfig": {
"SystemSchedulerEnabled": false
"SystemSchedulerEnabled": false,
"BatchEnabled":false
}}`))
req, _ := http.NewRequest("PUT", fmt.Sprintf("/v1/operator/scheduler/configuration?cas=%d", reply.QueryMeta.Index), buf)
resp := httptest.NewRecorder()
Expand All @@ -369,5 +377,6 @@ func TestOperator_SchedulerCASConfiguration(t *testing.T) {
t.Fatalf("err: %v", err)
}
require.False(reply.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled)
require.False(reply.SchedulerConfig.PreemptionConfig.BatchEnabled)
})
}
7 changes: 5 additions & 2 deletions nomad/fsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2971,11 +2971,12 @@ func TestFSM_SchedulerConfig(t *testing.T) {

require := require.New(t)

// Set the autopilot config using a request.
// Set the scheduler config using a request.
req := structs.SchedulerSetConfigRequest{
Config: structs.SchedulerConfiguration{
PreemptionConfig: structs.PreemptionConfig{
SystemSchedulerEnabled: true,
BatchEnabled: true,
},
},
}
Expand All @@ -2992,10 +2993,11 @@ func TestFSM_SchedulerConfig(t *testing.T) {
require.Nil(err)

require.Equal(config.PreemptionConfig.SystemSchedulerEnabled, req.Config.PreemptionConfig.SystemSchedulerEnabled)
require.Equal(config.PreemptionConfig.BatchEnabled, req.Config.PreemptionConfig.BatchEnabled)

// Now use CAS and provide an old index
req.CAS = true
req.Config.PreemptionConfig = structs.PreemptionConfig{SystemSchedulerEnabled: false}
req.Config.PreemptionConfig = structs.PreemptionConfig{SystemSchedulerEnabled: false, BatchEnabled: false}
req.Config.ModifyIndex = config.ModifyIndex - 1
buf, err = structs.Encode(structs.SchedulerConfigRequestType, req)
require.Nil(err)
Expand All @@ -3009,4 +3011,5 @@ func TestFSM_SchedulerConfig(t *testing.T) {
require.Nil(err)
// Verify that preemption is still enabled
require.True(config.PreemptionConfig.SystemSchedulerEnabled)
require.True(config.PreemptionConfig.BatchEnabled)
}
2 changes: 2 additions & 0 deletions nomad/leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ var minSchedulerConfigVersion = version.Must(version.NewVersion("0.9.0"))
var defaultSchedulerConfig = &structs.SchedulerConfiguration{
PreemptionConfig: structs.PreemptionConfig{
SystemSchedulerEnabled: true,
BatchEnabled: true,
ServiceEnabled: true,
},
}

Expand Down
6 changes: 6 additions & 0 deletions nomad/structs/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ type SchedulerSetConfigurationResponse struct {
type PreemptionConfig struct {
// SystemSchedulerEnabled specifies if preemption is enabled for system jobs
SystemSchedulerEnabled bool

// BatchEnabled specifies if preemption is enabled for batch jobs
BatchEnabled bool

// ServiceEnabled specifies if preemption is enabled for service jobs
ServiceEnabled bool
}

// SchedulerSetConfigRequest is used by the Operator endpoint to update the
Expand Down