Skip to content

Commit

Permalink
final review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasell committed Jul 1, 2022
1 parent 9177f83 commit f6c63f8
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 11 deletions.
6 changes: 3 additions & 3 deletions command/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ func (m *monitor) monitor(evalID string) int {
// Add the initial pending state
m.update(newEvalState())

m.ui.Info(fmt.Sprintf("%s: Monitoring evaluation %q",
formatTime(time.Now()), limit(evalID, m.length)))

for {
// Query the evaluation
eval, _, err := m.client.Evaluations().Info(evalID, nil)
Expand All @@ -194,9 +197,6 @@ func (m *monitor) monitor(evalID string) int {
return 1
}

m.ui.Info(fmt.Sprintf("%s: Monitoring evaluation %q",
formatTime(time.Now()), limit(eval.ID, m.length)))

// Create the new eval state.
state := newEvalState()
state.status = eval.Status
Expand Down
1 change: 1 addition & 0 deletions command/operator_scheduler_get_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func (o *OperatorSchedulerGetConfig) Run(args []string) int {
fmt.Sprintf("Preemption Service Scheduler|%v", schedConfig.PreemptionConfig.ServiceSchedulerEnabled),
fmt.Sprintf("Preemption Batch Scheduler|%v", schedConfig.PreemptionConfig.BatchSchedulerEnabled),
fmt.Sprintf("Preemption SysBatch Scheduler|%v", schedConfig.PreemptionConfig.SysBatchSchedulerEnabled),
fmt.Sprintf("Modify Index|%v", resp.SchedulerConfig.ModifyIndex),
}))
return 0
}
Expand Down
30 changes: 30 additions & 0 deletions command/operator_scheduler_set_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type OperatorSchedulerSetConfig struct {
// The scheduler configuration flags allow us to tell whether the user set
// a value or not. This means we can safely merge the current configuration
// with user supplied, selective updates.
checkIndex string
schedulerAlgorithm string
memoryOversubscription flagHelper.BoolValue
rejectJobRegistration flagHelper.BoolValue
Expand All @@ -32,6 +33,7 @@ type OperatorSchedulerSetConfig struct {
func (o *OperatorSchedulerSetConfig) AutocompleteFlags() complete.Flags {
return mergeAutocompleteFlags(o.Meta.AutocompleteFlags(FlagSetClient),
complete.Flags{
"-check-index": complete.PredictAnything,
"-scheduler-algorithm": complete.PredictSet(
string(api.SchedulerAlgorithmBinpack),
string(api.SchedulerAlgorithmSpread),
Expand All @@ -58,6 +60,7 @@ func (o *OperatorSchedulerSetConfig) Run(args []string) int {
flags := o.Meta.FlagSet("set-config", FlagSetClient)
flags.Usage = func() { o.Ui.Output(o.Help()) }

flags.StringVar(&o.checkIndex, "check-index", "", "")
flags.StringVar(&o.schedulerAlgorithm, "scheduler-algorithm", "", "")
flags.Var(&o.memoryOversubscription, "memory-oversubscription", "")
flags.Var(&o.rejectJobRegistration, "reject-job-registration", "")
Expand All @@ -78,15 +81,37 @@ func (o *OperatorSchedulerSetConfig) Run(args []string) int {
return 1
}

// Convert the check index string and handle any errors before adding this
// to our request. This parsing handles empty values correctly.
checkIndex, _, err := parseCheckIndex(o.checkIndex)
if err != nil {
o.Ui.Error(fmt.Sprintf("Error parsing check-index value %q: %v", o.checkIndex, err))
return 1
}

// Fetch the current configuration. This will be used as a base to merge
// user configuration onto.
resp, _, err := client.Operator().SchedulerGetConfiguration(nil)
if err != nil {
o.Ui.Error(fmt.Sprintf("Error querying for scheduler configuration: %s", err))
return 1
}

if checkIndex > 0 && resp.SchedulerConfig.ModifyIndex != checkIndex {
errMsg := fmt.Sprintf("check-index %v does not match does not match current state value %v",
checkIndex, resp.SchedulerConfig.ModifyIndex)
o.Ui.Error(fmt.Sprintf("Error performing check index set: %s", errMsg))
return 1
}

schedulerConfig := resp.SchedulerConfig

// Overwrite the modification index if the user supplied one, otherwise we
// use what was included within the read response.
if checkIndex > 0 {
schedulerConfig.ModifyIndex = checkIndex
}

// Merge the current configuration with any values set by the operator.
if o.schedulerAlgorithm != "" {
schedulerConfig.SchedulerAlgorithm = api.SchedulerAlgorithm(o.schedulerAlgorithm)
Expand Down Expand Up @@ -132,6 +157,11 @@ General Options:
Scheduler Set Config Options:
-check-index
If set, the scheduler config is only updated if the passed modify index
matches the current server side version. If a non-zero value is passed, it
ensures that the scheduler config is being updated from a known state.
-scheduler-algorithm=["binpack"|"spread"]
Specifies whether scheduler binpacks or spreads allocations on available
nodes.
Expand Down
23 changes: 23 additions & 0 deletions command/operator_scheduler_set_config_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package command

import (
"strconv"
"testing"

"github.com/hashicorp/nomad/api"
Expand Down Expand Up @@ -74,6 +75,28 @@ func TestOperatorSchedulerSetConfig_Run(t *testing.T) {
// returned.
require.EqualValues(t, 1, c.Run([]string{"-address=" + addr, "-pause-evil-broker=true"}))
require.Contains(t, ui.OutputWriter.String(), "Usage: nomad operator scheduler set-config")
ui.ErrorWriter.Reset()
ui.OutputWriter.Reset()

// Try updating the config using an incorrect check-index value.
require.EqualValues(t, 1, c.Run([]string{
"-address=" + addr,
"-pause-eval-broker=false",
"-check-index=1000000",
}))
require.Contains(t, ui.ErrorWriter.String(), "check-index 1000000 does not match does not match current state")
ui.ErrorWriter.Reset()
ui.OutputWriter.Reset()

// Try updating the config using a correct check-index value.
require.EqualValues(t, 0, c.Run([]string{
"-address=" + addr,
"-pause-eval-broker=false",
"-check-index=" + strconv.FormatUint(modifiedConfig.SchedulerConfig.ModifyIndex, 10),
}))
require.Contains(t, ui.OutputWriter.String(), "Scheduler configuration updated!")
ui.ErrorWriter.Reset()
ui.OutputWriter.Reset()
}

func schedulerConfigEquals(t *testing.T, expected, actual *api.SchedulerConfiguration) {
Expand Down
17 changes: 9 additions & 8 deletions website/content/docs/commands/operator/scheduler-get-config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ Display the current scheduler configuration:

```shell-session
$ nomad operator scheduler get-config
Scheduler Algorithm = binpack
Memory Oversubscription = false
Reject Job Registration = false
Pause Eval Broker = false
Preemtion System Scheduler = true
Preemtion Service Scheduler = false
Preemtion Batch Scheduler = false
Preemtion SysBatch Scheduler = false
Scheduler Algorithm = binpack
Memory Oversubscription = false
Reject Job Registration = false
Pause Eval Broker = false
Preemption System Scheduler = true
Preemption Service Scheduler = false
Preemption Batch Scheduler = false
Preemption SysBatch Scheduler = false
Modify Index = 5
```
12 changes: 12 additions & 0 deletions website/content/docs/commands/operator/scheduler-set-config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ capability.

## Set Config Options

- `-check-index` - If set, the scheduler config is only updated if the passed
modify index matches the current server side version. If a non-zero value is
passed, it ensures that the scheduler config is being updated from a known
state.

- `-scheduler-algorithm` - Specifies whether scheduler binpacks or spreads
allocations on available nodes. Must be one of `["binpack"|"spread"]`.

Expand Down Expand Up @@ -67,4 +72,11 @@ $ nomad operator scheduler set-config -scheduler-algorithm=spread
Scheduler configuration updated!
```

Modify the scheduler algorithm to spread using the check index flag:

```shell-session
$ nomad operator scheduler set-config -scheduler-algorithm=spread -check-index=5
Scheduler configuration updated!
```

[`memory_max`]: /docs/job-specification/resources#memory_max

0 comments on commit f6c63f8

Please sign in to comment.