mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
Advertise signalling abilities
This commit is contained in:
@@ -266,6 +266,12 @@ func (d *DockerDriver) Validate(config map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DockerDriver) Abilities() DriverAbilities {
|
||||
return DriverAbilities{
|
||||
SendSignals: true,
|
||||
}
|
||||
}
|
||||
|
||||
// dockerClients creates two *docker.Client, one for long running operations and
|
||||
// the other for shorter operations. In test / dev mode we can use ENV vars to
|
||||
// connect to the docker daemon. In production mode we will read docker.endpoint
|
||||
|
||||
@@ -59,6 +59,15 @@ type Driver interface {
|
||||
|
||||
// Drivers must validate their configuration
|
||||
Validate(map[string]interface{}) error
|
||||
|
||||
// Abilities returns the abilities of the driver
|
||||
Abilities() DriverAbilities
|
||||
}
|
||||
|
||||
// DriverAbilities marks the abilities the driver has.
|
||||
type DriverAbilities struct {
|
||||
// SendSignals marks the driver as being able to send signals
|
||||
SendSignals bool
|
||||
}
|
||||
|
||||
// DriverContext is a means to inject dependencies such as loggers, configs, and
|
||||
|
||||
@@ -82,6 +82,12 @@ func (d *ExecDriver) Validate(config map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *ExecDriver) Abilities() DriverAbilities {
|
||||
return DriverAbilities{
|
||||
SendSignals: true,
|
||||
}
|
||||
}
|
||||
|
||||
func (d *ExecDriver) Periodic() (bool, time.Duration) {
|
||||
return true, 15 * time.Second
|
||||
}
|
||||
|
||||
@@ -94,6 +94,12 @@ func (d *JavaDriver) Validate(config map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *JavaDriver) Abilities() DriverAbilities {
|
||||
return DriverAbilities{
|
||||
SendSignals: true,
|
||||
}
|
||||
}
|
||||
|
||||
func (d *JavaDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) {
|
||||
// Get the current status so that we can log any debug messages only if the
|
||||
// state changes
|
||||
|
||||
@@ -62,6 +62,12 @@ func NewMockDriver(ctx *DriverContext) Driver {
|
||||
return &MockDriver{DriverContext: *ctx}
|
||||
}
|
||||
|
||||
func (d *MockDriver) Abilities() DriverAbilities {
|
||||
return DriverAbilities{
|
||||
SendSignals: false,
|
||||
}
|
||||
}
|
||||
|
||||
// Start starts the mock driver
|
||||
func (m *MockDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, error) {
|
||||
var driverConfig MockDriverConfig
|
||||
|
||||
@@ -97,6 +97,12 @@ func (d *QemuDriver) Validate(config map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *QemuDriver) Abilities() DriverAbilities {
|
||||
return DriverAbilities{
|
||||
SendSignals: false,
|
||||
}
|
||||
}
|
||||
|
||||
func (d *QemuDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) {
|
||||
// Get the current status so that we can log any debug messages only if the
|
||||
// state changes
|
||||
|
||||
@@ -81,6 +81,12 @@ func (d *RawExecDriver) Validate(config map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *RawExecDriver) Abilities() DriverAbilities {
|
||||
return DriverAbilities{
|
||||
SendSignals: true,
|
||||
}
|
||||
}
|
||||
|
||||
func (d *RawExecDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) {
|
||||
// Get the current status so that we can log any debug messages only if the
|
||||
// state changes
|
||||
|
||||
@@ -128,6 +128,12 @@ func (d *RktDriver) Validate(config map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *RktDriver) Abilities() DriverAbilities {
|
||||
return DriverAbilities{
|
||||
SendSignals: false,
|
||||
}
|
||||
}
|
||||
|
||||
func (d *RktDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) {
|
||||
// Get the current status so that we can log any debug messages only if the
|
||||
// state changes
|
||||
|
||||
@@ -25,6 +25,7 @@ func init() {
|
||||
builtinFingerprintMap["memory"] = NewMemoryFingerprint
|
||||
builtinFingerprintMap["network"] = NewNetworkFingerprint
|
||||
builtinFingerprintMap["nomad"] = NewNomadFingerprint
|
||||
builtinFingerprintMap["signal"] = NewSignalFingerprint
|
||||
builtinFingerprintMap["storage"] = NewStorageFingerprint
|
||||
builtinFingerprintMap["vault"] = NewVaultFingerprint
|
||||
|
||||
|
||||
33
client/fingerprint/signal.go
Normal file
33
client/fingerprint/signal.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package fingerprint
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/consul-template/signals"
|
||||
"github.com/hashicorp/nomad/client/config"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
)
|
||||
|
||||
// SignalFingerprint is used to fingerprint the available signals
|
||||
type SignalFingerprint struct {
|
||||
StaticFingerprinter
|
||||
logger *log.Logger
|
||||
}
|
||||
|
||||
// NewSignalFingerprint is used to create a Signal fingerprint
|
||||
func NewSignalFingerprint(logger *log.Logger) Fingerprint {
|
||||
f := &SignalFingerprint{logger: logger}
|
||||
return f
|
||||
}
|
||||
|
||||
func (f *SignalFingerprint) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) {
|
||||
// Build the list of available signals
|
||||
sigs := make([]string, 0, len(signals.SignalLookup))
|
||||
for signal := range signals.SignalLookup {
|
||||
sigs = append(sigs, signal)
|
||||
}
|
||||
|
||||
node.Attributes["os.signals"] = strings.Join(sigs, ",")
|
||||
return true, nil
|
||||
}
|
||||
17
client/fingerprint/signal_test.go
Normal file
17
client/fingerprint/signal_test.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package fingerprint
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
)
|
||||
|
||||
func TestSignalFingerprint(t *testing.T) {
|
||||
fp := NewSignalFingerprint(testLogger())
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
|
||||
assertFingerprintOK(t, fp, node)
|
||||
assertNodeAttributeContains(t, node, "os.signals")
|
||||
}
|
||||
Reference in New Issue
Block a user