Skip to content

Commit

Permalink
Merge pull request #3978 from hashicorp/b-core-sched
Browse files Browse the repository at this point in the history
Always add core scheduler
  • Loading branch information
dadgar committed Mar 14, 2018
2 parents 7f2caf5 + 3840ffd commit 66f85b2
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ BUG FIXES:
* client: Improve auto-detection of network interface when interface name has a
space in it on Windows [[GH-3855](https://github.com/hashicorp/nomad/issues/3855)]
* client/vault: Recognize renewing non-renewable Vault lease as fatal [[GH-3727](https://github.com/hashicorp/nomad/issues/3727)]
* config: Revert minimum CPU limit back to 20 from 100.
* config: Revert minimum CPU limit back to 20 from 100 [[GH-3706](https://github.com/hashicorp/nomad/issues/3706)]
* config: Always add core scheduler to enabled schedulers and add invalid
EnabledScheduler detection [[GH-3978](https://github.com/hashicorp/nomad/issues/3978)]
* driver/exec: Properly disable swapping [[GH-3958](https://github.com/hashicorp/nomad/issues/3958)]
* driver/lxc: Cleanup LXC containers after errors on container startup. [[GH-3773](https://github.com/hashicorp/nomad/issues/3773)]
* ui: Fix ui on non-leaders when ACLs are enabled [[GH-3722](https://github.com/hashicorp/nomad/issues/3722)]
Expand Down
15 changes: 14 additions & 1 deletion command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,20 @@ func convertServerConfig(agentConfig *Config, logOutput io.Writer) (*nomad.Confi
conf.NumSchedulers = agentConfig.Server.NumSchedulers
}
if len(agentConfig.Server.EnabledSchedulers) != 0 {
conf.EnabledSchedulers = agentConfig.Server.EnabledSchedulers
// Convert to a set and require the core scheduler
set := make(map[string]struct{}, 4)
set[structs.JobTypeCore] = struct{}{}
for _, sched := range agentConfig.Server.EnabledSchedulers {
set[sched] = struct{}{}
}

schedulers := make([]string, 0, len(set))
for k := range set {
schedulers = append(schedulers, k)
}

conf.EnabledSchedulers = schedulers

}
if agentConfig.ACL.Enabled {
conf.ACLEnabled = true
Expand Down
17 changes: 17 additions & 0 deletions nomad/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/hashicorp/nomad/nomad/state"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/nomad/structs/config"
"github.com/hashicorp/nomad/scheduler"
"github.com/hashicorp/raft"
raftboltdb "github.com/hashicorp/raft-boltdb"
"github.com/hashicorp/serf/serf"
Expand Down Expand Up @@ -1193,6 +1194,22 @@ func (s *Server) setupWorkers() error {
return nil
}

// Check if the core scheduler is not enabled
foundCore := false
for _, sched := range s.config.EnabledSchedulers {
if sched == structs.JobTypeCore {
foundCore = true
continue
}

if _, ok := scheduler.BuiltinSchedulers[sched]; !ok {
return fmt.Errorf("invalid configuration: unknown scheduler %q in enabled schedulers", sched)
}
}
if !foundCore {
return fmt.Errorf("invalid configuration: %q scheduler not enabled", structs.JobTypeCore)
}

// Start the workers
for i := 0; i < s.config.NumSchedulers; i++ {
if w, err := NewWorker(s); err != nil {
Expand Down
27 changes: 27 additions & 0 deletions nomad/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ package nomad
import (
"fmt"
"io/ioutil"
"log"
"os"
"path"
"strings"
"testing"
"time"

msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc"
"github.com/hashicorp/nomad/command/agent/consul"
"github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/nomad/structs/config"
"github.com/hashicorp/nomad/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func tmpDir(t *testing.T) string {
Expand Down Expand Up @@ -412,3 +416,26 @@ func TestServer_Reload_TLSConnections_Raft(t *testing.T) {

testutil.WaitForLeader(t, s2.RPC)
}

func TestServer_InvalidSchedulers(t *testing.T) {
t.Parallel()
require := require.New(t)

config := DefaultConfig()
config.DevMode = true
config.LogOutput = testlog.NewWriter(t)
logger := log.New(config.LogOutput, "", log.LstdFlags)
catalog := consul.NewMockCatalog(logger)

// Set the config to not have the core scheduler
config.EnabledSchedulers = []string{"batch"}
_, err := NewServer(config, catalog, logger)
require.NotNil(err)
require.Contains(err.Error(), "scheduler not enabled")

// Set the config to have an unknown scheduler
config.EnabledSchedulers = []string{"batch", structs.JobTypeCore, "foo"}
_, err = NewServer(config, catalog, logger)
require.NotNil(err)
require.Contains(err.Error(), "foo")
}

0 comments on commit 66f85b2

Please sign in to comment.