mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 17:35:43 +03:00
Adds a new configuration to clients to optionally allow them to drain their workloads on shutdown. The client sends the `Node.UpdateDrain` RPC targeting itself and then monitors the drain state as seen by the server until the drain is complete or the deadline expires. If it loses connection with the server, it will monitor local client status instead to ensure allocations are stopped before exiting.
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs/config"
|
|
)
|
|
|
|
// DrainConfig describes a Node's drain behavior on graceful shutdown.
|
|
type DrainConfig struct {
|
|
// Deadline is the duration after the drain starts when client will stop
|
|
// waiting for allocations to stop.
|
|
Deadline time.Duration
|
|
|
|
// IgnoreSystemJobs allows systems jobs to remain on the node even though it
|
|
// has been marked for draining.
|
|
IgnoreSystemJobs bool
|
|
|
|
// Force causes the drain to stop all the allocations immediately, ignoring
|
|
// their jobs' migrate blocks.
|
|
Force bool
|
|
}
|
|
|
|
// DrainConfigFromAgent creates the internal read-only copy of the client
|
|
// agent's DrainConfig.
|
|
func DrainConfigFromAgent(c *config.DrainConfig) (*DrainConfig, error) {
|
|
if c == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
deadline := time.Hour
|
|
ignoreSystemJobs := false
|
|
force := false
|
|
|
|
if c.Deadline != nil {
|
|
var err error
|
|
deadline, err = time.ParseDuration(*c.Deadline)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error parsing Deadline: %w", err)
|
|
}
|
|
}
|
|
if c.IgnoreSystemJobs != nil {
|
|
ignoreSystemJobs = *c.IgnoreSystemJobs
|
|
}
|
|
if c.Force != nil {
|
|
force = *c.Force
|
|
}
|
|
|
|
return &DrainConfig{
|
|
Deadline: deadline,
|
|
IgnoreSystemJobs: ignoreSystemJobs,
|
|
Force: force,
|
|
}, nil
|
|
}
|