Skip to content

Commit dceb997

Browse files
committed
Remove inappropriate allocator import
Removes inappropriate import of manager/allocator/cnmallocator into node/node.go. The consequence of this is that in upstream moby/moby, we can remove that import as well. manager/allocator/cnmallocator is an implementation detail, and importing it so high in the stack creates an unacceptably high degree of coupling. Signed-off-by: Drew Erny <[email protected]>
1 parent b7708a5 commit dceb997

File tree

2 files changed

+44
-25
lines changed

2 files changed

+44
-25
lines changed

manager/manager.go

+28-21
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,15 @@ type Config struct {
132132
// FIPS setting.
133133
FIPS bool
134134

135-
// NetworkConfig stores network related config for the cluster
136-
NetworkConfig *cnmallocator.NetworkConfig
135+
// DefaultAddrPool specifies default subnet pool for global scope networks
136+
DefaultAddrPool []string
137+
138+
// SubnetSize specifies the subnet size of the networks created from
139+
// the default subnet pool
140+
SubnetSize uint32
141+
142+
// VXLANUDPPort specifies the UDP port number for VXLAN traffic
143+
VXLANUDPPort uint32
137144
}
138145

139146
// Manager is the cluster manager for Swarm.
@@ -961,15 +968,13 @@ func (m *Manager) becomeLeader(ctx context.Context) {
961968

962969
// If defaultAddrPool is valid we update cluster object with new value
963970
// If VXLANUDPPort is not 0 then we call update cluster object with new value
964-
if m.config.NetworkConfig != nil {
965-
if m.config.NetworkConfig.DefaultAddrPool != nil {
966-
clusterObj.DefaultAddressPool = m.config.NetworkConfig.DefaultAddrPool
967-
clusterObj.SubnetSize = m.config.NetworkConfig.SubnetSize
968-
}
971+
if m.config.DefaultAddrPool != nil {
972+
clusterObj.DefaultAddressPool = m.config.DefaultAddrPool
973+
clusterObj.SubnetSize = m.config.SubnetSize
974+
}
969975

970-
if m.config.NetworkConfig.VXLANUDPPort != 0 {
971-
clusterObj.VXLANUDPPort = m.config.NetworkConfig.VXLANUDPPort
972-
}
976+
if m.config.VXLANUDPPort != 0 {
977+
clusterObj.VXLANUDPPort = m.config.VXLANUDPPort
973978
}
974979
err := store.CreateCluster(tx, clusterObj)
975980

@@ -1021,27 +1026,29 @@ func (m *Manager) becomeLeader(ctx context.Context) {
10211026
// If DefaultAddrPool is null, Read from store and check if
10221027
// DefaultAddrPool info is stored in cluster object
10231028
// If VXLANUDPPort is 0, read it from the store - cluster object
1024-
if m.config.NetworkConfig == nil || m.config.NetworkConfig.DefaultAddrPool == nil || m.config.NetworkConfig.VXLANUDPPort == 0 {
1029+
if m.config.DefaultAddrPool == nil || m.config.VXLANUDPPort == 0 {
10251030
var cluster *api.Cluster
10261031
s.View(func(tx store.ReadTx) {
10271032
cluster = store.GetCluster(tx, clusterID)
10281033
})
10291034
if cluster.DefaultAddressPool != nil {
1030-
if m.config.NetworkConfig == nil {
1031-
m.config.NetworkConfig = &cnmallocator.NetworkConfig{}
1032-
}
1033-
m.config.NetworkConfig.DefaultAddrPool = append(m.config.NetworkConfig.DefaultAddrPool, cluster.DefaultAddressPool...)
1034-
m.config.NetworkConfig.SubnetSize = cluster.SubnetSize
1035+
m.config.DefaultAddrPool = append(m.config.DefaultAddrPool, cluster.DefaultAddressPool...)
1036+
m.config.SubnetSize = cluster.SubnetSize
10351037
}
10361038
if cluster.VXLANUDPPort != 0 {
1037-
if m.config.NetworkConfig == nil {
1038-
m.config.NetworkConfig = &cnmallocator.NetworkConfig{}
1039-
}
1040-
m.config.NetworkConfig.VXLANUDPPort = cluster.VXLANUDPPort
1039+
m.config.VXLANUDPPort = cluster.VXLANUDPPort
10411040
}
10421041
}
10431042

1044-
m.allocator, err = allocator.New(s, m.config.PluginGetter, m.config.NetworkConfig)
1043+
// Toss all this info into a netCfg, so that the allocator can do its
1044+
// thing.
1045+
netCfg := &cnmallocator.NetworkConfig{
1046+
DefaultAddrPool: m.config.DefaultAddrPool,
1047+
SubnetSize: m.config.SubnetSize,
1048+
VXLANUDPPort: m.config.VXLANUDPPort,
1049+
}
1050+
1051+
m.allocator, err = allocator.New(s, m.config.PluginGetter, netCfg)
10451052
if err != nil {
10461053
log.G(ctx).WithError(err).Error("failed to create allocator")
10471054
// TODO(stevvooe): It doesn't seem correct here to fail

node/node.go

+16-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"github.com/moby/swarmkit/v2/ioutils"
3030
"github.com/moby/swarmkit/v2/log"
3131
"github.com/moby/swarmkit/v2/manager"
32-
"github.com/moby/swarmkit/v2/manager/allocator/cnmallocator"
3332
"github.com/moby/swarmkit/v2/manager/encryption"
3433
"github.com/moby/swarmkit/v2/remotes"
3534
"github.com/moby/swarmkit/v2/xnet"
@@ -106,8 +105,19 @@ type Config struct {
106105
// for connections to the remote API (including the raft service).
107106
AdvertiseRemoteAPI string
108107

109-
// NetworkConfig stores network related config for the cluster
110-
NetworkConfig *cnmallocator.NetworkConfig
108+
// DefaultAddrPool specifies default subnet pool for global scope networks
109+
// This duplicates information found in a type deeper in the stack
110+
// (manager/allocation/cnmallocator.NetworkConfig) but is brought up to
111+
// the top level in this config file to avoid creating a dependency from
112+
// this node package to any deeper levels.
113+
DefaultAddrPool []string
114+
115+
// SubnetSize specifies the subnet size of the networks created from
116+
// the default subnet pool
117+
SubnetSize uint32
118+
119+
// VXLANUDPPort specifies the UDP port number for VXLAN traffic
120+
VXLANUDPPort uint32
111121

112122
// Executor specifies the executor to use for the agent.
113123
Executor exec.Executor
@@ -1014,7 +1024,9 @@ func (n *Node) runManager(ctx context.Context, securityConfig *ca.SecurityConfig
10141024
PluginGetter: n.config.PluginGetter,
10151025
RootCAPaths: rootPaths,
10161026
FIPS: n.config.FIPS,
1017-
NetworkConfig: n.config.NetworkConfig,
1027+
DefaultAddrPool: n.config.DefaultAddrPool,
1028+
SubnetSize: n.config.SubnetSize,
1029+
VXLANUDPPort: n.config.VXLANUDPPort,
10181030
})
10191031
if err != nil {
10201032
return false, err

0 commit comments

Comments
 (0)