@@ -132,8 +132,15 @@ type Config struct {
132
132
// FIPS setting.
133
133
FIPS bool
134
134
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
137
144
}
138
145
139
146
// Manager is the cluster manager for Swarm.
@@ -961,15 +968,13 @@ func (m *Manager) becomeLeader(ctx context.Context) {
961
968
962
969
// If defaultAddrPool is valid we update cluster object with new value
963
970
// 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
+ }
969
975
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
973
978
}
974
979
err := store .CreateCluster (tx , clusterObj )
975
980
@@ -1021,27 +1026,29 @@ func (m *Manager) becomeLeader(ctx context.Context) {
1021
1026
// If DefaultAddrPool is null, Read from store and check if
1022
1027
// DefaultAddrPool info is stored in cluster object
1023
1028
// 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 {
1025
1030
var cluster * api.Cluster
1026
1031
s .View (func (tx store.ReadTx ) {
1027
1032
cluster = store .GetCluster (tx , clusterID )
1028
1033
})
1029
1034
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
1035
1037
}
1036
1038
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
1041
1040
}
1042
1041
}
1043
1042
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 )
1045
1052
if err != nil {
1046
1053
log .G (ctx ).WithError (err ).Error ("failed to create allocator" )
1047
1054
// TODO(stevvooe): It doesn't seem correct here to fail
0 commit comments