mirror of
https://github.com/kemko/nomad.git
synced 2026-01-03 00:45:43 +03:00
docker: move config RPCs to config.go
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package docker
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -382,3 +383,54 @@ type VolumeConfig struct {
|
||||
Enabled bool `codec:"enabled"`
|
||||
SelinuxLabel string `codec:"selinuxlabel"`
|
||||
}
|
||||
|
||||
func (d *Driver) PluginInfo() (*base.PluginInfoResponse, error) {
|
||||
return pluginInfo, nil
|
||||
}
|
||||
|
||||
func (d *Driver) ConfigSchema() (*hclspec.Spec, error) {
|
||||
return configSpec, nil
|
||||
}
|
||||
|
||||
func (d *Driver) SetConfig(data []byte, cfg *base.ClientAgentConfig) error {
|
||||
var config DriverConfig
|
||||
if err := base.MsgPackDecode(data, &config); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.config = &config
|
||||
if len(d.config.GC.ImageDelay) > 0 {
|
||||
dur, err := time.ParseDuration(d.config.GC.ImageDelay)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse 'image_delay' duration: %v", err)
|
||||
}
|
||||
d.config.GC.imageDelayDuration = dur
|
||||
}
|
||||
|
||||
if cfg != nil {
|
||||
d.clientConfig = cfg.Driver
|
||||
}
|
||||
|
||||
dockerClient, _, err := d.dockerClients()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get docker client: %v", err)
|
||||
}
|
||||
coordinatorConfig := &dockerCoordinatorConfig{
|
||||
client: dockerClient,
|
||||
cleanup: d.config.GC.Image,
|
||||
logger: d.logger,
|
||||
removeDelay: d.config.GC.imageDelayDuration,
|
||||
}
|
||||
|
||||
d.coordinator = NewDockerCoordinator(coordinatorConfig)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Driver) TaskConfigSchema() (*hclspec.Spec, error) {
|
||||
return taskConfigSpec, nil
|
||||
}
|
||||
|
||||
func (d *Driver) Capabilities() (*drivers.Capabilities, error) {
|
||||
return capabilities, nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package docker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
@@ -11,8 +12,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
docker "github.com/fsouza/go-dockerclient"
|
||||
"github.com/hashicorp/consul-template/signals"
|
||||
hclog "github.com/hashicorp/go-hclog"
|
||||
@@ -25,7 +24,6 @@ import (
|
||||
"github.com/hashicorp/nomad/plugins/base"
|
||||
"github.com/hashicorp/nomad/plugins/drivers"
|
||||
"github.com/hashicorp/nomad/plugins/shared"
|
||||
"github.com/hashicorp/nomad/plugins/shared/hclspec"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -104,57 +102,6 @@ func NewDockerDriver(logger hclog.Logger) drivers.DriverPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Driver) PluginInfo() (*base.PluginInfoResponse, error) {
|
||||
return pluginInfo, nil
|
||||
}
|
||||
|
||||
func (d *Driver) ConfigSchema() (*hclspec.Spec, error) {
|
||||
return configSpec, nil
|
||||
}
|
||||
|
||||
func (d *Driver) SetConfig(data []byte, cfg *base.ClientAgentConfig) error {
|
||||
var config DriverConfig
|
||||
if err := base.MsgPackDecode(data, &config); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.config = &config
|
||||
if len(d.config.GC.ImageDelay) > 0 {
|
||||
dur, err := time.ParseDuration(d.config.GC.ImageDelay)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse 'image_delay' duration: %v", err)
|
||||
}
|
||||
d.config.GC.imageDelayDuration = dur
|
||||
}
|
||||
|
||||
if cfg != nil {
|
||||
d.clientConfig = cfg.Driver
|
||||
}
|
||||
|
||||
dockerClient, _, err := d.dockerClients()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get docker client: %v", err)
|
||||
}
|
||||
coordinatorConfig := &dockerCoordinatorConfig{
|
||||
client: dockerClient,
|
||||
cleanup: d.config.GC.Image,
|
||||
logger: d.logger,
|
||||
removeDelay: d.config.GC.imageDelayDuration,
|
||||
}
|
||||
|
||||
d.coordinator = NewDockerCoordinator(coordinatorConfig)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Driver) TaskConfigSchema() (*hclspec.Spec, error) {
|
||||
return taskConfigSpec, nil
|
||||
}
|
||||
|
||||
func (d *Driver) Capabilities() (*drivers.Capabilities, error) {
|
||||
return capabilities, nil
|
||||
}
|
||||
|
||||
func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error {
|
||||
if _, ok := d.tasks.Get(handle.Config.ID); ok {
|
||||
return nil
|
||||
@@ -287,7 +234,9 @@ CREATE:
|
||||
|
||||
dlogger, pluginClient, err := docklog.LaunchDockerLogger(d.logger)
|
||||
if err != nil {
|
||||
pluginClient.Kill()
|
||||
if pluginClient != nil {
|
||||
pluginClient.Kill()
|
||||
}
|
||||
d.logger.Error("an error occurred after container startup, terminating container", "container_id", container.ID)
|
||||
client.RemoveContainer(docker.RemoveContainerOptions{ID: container.ID, Force: true})
|
||||
return nil, nil, fmt.Errorf("failed to launch docker logger plugin: %v", err)
|
||||
@@ -594,7 +543,7 @@ func (d *Driver) containerBinds(task *drivers.TaskConfig, driverConfig *TaskConf
|
||||
binds := []string{allocDirBind, taskLocalBind, secretDirBind}
|
||||
|
||||
if !d.config.Volumes.Enabled && driverConfig.VolumeDriver != "" {
|
||||
return nil, fmt.Errorf("'volumes_enabled' is false; cannot use volume driver %q", driverConfig.VolumeDriver)
|
||||
return nil, fmt.Errorf("volumes are not enabled; cannot use volume driver %q", driverConfig.VolumeDriver)
|
||||
}
|
||||
|
||||
for _, userbind := range driverConfig.Volumes {
|
||||
@@ -610,7 +559,7 @@ func (d *Driver) containerBinds(task *drivers.TaskConfig, driverConfig *TaskConf
|
||||
if filepath.IsAbs(parts[0]) {
|
||||
if !d.config.Volumes.Enabled {
|
||||
// Disallow mounting arbitrary absolute paths
|
||||
return nil, fmt.Errorf("'volumes_enabled' is false; cannot mount host paths: %+q", userbind)
|
||||
return nil, fmt.Errorf("volumes are not enabled; cannot mount host paths: %+q", userbind)
|
||||
}
|
||||
binds = append(binds, userbind)
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user