2018-02-05 16:05:59 -05:00
|
|
|
package container // import "github.com/docker/docker/daemon/cluster/executor/container"
|
2016-06-13 19:52:49 -07:00
|
|
|
|
|
|
|
import (
|
2018-04-19 15:30:59 -07:00
|
|
|
"context"
|
2017-03-01 15:52:55 -05:00
|
|
|
"fmt"
|
2016-07-25 10:38:24 -07:00
|
|
|
"sort"
|
2016-06-13 19:52:49 -07:00
|
|
|
"strings"
|
2017-08-30 21:45:05 +02:00
|
|
|
"sync"
|
2016-06-13 19:52:49 -07:00
|
|
|
|
2016-09-06 11:46:37 -07:00
|
|
|
"github.com/docker/docker/api/types"
|
2016-11-23 04:58:15 -08:00
|
|
|
"github.com/docker/docker/api/types/filters"
|
2016-09-06 11:46:37 -07:00
|
|
|
"github.com/docker/docker/api/types/network"
|
2017-03-01 15:52:55 -05:00
|
|
|
swarmtypes "github.com/docker/docker/api/types/swarm"
|
|
|
|
"github.com/docker/docker/daemon/cluster/controllers/plugin"
|
2017-05-30 17:02:11 -07:00
|
|
|
"github.com/docker/docker/daemon/cluster/convert"
|
2016-06-13 19:52:49 -07:00
|
|
|
executorpkg "github.com/docker/docker/daemon/cluster/executor"
|
|
|
|
clustertypes "github.com/docker/docker/daemon/cluster/provider"
|
Fix possible overlapping IPs
A node is no longer using its load balancer IP address when it no longer
has tasks that use the network that requires that load balancer. When
this occurs, the swarmkit manager will free that IP in IPAM, and may
reaassign it.
When a task shuts down cleanly, it attempts removal of the networks it
uses, and if it is the last task using those networks, this removal
succeeds, and the load balancer IP is freed.
However, this behavior is absent if the container fails. Removal of the
networks is never attempted.
To address this issue, I amend the executor. Whenever a node load
balancer IP is removed or changed, that information is passedd to the
executor by way of the Configure method. By keeping track of the set of
node NetworkAttachments from the previous call to Configure, we can
determine which, if any, have been removed or changed.
At first, this seems to create a race, by which a task can be attempting
to start and the network is removed right out from under it. However,
this is already addressed in the controller. The controller will attempt
to recreate missing networks before starting a task.
Signed-off-by: Drew Erny <derny@mirantis.com>
2021-05-10 14:11:13 -06:00
|
|
|
"github.com/docker/docker/libnetwork"
|
2021-04-06 00:24:47 +00:00
|
|
|
networktypes "github.com/docker/docker/libnetwork/types"
|
2017-03-16 14:23:33 -07:00
|
|
|
"github.com/docker/swarmkit/agent"
|
2016-06-13 19:52:49 -07:00
|
|
|
"github.com/docker/swarmkit/agent/exec"
|
|
|
|
"github.com/docker/swarmkit/api"
|
2017-03-01 15:52:55 -05:00
|
|
|
"github.com/docker/swarmkit/api/naming"
|
Fix possible overlapping IPs
A node is no longer using its load balancer IP address when it no longer
has tasks that use the network that requires that load balancer. When
this occurs, the swarmkit manager will free that IP in IPAM, and may
reaassign it.
When a task shuts down cleanly, it attempts removal of the networks it
uses, and if it is the last task using those networks, this removal
succeeds, and the load balancer IP is freed.
However, this behavior is absent if the container fails. Removal of the
networks is never attempted.
To address this issue, I amend the executor. Whenever a node load
balancer IP is removed or changed, that information is passedd to the
executor by way of the Configure method. By keeping track of the set of
node NetworkAttachments from the previous call to Configure, we can
determine which, if any, have been removed or changed.
At first, this seems to create a race, by which a task can be attempting
to start and the network is removed right out from under it. However,
this is already addressed in the controller. The controller will attempt
to recreate missing networks before starting a task.
Signed-off-by: Drew Erny <derny@mirantis.com>
2021-05-10 14:11:13 -06:00
|
|
|
"github.com/docker/swarmkit/log"
|
2017-06-15 11:21:05 -07:00
|
|
|
"github.com/docker/swarmkit/template"
|
Fix possible overlapping IPs
A node is no longer using its load balancer IP address when it no longer
has tasks that use the network that requires that load balancer. When
this occurs, the swarmkit manager will free that IP in IPAM, and may
reaassign it.
When a task shuts down cleanly, it attempts removal of the networks it
uses, and if it is the last task using those networks, this removal
succeeds, and the load balancer IP is freed.
However, this behavior is absent if the container fails. Removal of the
networks is never attempted.
To address this issue, I amend the executor. Whenever a node load
balancer IP is removed or changed, that information is passedd to the
executor by way of the Configure method. By keeping track of the set of
node NetworkAttachments from the previous call to Configure, we can
determine which, if any, have been removed or changed.
At first, this seems to create a race, by which a task can be attempting
to start and the network is removed right out from under it. However,
this is already addressed in the controller. The controller will attempt
to recreate missing networks before starting a task.
Signed-off-by: Drew Erny <derny@mirantis.com>
2021-05-10 14:11:13 -06:00
|
|
|
"github.com/pkg/errors"
|
2017-07-26 14:42:13 -07:00
|
|
|
"github.com/sirupsen/logrus"
|
2016-06-13 19:52:49 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
type executor struct {
|
2017-06-07 13:07:01 -04:00
|
|
|
backend executorpkg.Backend
|
2018-02-02 14:18:46 -08:00
|
|
|
imageBackend executorpkg.ImageBackend
|
2017-06-07 13:07:01 -04:00
|
|
|
pluginBackend plugin.Backend
|
2018-03-22 17:11:03 -04:00
|
|
|
volumeBackend executorpkg.VolumeBackend
|
2017-06-07 13:07:01 -04:00
|
|
|
dependencies exec.DependencyManager
|
2017-08-30 21:45:05 +02:00
|
|
|
mutex sync.Mutex // This mutex protects the following node field
|
|
|
|
node *api.NodeDescription
|
Fix possible overlapping IPs
A node is no longer using its load balancer IP address when it no longer
has tasks that use the network that requires that load balancer. When
this occurs, the swarmkit manager will free that IP in IPAM, and may
reaassign it.
When a task shuts down cleanly, it attempts removal of the networks it
uses, and if it is the last task using those networks, this removal
succeeds, and the load balancer IP is freed.
However, this behavior is absent if the container fails. Removal of the
networks is never attempted.
To address this issue, I amend the executor. Whenever a node load
balancer IP is removed or changed, that information is passedd to the
executor by way of the Configure method. By keeping track of the set of
node NetworkAttachments from the previous call to Configure, we can
determine which, if any, have been removed or changed.
At first, this seems to create a race, by which a task can be attempting
to start and the network is removed right out from under it. However,
this is already addressed in the controller. The controller will attempt
to recreate missing networks before starting a task.
Signed-off-by: Drew Erny <derny@mirantis.com>
2021-05-10 14:11:13 -06:00
|
|
|
|
|
|
|
// nodeObj holds a copy of the swarmkit Node object from the time of the
|
|
|
|
// last call to executor.Configure. This allows us to discover which
|
|
|
|
// network attachments the node previously had, which further allows us to
|
|
|
|
// determine which, if any, need to be removed. nodeObj is not protected by
|
|
|
|
// a mutex, because it is only written to in the method (Configure) that it
|
|
|
|
// is read from. If that changes, it may need to be guarded.
|
|
|
|
nodeObj *api.Node
|
2016-06-13 19:52:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewExecutor returns an executor from the docker client.
|
2018-03-22 17:11:03 -04:00
|
|
|
func NewExecutor(b executorpkg.Backend, p plugin.Backend, i executorpkg.ImageBackend, v executorpkg.VolumeBackend) exec.Executor {
|
2016-06-13 19:52:49 -07:00
|
|
|
return &executor{
|
2017-06-07 13:07:01 -04:00
|
|
|
backend: b,
|
|
|
|
pluginBackend: p,
|
2018-02-02 14:18:46 -08:00
|
|
|
imageBackend: i,
|
2018-03-22 17:11:03 -04:00
|
|
|
volumeBackend: v,
|
2017-06-07 13:07:01 -04:00
|
|
|
dependencies: agent.NewDependencyManager(),
|
2016-06-13 19:52:49 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Describe returns the underlying node description from the docker client.
|
|
|
|
func (e *executor) Describe(ctx context.Context) (*api.NodeDescription, error) {
|
2019-08-29 07:44:39 +08:00
|
|
|
info := e.backend.SystemInfo()
|
2016-06-13 19:52:49 -07:00
|
|
|
|
2016-07-25 17:16:31 -07:00
|
|
|
plugins := map[api.PluginDescription]struct{}{}
|
2016-06-13 19:52:49 -07:00
|
|
|
addPlugins := func(typ string, names []string) {
|
|
|
|
for _, name := range names {
|
2016-07-25 17:16:31 -07:00
|
|
|
plugins[api.PluginDescription{
|
2016-06-13 19:52:49 -07:00
|
|
|
Type: typ,
|
|
|
|
Name: name,
|
2016-07-25 17:16:31 -07:00
|
|
|
}] = struct{}{}
|
2016-06-13 19:52:49 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:20:37 -08:00
|
|
|
// add v1 plugins
|
2016-06-13 19:52:49 -07:00
|
|
|
addPlugins("Volume", info.Plugins.Volume)
|
|
|
|
// Add builtin driver "overlay" (the only builtin multi-host driver) to
|
|
|
|
// the plugin list by default.
|
|
|
|
addPlugins("Network", append([]string{"overlay"}, info.Plugins.Network...))
|
|
|
|
addPlugins("Authorization", info.Plugins.Authorization)
|
2017-04-11 17:21:21 -04:00
|
|
|
addPlugins("Log", info.Plugins.Log)
|
2016-06-13 19:52:49 -07:00
|
|
|
|
2016-12-13 17:20:37 -08:00
|
|
|
// add v2 plugins
|
2016-11-23 04:58:15 -08:00
|
|
|
v2Plugins, err := e.backend.PluginManager().List(filters.NewArgs())
|
2016-12-13 17:20:37 -08:00
|
|
|
if err == nil {
|
|
|
|
for _, plgn := range v2Plugins {
|
|
|
|
for _, typ := range plgn.Config.Interface.Types {
|
|
|
|
if typ.Prefix != "docker" || !plgn.Enabled {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
plgnTyp := typ.Capability
|
2017-04-11 17:21:21 -04:00
|
|
|
switch typ.Capability {
|
|
|
|
case "volumedriver":
|
2016-12-13 17:20:37 -08:00
|
|
|
plgnTyp = "Volume"
|
2017-04-11 17:21:21 -04:00
|
|
|
case "networkdriver":
|
2016-12-13 17:20:37 -08:00
|
|
|
plgnTyp = "Network"
|
2017-04-11 17:21:21 -04:00
|
|
|
case "logdriver":
|
|
|
|
plgnTyp = "Log"
|
2016-12-13 17:20:37 -08:00
|
|
|
}
|
2017-04-11 17:21:21 -04:00
|
|
|
|
2016-12-13 17:20:37 -08:00
|
|
|
plugins[api.PluginDescription{
|
|
|
|
Type: plgnTyp,
|
2016-12-12 15:05:53 -08:00
|
|
|
Name: plgn.Name,
|
2016-12-13 17:20:37 -08:00
|
|
|
}] = struct{}{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-25 17:16:31 -07:00
|
|
|
pluginFields := make([]api.PluginDescription, 0, len(plugins))
|
|
|
|
for k := range plugins {
|
|
|
|
pluginFields = append(pluginFields, k)
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Sort(sortedPlugins(pluginFields))
|
2016-07-25 10:38:24 -07:00
|
|
|
|
2016-06-13 19:52:49 -07:00
|
|
|
// parse []string labels into a map[string]string
|
|
|
|
labels := map[string]string{}
|
|
|
|
for _, l := range info.Labels {
|
|
|
|
stringSlice := strings.SplitN(l, "=", 2)
|
|
|
|
// this will take the last value in the list for a given key
|
|
|
|
// ideally, one shouldn't assign multiple values to the same key
|
|
|
|
if len(stringSlice) > 1 {
|
|
|
|
labels[stringSlice[0]] = stringSlice[1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
description := &api.NodeDescription{
|
|
|
|
Hostname: info.Name,
|
|
|
|
Platform: &api.Platform{
|
|
|
|
Architecture: info.Architecture,
|
|
|
|
OS: info.OSType,
|
|
|
|
},
|
|
|
|
Engine: &api.EngineDescription{
|
|
|
|
EngineVersion: info.ServerVersion,
|
|
|
|
Labels: labels,
|
2016-07-25 17:16:31 -07:00
|
|
|
Plugins: pluginFields,
|
2016-06-13 19:52:49 -07:00
|
|
|
},
|
|
|
|
Resources: &api.Resources{
|
|
|
|
NanoCPUs: int64(info.NCPU) * 1e9,
|
|
|
|
MemoryBytes: info.MemTotal,
|
2017-05-30 17:02:11 -07:00
|
|
|
Generic: convert.GenericResourcesToGRPC(info.GenericResources),
|
2016-06-13 19:52:49 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-08-30 21:45:05 +02:00
|
|
|
// Save the node information in the executor field
|
|
|
|
e.mutex.Lock()
|
|
|
|
e.node = description
|
|
|
|
e.mutex.Unlock()
|
|
|
|
|
2016-06-13 19:52:49 -07:00
|
|
|
return description, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *executor) Configure(ctx context.Context, node *api.Node) error {
|
2017-08-28 23:49:26 -07:00
|
|
|
var ingressNA *api.NetworkAttachment
|
2017-09-21 23:04:34 -07:00
|
|
|
attachments := make(map[string]string)
|
2017-08-28 23:49:26 -07:00
|
|
|
|
2017-09-21 23:04:34 -07:00
|
|
|
for _, na := range node.Attachments {
|
2018-04-02 16:09:15 -07:00
|
|
|
if na == nil || na.Network == nil || len(na.Addresses) == 0 {
|
|
|
|
// this should not happen, but we got a panic here and don't have a
|
|
|
|
// good idea about what the underlying data structure looks like.
|
|
|
|
logrus.WithField("NetworkAttachment", fmt.Sprintf("%#v", na)).
|
|
|
|
Warnf("skipping nil or malformed node network attachment entry")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2017-08-28 23:49:26 -07:00
|
|
|
if na.Network.Spec.Ingress {
|
|
|
|
ingressNA = na
|
|
|
|
}
|
2018-04-02 16:09:15 -07:00
|
|
|
|
2017-09-21 23:04:34 -07:00
|
|
|
attachments[na.Network.ID] = na.Addresses[0]
|
2017-08-28 23:49:26 -07:00
|
|
|
}
|
|
|
|
|
Fix possible overlapping IPs
A node is no longer using its load balancer IP address when it no longer
has tasks that use the network that requires that load balancer. When
this occurs, the swarmkit manager will free that IP in IPAM, and may
reaassign it.
When a task shuts down cleanly, it attempts removal of the networks it
uses, and if it is the last task using those networks, this removal
succeeds, and the load balancer IP is freed.
However, this behavior is absent if the container fails. Removal of the
networks is never attempted.
To address this issue, I amend the executor. Whenever a node load
balancer IP is removed or changed, that information is passedd to the
executor by way of the Configure method. By keeping track of the set of
node NetworkAttachments from the previous call to Configure, we can
determine which, if any, have been removed or changed.
At first, this seems to create a race, by which a task can be attempting
to start and the network is removed right out from under it. However,
this is already addressed in the controller. The controller will attempt
to recreate missing networks before starting a task.
Signed-off-by: Drew Erny <derny@mirantis.com>
2021-05-10 14:11:13 -06:00
|
|
|
// discover which, if any, attachments have been removed.
|
|
|
|
//
|
|
|
|
// we aren't responsible directly for creating these networks. that is
|
|
|
|
// handled indirectly when a container using that network is created.
|
|
|
|
// however, when it comes time to remove the network, none of the relevant
|
|
|
|
// tasks may exist anymore. this means we should go ahead and try to remove
|
|
|
|
// any network we know to no longer be in use.
|
|
|
|
|
|
|
|
// removeAttachments maps the network ID to a boolean. This boolean
|
|
|
|
// indicates whether the attachment in question is totally removed (true),
|
|
|
|
// or has just had its IP changed (false)
|
|
|
|
removeAttachments := make(map[string]bool)
|
|
|
|
|
|
|
|
// the first time we Configure, nodeObj wil be nil, because it will not be
|
|
|
|
// set yet. in that case, skip this check.
|
|
|
|
if e.nodeObj != nil {
|
|
|
|
for _, na := range e.nodeObj.Attachments {
|
|
|
|
// same thing as above, check sanity of the attachments so we don't
|
|
|
|
// get a panic.
|
|
|
|
if na == nil || na.Network == nil || len(na.Addresses) == 0 {
|
|
|
|
logrus.WithField("NetworkAttachment", fmt.Sprintf("%#v", na)).
|
|
|
|
Warnf("skipping nil or malformed node network attachment entry")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// now, check if the attachment exists and shares the same IP address.
|
|
|
|
if ip, ok := attachments[na.Network.ID]; !ok || na.Addresses[0] != ip {
|
|
|
|
// if the map entry exists, then the network still exists, and the
|
|
|
|
// IP must be what has changed
|
|
|
|
removeAttachments[na.Network.ID] = !ok
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 16:09:15 -07:00
|
|
|
if (ingressNA == nil) && (node.Attachment != nil) && (len(node.Attachment.Addresses) > 0) {
|
2018-01-12 09:27:30 +00:00
|
|
|
ingressNA = node.Attachment
|
|
|
|
attachments[ingressNA.Network.ID] = ingressNA.Addresses[0]
|
|
|
|
}
|
|
|
|
|
2017-08-28 23:49:26 -07:00
|
|
|
if ingressNA == nil {
|
2017-03-09 11:52:25 -08:00
|
|
|
e.backend.ReleaseIngress()
|
2017-09-21 23:04:34 -07:00
|
|
|
return e.backend.GetAttachmentStore().ResetAttachments(attachments)
|
2016-06-13 19:52:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
options := types.NetworkCreate{
|
2017-08-28 23:49:26 -07:00
|
|
|
Driver: ingressNA.Network.DriverState.Name,
|
2016-08-31 17:25:14 +02:00
|
|
|
IPAM: &network.IPAM{
|
2017-08-28 23:49:26 -07:00
|
|
|
Driver: ingressNA.Network.IPAM.Driver.Name,
|
2016-06-13 19:52:49 -07:00
|
|
|
},
|
2017-08-28 23:49:26 -07:00
|
|
|
Options: ingressNA.Network.DriverState.Options,
|
2017-03-09 11:52:25 -08:00
|
|
|
Ingress: true,
|
2016-06-13 19:52:49 -07:00
|
|
|
CheckDuplicate: true,
|
|
|
|
}
|
|
|
|
|
2017-08-28 23:49:26 -07:00
|
|
|
for _, ic := range ingressNA.Network.IPAM.Configs {
|
2016-06-13 19:52:49 -07:00
|
|
|
c := network.IPAMConfig{
|
|
|
|
Subnet: ic.Subnet,
|
|
|
|
IPRange: ic.Range,
|
|
|
|
Gateway: ic.Gateway,
|
|
|
|
}
|
|
|
|
options.IPAM.Config = append(options.IPAM.Config, c)
|
|
|
|
}
|
|
|
|
|
2017-03-31 14:07:55 -07:00
|
|
|
_, err := e.backend.SetupIngress(clustertypes.NetworkCreateRequest{
|
2017-08-28 23:49:26 -07:00
|
|
|
ID: ingressNA.Network.ID,
|
2016-11-29 19:36:56 +08:00
|
|
|
NetworkCreateRequest: types.NetworkCreateRequest{
|
2017-08-28 23:49:26 -07:00
|
|
|
Name: ingressNA.Network.Spec.Annotations.Name,
|
2016-06-13 19:52:49 -07:00
|
|
|
NetworkCreate: options,
|
|
|
|
},
|
2017-08-28 23:49:26 -07:00
|
|
|
}, ingressNA.Addresses[0])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-03-31 14:07:55 -07:00
|
|
|
|
Fix possible overlapping IPs
A node is no longer using its load balancer IP address when it no longer
has tasks that use the network that requires that load balancer. When
this occurs, the swarmkit manager will free that IP in IPAM, and may
reaassign it.
When a task shuts down cleanly, it attempts removal of the networks it
uses, and if it is the last task using those networks, this removal
succeeds, and the load balancer IP is freed.
However, this behavior is absent if the container fails. Removal of the
networks is never attempted.
To address this issue, I amend the executor. Whenever a node load
balancer IP is removed or changed, that information is passedd to the
executor by way of the Configure method. By keeping track of the set of
node NetworkAttachments from the previous call to Configure, we can
determine which, if any, have been removed or changed.
At first, this seems to create a race, by which a task can be attempting
to start and the network is removed right out from under it. However,
this is already addressed in the controller. The controller will attempt
to recreate missing networks before starting a task.
Signed-off-by: Drew Erny <derny@mirantis.com>
2021-05-10 14:11:13 -06:00
|
|
|
var (
|
|
|
|
activeEndpointsError *libnetwork.ActiveEndpointsError
|
|
|
|
errNoSuchNetwork libnetwork.ErrNoSuchNetwork
|
|
|
|
)
|
|
|
|
|
|
|
|
// now, finally, remove any network LB attachments that we no longer have.
|
|
|
|
for nw, gone := range removeAttachments {
|
|
|
|
err := e.backend.DeleteManagedNetwork(nw)
|
|
|
|
switch {
|
|
|
|
case err == nil:
|
|
|
|
continue
|
|
|
|
case errors.As(err, &activeEndpointsError):
|
|
|
|
// this is the purpose of the boolean in the map. it's literally
|
|
|
|
// just to log an appropriate, informative error. i'm unsure if
|
|
|
|
// this can ever actually occur, but we need to know if it does.
|
|
|
|
if gone {
|
|
|
|
log.G(ctx).Warnf("network %s should be removed, but still has active attachments", nw)
|
|
|
|
} else {
|
|
|
|
log.G(ctx).Warnf(
|
|
|
|
"network %s should have its node LB IP changed, but cannot be removed because of active attachments",
|
|
|
|
nw,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
case errors.As(err, &errNoSuchNetwork):
|
|
|
|
// NoSuchNetworkError indicates the network is already gone.
|
|
|
|
continue
|
|
|
|
default:
|
|
|
|
log.G(ctx).Errorf("network %s remove failed: %v", nw, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now update our copy of the node object, reset the attachment store, and
|
|
|
|
// return
|
|
|
|
e.nodeObj = node
|
|
|
|
|
2017-09-21 23:04:34 -07:00
|
|
|
return e.backend.GetAttachmentStore().ResetAttachments(attachments)
|
2016-06-13 19:52:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Controller returns a docker container runner.
|
2016-10-27 10:34:58 -07:00
|
|
|
func (e *executor) Controller(t *api.Task) (exec.Controller, error) {
|
2017-06-15 11:21:05 -07:00
|
|
|
dependencyGetter := template.NewTemplatedDependencyGetter(agent.Restrict(e.dependencies, t), t, nil)
|
2017-03-16 14:23:33 -07:00
|
|
|
|
2017-08-30 21:45:05 +02:00
|
|
|
// Get the node description from the executor field
|
|
|
|
e.mutex.Lock()
|
|
|
|
nodeDescription := e.node
|
|
|
|
e.mutex.Unlock()
|
|
|
|
|
2016-08-23 16:50:15 -07:00
|
|
|
if t.Spec.GetAttachment() != nil {
|
2018-03-22 17:11:03 -04:00
|
|
|
return newNetworkAttacherController(e.backend, e.imageBackend, e.volumeBackend, t, nodeDescription, dependencyGetter)
|
2016-08-23 16:50:15 -07:00
|
|
|
}
|
|
|
|
|
2017-03-01 15:52:55 -05:00
|
|
|
var ctlr exec.Controller
|
|
|
|
switch r := t.Spec.GetRuntime().(type) {
|
|
|
|
case *api.TaskSpec_Generic:
|
|
|
|
logrus.WithFields(logrus.Fields{
|
2017-03-24 15:19:59 -04:00
|
|
|
"kind": r.Generic.Kind,
|
|
|
|
"type_url": r.Generic.Payload.TypeUrl,
|
2017-03-01 15:52:55 -05:00
|
|
|
}).Debug("custom runtime requested")
|
|
|
|
runtimeKind, err := naming.Runtime(t.Spec)
|
|
|
|
if err != nil {
|
|
|
|
return ctlr, err
|
|
|
|
}
|
|
|
|
switch runtimeKind {
|
|
|
|
case string(swarmtypes.RuntimePlugin):
|
2019-02-28 16:52:30 -08:00
|
|
|
if !e.backend.HasExperimental() {
|
2017-08-08 18:33:25 -07:00
|
|
|
return ctlr, fmt.Errorf("runtime type %q only supported in experimental", swarmtypes.RuntimePlugin)
|
|
|
|
}
|
2017-06-07 13:07:01 -04:00
|
|
|
c, err := plugin.NewController(e.pluginBackend, t)
|
2017-03-01 15:52:55 -05:00
|
|
|
if err != nil {
|
|
|
|
return ctlr, err
|
|
|
|
}
|
|
|
|
ctlr = c
|
|
|
|
default:
|
2017-08-08 18:33:25 -07:00
|
|
|
return ctlr, fmt.Errorf("unsupported runtime type: %q", runtimeKind)
|
2017-03-01 15:52:55 -05:00
|
|
|
}
|
|
|
|
case *api.TaskSpec_Container:
|
2018-03-22 17:11:03 -04:00
|
|
|
c, err := newController(e.backend, e.imageBackend, e.volumeBackend, t, nodeDescription, dependencyGetter)
|
2017-03-01 15:52:55 -05:00
|
|
|
if err != nil {
|
2017-03-27 10:51:42 -04:00
|
|
|
return ctlr, err
|
2017-03-01 15:52:55 -05:00
|
|
|
}
|
|
|
|
ctlr = c
|
|
|
|
default:
|
2017-03-27 10:51:42 -04:00
|
|
|
return ctlr, fmt.Errorf("unsupported runtime: %q", r)
|
2016-06-13 19:52:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return ctlr, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *executor) SetNetworkBootstrapKeys(keys []*api.EncryptionKey) error {
|
|
|
|
nwKeys := []*networktypes.EncryptionKey{}
|
|
|
|
for _, key := range keys {
|
|
|
|
nwKey := &networktypes.EncryptionKey{
|
|
|
|
Subsystem: key.Subsystem,
|
|
|
|
Algorithm: int32(key.Algorithm),
|
|
|
|
Key: make([]byte, len(key.Key)),
|
|
|
|
LamportTime: key.LamportTime,
|
|
|
|
}
|
|
|
|
copy(nwKey.Key, key.Key)
|
|
|
|
nwKeys = append(nwKeys, nwKey)
|
|
|
|
}
|
|
|
|
e.backend.SetNetworkBootstrapKeys(nwKeys)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2016-07-25 10:38:24 -07:00
|
|
|
|
2016-10-27 10:34:58 -07:00
|
|
|
func (e *executor) Secrets() exec.SecretsManager {
|
2017-03-16 14:23:33 -07:00
|
|
|
return e.dependencies.Secrets()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *executor) Configs() exec.ConfigsManager {
|
|
|
|
return e.dependencies.Configs()
|
2016-10-27 10:34:58 -07:00
|
|
|
}
|
|
|
|
|
2016-07-25 10:38:24 -07:00
|
|
|
type sortedPlugins []api.PluginDescription
|
|
|
|
|
|
|
|
func (sp sortedPlugins) Len() int { return len(sp) }
|
|
|
|
|
|
|
|
func (sp sortedPlugins) Swap(i, j int) { sp[i], sp[j] = sp[j], sp[i] }
|
|
|
|
|
|
|
|
func (sp sortedPlugins) Less(i, j int) bool {
|
|
|
|
if sp[i].Type != sp[j].Type {
|
|
|
|
return sp[i].Type < sp[j].Type
|
|
|
|
}
|
|
|
|
return sp[i].Name < sp[j].Name
|
|
|
|
}
|