mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #33440 from RenaudWasTaken/genericresource
Added support for Generic Resources
This commit is contained in:
commit
9319a8a2dd
13 changed files with 196 additions and 33 deletions
|
|
@ -487,6 +487,41 @@ definitions:
|
||||||
type: "integer"
|
type: "integer"
|
||||||
format: "int64"
|
format: "int64"
|
||||||
|
|
||||||
|
ResourceObject:
|
||||||
|
description: "An object describing the resources which can be advertised by a node and requested by a task"
|
||||||
|
type: "object"
|
||||||
|
properties:
|
||||||
|
NanoCPUs:
|
||||||
|
type: "integer"
|
||||||
|
format: "int64"
|
||||||
|
MemoryBytes:
|
||||||
|
type: "integer"
|
||||||
|
format: "int64"
|
||||||
|
GenericResources:
|
||||||
|
$ref: "#/definitions/GenericResources"
|
||||||
|
|
||||||
|
GenericResources:
|
||||||
|
description: "User defined Resources, can be either Integer resources (e.g: SSD=3) or String resources (e.g: GPU={UUID1, UUID2})"
|
||||||
|
type: "array"
|
||||||
|
items:
|
||||||
|
type: "object"
|
||||||
|
properties:
|
||||||
|
NamedResourceSpec:
|
||||||
|
type: "object"
|
||||||
|
properties:
|
||||||
|
Kind:
|
||||||
|
type: "string"
|
||||||
|
Value:
|
||||||
|
type: "string"
|
||||||
|
DiscreteResourceSpec:
|
||||||
|
type: "object"
|
||||||
|
properties:
|
||||||
|
Kind:
|
||||||
|
type: "string"
|
||||||
|
Value:
|
||||||
|
type: "integer"
|
||||||
|
format: "int64"
|
||||||
|
|
||||||
HealthConfig:
|
HealthConfig:
|
||||||
description: "A test to perform to check that the container is healthy."
|
description: "A test to perform to check that the container is healthy."
|
||||||
type: "object"
|
type: "object"
|
||||||
|
|
@ -1712,14 +1747,7 @@ definitions:
|
||||||
OS:
|
OS:
|
||||||
type: "string"
|
type: "string"
|
||||||
Resources:
|
Resources:
|
||||||
type: "object"
|
$ref: "#/definitions/ResourceObject"
|
||||||
properties:
|
|
||||||
NanoCPUs:
|
|
||||||
type: "integer"
|
|
||||||
format: "int64"
|
|
||||||
MemoryBytes:
|
|
||||||
type: "integer"
|
|
||||||
format: "int64"
|
|
||||||
Engine:
|
Engine:
|
||||||
type: "object"
|
type: "object"
|
||||||
properties:
|
properties:
|
||||||
|
|
@ -1760,6 +1788,16 @@ definitions:
|
||||||
Resources:
|
Resources:
|
||||||
NanoCPUs: 4000000000
|
NanoCPUs: 4000000000
|
||||||
MemoryBytes: 8272408576
|
MemoryBytes: 8272408576
|
||||||
|
GenericResources:
|
||||||
|
- DiscreteResourceSpec:
|
||||||
|
Kind: "SSD"
|
||||||
|
Value: 3
|
||||||
|
- NamedResourceSpec:
|
||||||
|
Kind: "GPU"
|
||||||
|
Value: "UUID1"
|
||||||
|
- NamedResourceSpec:
|
||||||
|
Kind: "GPU"
|
||||||
|
Value: "UUID2"
|
||||||
Engine:
|
Engine:
|
||||||
EngineVersion: "17.04.0"
|
EngineVersion: "17.04.0"
|
||||||
Labels:
|
Labels:
|
||||||
|
|
@ -2224,27 +2262,10 @@ definitions:
|
||||||
properties:
|
properties:
|
||||||
Limits:
|
Limits:
|
||||||
description: "Define resources limits."
|
description: "Define resources limits."
|
||||||
type: "object"
|
$ref: "#/definitions/ResourceObject"
|
||||||
properties:
|
|
||||||
NanoCPUs:
|
|
||||||
description: "CPU limit in units of 10<sup>-9</sup> CPU shares."
|
|
||||||
type: "integer"
|
|
||||||
format: "int64"
|
|
||||||
MemoryBytes:
|
|
||||||
description: "Memory limit in Bytes."
|
|
||||||
type: "integer"
|
|
||||||
format: "int64"
|
|
||||||
Reservation:
|
Reservation:
|
||||||
description: "Define resources reservation."
|
description: "Define resources reservation."
|
||||||
properties:
|
$ref: "#/definitions/ResourceObject"
|
||||||
NanoCPUs:
|
|
||||||
description: "CPU reservation in units of 10<sup>-9</sup> CPU shares."
|
|
||||||
type: "integer"
|
|
||||||
format: "int64"
|
|
||||||
MemoryBytes:
|
|
||||||
description: "Memory reservation in Bytes."
|
|
||||||
type: "integer"
|
|
||||||
format: "int64"
|
|
||||||
RestartPolicy:
|
RestartPolicy:
|
||||||
description: "Specification for the restart policy which applies to containers created as part of this service."
|
description: "Specification for the restart policy which applies to containers created as part of this service."
|
||||||
type: "object"
|
type: "object"
|
||||||
|
|
@ -2375,6 +2396,8 @@ definitions:
|
||||||
NodeID:
|
NodeID:
|
||||||
description: "The ID of the node that this task is on."
|
description: "The ID of the node that this task is on."
|
||||||
type: "string"
|
type: "string"
|
||||||
|
AssignedGenericResources:
|
||||||
|
$ref: "#/definitions/GenericResources"
|
||||||
Status:
|
Status:
|
||||||
type: "object"
|
type: "object"
|
||||||
properties:
|
properties:
|
||||||
|
|
@ -2454,6 +2477,16 @@ definitions:
|
||||||
Gateway: "10.255.0.1"
|
Gateway: "10.255.0.1"
|
||||||
Addresses:
|
Addresses:
|
||||||
- "10.255.0.10/16"
|
- "10.255.0.10/16"
|
||||||
|
AssignedGenericResources:
|
||||||
|
- DiscreteResourceSpec:
|
||||||
|
Kind: "SSD"
|
||||||
|
Value: 3
|
||||||
|
- NamedResourceSpec:
|
||||||
|
Kind: "GPU"
|
||||||
|
Value: "UUID1"
|
||||||
|
- NamedResourceSpec:
|
||||||
|
Kind: "GPU"
|
||||||
|
Value: "UUID2"
|
||||||
ServiceSpec:
|
ServiceSpec:
|
||||||
description: "User modifiable configuration for a service."
|
description: "User modifiable configuration for a service."
|
||||||
properties:
|
properties:
|
||||||
|
|
@ -5516,6 +5549,8 @@ paths:
|
||||||
type: "string"
|
type: "string"
|
||||||
MemTotal:
|
MemTotal:
|
||||||
type: "integer"
|
type: "integer"
|
||||||
|
GenericResources:
|
||||||
|
$ref: "#/definitions/GenericResources"
|
||||||
MemoryLimit:
|
MemoryLimit:
|
||||||
type: "boolean"
|
type: "boolean"
|
||||||
NCPU:
|
NCPU:
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ type Task struct {
|
||||||
Status TaskStatus `json:",omitempty"`
|
Status TaskStatus `json:",omitempty"`
|
||||||
DesiredState TaskState `json:",omitempty"`
|
DesiredState TaskState `json:",omitempty"`
|
||||||
NetworksAttachments []NetworkAttachment `json:",omitempty"`
|
NetworksAttachments []NetworkAttachment `json:",omitempty"`
|
||||||
|
GenericResources []GenericResource `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TaskSpec represents the spec of a task.
|
// TaskSpec represents the spec of a task.
|
||||||
|
|
@ -79,8 +80,34 @@ type TaskSpec struct {
|
||||||
|
|
||||||
// Resources represents resources (CPU/Memory).
|
// Resources represents resources (CPU/Memory).
|
||||||
type Resources struct {
|
type Resources struct {
|
||||||
NanoCPUs int64 `json:",omitempty"`
|
NanoCPUs int64 `json:",omitempty"`
|
||||||
MemoryBytes int64 `json:",omitempty"`
|
MemoryBytes int64 `json:",omitempty"`
|
||||||
|
GenericResources []GenericResource `json:",omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenericResource represents a "user defined" resource which can
|
||||||
|
// be either an integer (e.g: SSD=3) or a string (e.g: SSD=sda1)
|
||||||
|
type GenericResource struct {
|
||||||
|
NamedResourceSpec *NamedGenericResource `json:",omitempty"`
|
||||||
|
DiscreteResourceSpec *DiscreteGenericResource `json:",omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// NamedGenericResource represents a "user defined" resource which is defined
|
||||||
|
// as a string.
|
||||||
|
// "Kind" is used to describe the Kind of a resource (e.g: "GPU", "FPGA", "SSD", ...)
|
||||||
|
// Value is used to identify the resource (GPU="UUID-1", FPGA="/dev/sdb5", ...)
|
||||||
|
type NamedGenericResource struct {
|
||||||
|
Kind string `json:",omitempty"`
|
||||||
|
Value string `json:",omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DiscreteGenericResource represents a "user defined" resource which is defined
|
||||||
|
// as an integer
|
||||||
|
// "Kind" is used to describe the Kind of a resource (e.g: "GPU", "FPGA", "SSD", ...)
|
||||||
|
// Value is used to count the resource (SSD=5, HDD=3, ...)
|
||||||
|
type DiscreteGenericResource struct {
|
||||||
|
Kind string `json:",omitempty"`
|
||||||
|
Value int64 `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResourceRequirements represents resources requirements.
|
// ResourceRequirements represents resources requirements.
|
||||||
|
|
|
||||||
|
|
@ -168,6 +168,7 @@ type Info struct {
|
||||||
RegistryConfig *registry.ServiceConfig
|
RegistryConfig *registry.ServiceConfig
|
||||||
NCPU int
|
NCPU int
|
||||||
MemTotal int64
|
MemTotal int64
|
||||||
|
GenericResources []swarm.GenericResource
|
||||||
DockerRootDir string
|
DockerRootDir string
|
||||||
HTTPProxy string `json:"HttpProxy"`
|
HTTPProxy string `json:"HttpProxy"`
|
||||||
HTTPSProxy string `json:"HttpsProxy"`
|
HTTPSProxy string `json:"HttpsProxy"`
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,8 @@ func installCommonConfigFlags(conf *config.Config, flags *pflag.FlagSet) {
|
||||||
|
|
||||||
flags.StringVar(&conf.MetricsAddress, "metrics-addr", "", "Set default address and port to serve the metrics api on")
|
flags.StringVar(&conf.MetricsAddress, "metrics-addr", "", "Set default address and port to serve the metrics api on")
|
||||||
|
|
||||||
|
flags.StringVar(&conf.NodeGenericResources, "node-generic-resources", "", "user defined resources (e.g. fpga=2;gpu={UUID1,UUID2,UUID3})")
|
||||||
|
|
||||||
// "--deprecated-key-path" is to allow configuration of the key used
|
// "--deprecated-key-path" is to allow configuration of the key used
|
||||||
// for the daemon ID and the deprecated image signing. It was never
|
// for the daemon ID and the deprecated image signing. It was never
|
||||||
// exposed as a command line option but is added here to allow
|
// exposed as a command line option but is added here to allow
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ func NodeFromGRPC(n swarmapi.Node) types.Node {
|
||||||
if n.Description.Resources != nil {
|
if n.Description.Resources != nil {
|
||||||
node.Description.Resources.NanoCPUs = n.Description.Resources.NanoCPUs
|
node.Description.Resources.NanoCPUs = n.Description.Resources.NanoCPUs
|
||||||
node.Description.Resources.MemoryBytes = n.Description.Resources.MemoryBytes
|
node.Description.Resources.MemoryBytes = n.Description.Resources.MemoryBytes
|
||||||
|
node.Description.Resources.GenericResources = GenericResourcesFromGRPC(n.Description.Resources.Generic)
|
||||||
}
|
}
|
||||||
if n.Description.Engine != nil {
|
if n.Description.Engine != nil {
|
||||||
node.Description.Engine.EngineVersion = n.Description.Engine.EngineVersion
|
node.Description.Engine.EngineVersion = n.Description.Engine.EngineVersion
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/docker/docker/api/types/swarm/runtime"
|
"github.com/docker/docker/api/types/swarm/runtime"
|
||||||
"github.com/docker/docker/pkg/namesgenerator"
|
"github.com/docker/docker/pkg/namesgenerator"
|
||||||
swarmapi "github.com/docker/swarmkit/api"
|
swarmapi "github.com/docker/swarmkit/api"
|
||||||
|
"github.com/docker/swarmkit/api/genericresource"
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
gogotypes "github.com/gogo/protobuf/types"
|
gogotypes "github.com/gogo/protobuf/types"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
@ -301,6 +302,31 @@ func annotationsFromGRPC(ann swarmapi.Annotations) types.Annotations {
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GenericResourcesFromGRPC converts a GRPC GenericResource to a GenericResource
|
||||||
|
func GenericResourcesFromGRPC(genericRes []*swarmapi.GenericResource) []types.GenericResource {
|
||||||
|
var generic []types.GenericResource
|
||||||
|
for _, res := range genericRes {
|
||||||
|
var current types.GenericResource
|
||||||
|
|
||||||
|
switch r := res.Resource.(type) {
|
||||||
|
case *swarmapi.GenericResource_DiscreteResourceSpec:
|
||||||
|
current.DiscreteResourceSpec = &types.DiscreteGenericResource{
|
||||||
|
Kind: r.DiscreteResourceSpec.Kind,
|
||||||
|
Value: r.DiscreteResourceSpec.Value,
|
||||||
|
}
|
||||||
|
case *swarmapi.GenericResource_NamedResourceSpec:
|
||||||
|
current.NamedResourceSpec = &types.NamedGenericResource{
|
||||||
|
Kind: r.NamedResourceSpec.Kind,
|
||||||
|
Value: r.NamedResourceSpec.Value,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
generic = append(generic, current)
|
||||||
|
}
|
||||||
|
|
||||||
|
return generic
|
||||||
|
}
|
||||||
|
|
||||||
func resourcesFromGRPC(res *swarmapi.ResourceRequirements) *types.ResourceRequirements {
|
func resourcesFromGRPC(res *swarmapi.ResourceRequirements) *types.ResourceRequirements {
|
||||||
var resources *types.ResourceRequirements
|
var resources *types.ResourceRequirements
|
||||||
if res != nil {
|
if res != nil {
|
||||||
|
|
@ -313,8 +339,9 @@ func resourcesFromGRPC(res *swarmapi.ResourceRequirements) *types.ResourceRequir
|
||||||
}
|
}
|
||||||
if res.Reservations != nil {
|
if res.Reservations != nil {
|
||||||
resources.Reservations = &types.Resources{
|
resources.Reservations = &types.Resources{
|
||||||
NanoCPUs: res.Reservations.NanoCPUs,
|
NanoCPUs: res.Reservations.NanoCPUs,
|
||||||
MemoryBytes: res.Reservations.MemoryBytes,
|
MemoryBytes: res.Reservations.MemoryBytes,
|
||||||
|
GenericResources: GenericResourcesFromGRPC(res.Reservations.Generic),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -322,6 +349,24 @@ func resourcesFromGRPC(res *swarmapi.ResourceRequirements) *types.ResourceRequir
|
||||||
return resources
|
return resources
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GenericResourcesToGRPC converts a GenericResource to a GRPC GenericResource
|
||||||
|
func GenericResourcesToGRPC(genericRes []types.GenericResource) []*swarmapi.GenericResource {
|
||||||
|
var generic []*swarmapi.GenericResource
|
||||||
|
for _, res := range genericRes {
|
||||||
|
var r *swarmapi.GenericResource
|
||||||
|
|
||||||
|
if res.DiscreteResourceSpec != nil {
|
||||||
|
r = genericresource.NewDiscrete(res.DiscreteResourceSpec.Kind, res.DiscreteResourceSpec.Value)
|
||||||
|
} else if res.NamedResourceSpec != nil {
|
||||||
|
r = genericresource.NewString(res.NamedResourceSpec.Kind, res.NamedResourceSpec.Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
generic = append(generic, r)
|
||||||
|
}
|
||||||
|
|
||||||
|
return generic
|
||||||
|
}
|
||||||
|
|
||||||
func resourcesToGRPC(res *types.ResourceRequirements) *swarmapi.ResourceRequirements {
|
func resourcesToGRPC(res *types.ResourceRequirements) *swarmapi.ResourceRequirements {
|
||||||
var reqs *swarmapi.ResourceRequirements
|
var reqs *swarmapi.ResourceRequirements
|
||||||
if res != nil {
|
if res != nil {
|
||||||
|
|
@ -336,6 +381,7 @@ func resourcesToGRPC(res *types.ResourceRequirements) *swarmapi.ResourceRequirem
|
||||||
reqs.Reservations = &swarmapi.Resources{
|
reqs.Reservations = &swarmapi.Resources{
|
||||||
NanoCPUs: res.Reservations.NanoCPUs,
|
NanoCPUs: res.Reservations.NanoCPUs,
|
||||||
MemoryBytes: res.Reservations.MemoryBytes,
|
MemoryBytes: res.Reservations.MemoryBytes,
|
||||||
|
Generic: GenericResourcesToGRPC(res.Reservations.GenericResources),
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,8 @@ func TaskFromGRPC(t swarmapi.Task) (types.Task, error) {
|
||||||
Message: t.Status.Message,
|
Message: t.Status.Message,
|
||||||
Err: t.Status.Err,
|
Err: t.Status.Err,
|
||||||
},
|
},
|
||||||
DesiredState: types.TaskState(strings.ToLower(t.DesiredState.String())),
|
DesiredState: types.TaskState(strings.ToLower(t.DesiredState.String())),
|
||||||
|
GenericResources: GenericResourcesFromGRPC(t.AssignedGenericResources),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Meta
|
// Meta
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import (
|
||||||
netconst "github.com/docker/libnetwork/datastore"
|
netconst "github.com/docker/libnetwork/datastore"
|
||||||
"github.com/docker/swarmkit/agent/exec"
|
"github.com/docker/swarmkit/agent/exec"
|
||||||
"github.com/docker/swarmkit/api"
|
"github.com/docker/swarmkit/api"
|
||||||
|
"github.com/docker/swarmkit/api/genericresource"
|
||||||
"github.com/docker/swarmkit/template"
|
"github.com/docker/swarmkit/template"
|
||||||
gogotypes "github.com/gogo/protobuf/types"
|
gogotypes "github.com/gogo/protobuf/types"
|
||||||
)
|
)
|
||||||
|
|
@ -186,13 +187,16 @@ func (c *containerConfig) exposedPorts() map[nat.Port]struct{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *containerConfig) config() *enginecontainer.Config {
|
func (c *containerConfig) config() *enginecontainer.Config {
|
||||||
|
genericEnvs := genericresource.EnvFormat(c.task.AssignedGenericResources, "DOCKER_RESOURCE")
|
||||||
|
env := append(c.spec().Env, genericEnvs...)
|
||||||
|
|
||||||
config := &enginecontainer.Config{
|
config := &enginecontainer.Config{
|
||||||
Labels: c.labels(),
|
Labels: c.labels(),
|
||||||
StopSignal: c.spec().StopSignal,
|
StopSignal: c.spec().StopSignal,
|
||||||
Tty: c.spec().TTY,
|
Tty: c.spec().TTY,
|
||||||
OpenStdin: c.spec().OpenStdin,
|
OpenStdin: c.spec().OpenStdin,
|
||||||
User: c.spec().User,
|
User: c.spec().User,
|
||||||
Env: c.spec().Env,
|
Env: env,
|
||||||
Hostname: c.spec().Hostname,
|
Hostname: c.spec().Hostname,
|
||||||
WorkingDir: c.spec().Dir,
|
WorkingDir: c.spec().Dir,
|
||||||
Image: c.image(),
|
Image: c.image(),
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/docker/docker/api/types/network"
|
"github.com/docker/docker/api/types/network"
|
||||||
swarmtypes "github.com/docker/docker/api/types/swarm"
|
swarmtypes "github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/daemon/cluster/controllers/plugin"
|
"github.com/docker/docker/daemon/cluster/controllers/plugin"
|
||||||
|
"github.com/docker/docker/daemon/cluster/convert"
|
||||||
executorpkg "github.com/docker/docker/daemon/cluster/executor"
|
executorpkg "github.com/docker/docker/daemon/cluster/executor"
|
||||||
clustertypes "github.com/docker/docker/daemon/cluster/provider"
|
clustertypes "github.com/docker/docker/daemon/cluster/provider"
|
||||||
networktypes "github.com/docker/libnetwork/types"
|
networktypes "github.com/docker/libnetwork/types"
|
||||||
|
|
@ -119,6 +120,7 @@ func (e *executor) Describe(ctx context.Context) (*api.NodeDescription, error) {
|
||||||
Resources: &api.Resources{
|
Resources: &api.Resources{
|
||||||
NanoCPUs: int64(info.NCPU) * 1e9,
|
NanoCPUs: int64(info.NCPU) * 1e9,
|
||||||
MemoryBytes: info.MemTotal,
|
MemoryBytes: info.MemTotal,
|
||||||
|
Generic: convert.GenericResourcesToGRPC(info.GenericResources),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -168,6 +168,9 @@ type CommonConfig struct {
|
||||||
ValuesSet map[string]interface{}
|
ValuesSet map[string]interface{}
|
||||||
|
|
||||||
Experimental bool `json:"experimental"` // Experimental indicates whether experimental features should be exposed or not
|
Experimental bool `json:"experimental"` // Experimental indicates whether experimental features should be exposed or not
|
||||||
|
|
||||||
|
// Exposed node Generic Resources
|
||||||
|
NodeGenericResources string `json:"node-generic-resources,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsValueSet returns true if a configuration value
|
// IsValueSet returns true if a configuration value
|
||||||
|
|
@ -497,6 +500,10 @@ func Validate(config *Config) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, err := opts.ParseGenericResources(config.NodeGenericResources); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if defaultRuntime := config.GetDefaultRuntimeName(); defaultRuntime != "" && defaultRuntime != StockRuntimeName {
|
if defaultRuntime := config.GetDefaultRuntimeName(); defaultRuntime != "" && defaultRuntime != StockRuntimeName {
|
||||||
runtimes := config.GetAllRuntimes()
|
runtimes := config.GetAllRuntimes()
|
||||||
if _, ok := runtimes[defaultRuntime]; !ok {
|
if _, ok := runtimes[defaultRuntime]; !ok {
|
||||||
|
|
|
||||||
|
|
@ -23,12 +23,14 @@ import (
|
||||||
"github.com/docker/docker/api"
|
"github.com/docker/docker/api"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
containertypes "github.com/docker/docker/api/types/container"
|
containertypes "github.com/docker/docker/api/types/container"
|
||||||
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/container"
|
"github.com/docker/docker/container"
|
||||||
"github.com/docker/docker/daemon/config"
|
"github.com/docker/docker/daemon/config"
|
||||||
"github.com/docker/docker/daemon/discovery"
|
"github.com/docker/docker/daemon/discovery"
|
||||||
"github.com/docker/docker/daemon/events"
|
"github.com/docker/docker/daemon/events"
|
||||||
"github.com/docker/docker/daemon/exec"
|
"github.com/docker/docker/daemon/exec"
|
||||||
"github.com/docker/docker/daemon/logger"
|
"github.com/docker/docker/daemon/logger"
|
||||||
|
"github.com/docker/docker/opts"
|
||||||
// register graph drivers
|
// register graph drivers
|
||||||
_ "github.com/docker/docker/daemon/graphdriver/register"
|
_ "github.com/docker/docker/daemon/graphdriver/register"
|
||||||
"github.com/docker/docker/daemon/initlayer"
|
"github.com/docker/docker/daemon/initlayer"
|
||||||
|
|
@ -109,6 +111,7 @@ type Daemon struct {
|
||||||
defaultIsolation containertypes.Isolation // Default isolation mode on Windows
|
defaultIsolation containertypes.Isolation // Default isolation mode on Windows
|
||||||
clusterProvider cluster.Provider
|
clusterProvider cluster.Provider
|
||||||
cluster Cluster
|
cluster Cluster
|
||||||
|
genericResources []swarm.GenericResource
|
||||||
metricsPluginListener net.Listener
|
metricsPluginListener net.Listener
|
||||||
|
|
||||||
machineMemory uint64
|
machineMemory uint64
|
||||||
|
|
@ -566,6 +569,9 @@ func NewDaemon(config *config.Config, registryService registry.Service, containe
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
if err := d.setGenericResources(config); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
// set up SIGUSR1 handler on Unix-like systems, or a Win32 global event
|
// set up SIGUSR1 handler on Unix-like systems, or a Win32 global event
|
||||||
// on Windows to dump Go routine stacks
|
// on Windows to dump Go routine stacks
|
||||||
stackDumpDir := config.Root
|
stackDumpDir := config.Root
|
||||||
|
|
@ -1035,6 +1041,17 @@ func (daemon *Daemon) setupInitLayer(initPath string) error {
|
||||||
return initlayer.Setup(initPath, rootIDs)
|
return initlayer.Setup(initPath, rootIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (daemon *Daemon) setGenericResources(conf *config.Config) error {
|
||||||
|
genericResources, err := opts.ParseGenericResources(conf.NodeGenericResources)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
daemon.genericResources = genericResources
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func setDefaultMtu(conf *config.Config) {
|
func setDefaultMtu(conf *config.Config) {
|
||||||
// do nothing if the config does not have the default 0 value.
|
// do nothing if the config does not have the default 0 value.
|
||||||
if conf.Mtu != 0 {
|
if conf.Mtu != 0 {
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,7 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) {
|
||||||
RegistryConfig: daemon.RegistryService.ServiceConfig(),
|
RegistryConfig: daemon.RegistryService.ServiceConfig(),
|
||||||
NCPU: sysinfo.NumCPU(),
|
NCPU: sysinfo.NumCPU(),
|
||||||
MemTotal: meminfo.MemTotal,
|
MemTotal: meminfo.MemTotal,
|
||||||
|
GenericResources: daemon.genericResources,
|
||||||
DockerRootDir: daemon.configStore.Root,
|
DockerRootDir: daemon.configStore.Root,
|
||||||
Labels: daemon.configStore.Labels,
|
Labels: daemon.configStore.Labels,
|
||||||
ExperimentalBuild: daemon.configStore.Experimental,
|
ExperimentalBuild: daemon.configStore.Experimental,
|
||||||
|
|
|
||||||
19
opts/opts.go
19
opts/opts.go
|
|
@ -7,7 +7,10 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/docker/docker/api/types/swarm"
|
||||||
|
"github.com/docker/docker/daemon/cluster/convert"
|
||||||
units "github.com/docker/go-units"
|
units "github.com/docker/go-units"
|
||||||
|
"github.com/docker/swarmkit/api/genericresource"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -325,3 +328,19 @@ func (m *MemBytes) UnmarshalJSON(s []byte) error {
|
||||||
*m = MemBytes(val)
|
*m = MemBytes(val)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ParseGenericResources parses and validates the specified string as a list of GenericResource
|
||||||
|
func ParseGenericResources(value string) ([]swarm.GenericResource, error) {
|
||||||
|
if value == "" {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
resources, err := genericresource.Parse(value)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
obj := convert.GenericResourcesFromGRPC(resources)
|
||||||
|
|
||||||
|
return obj, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue