Browse code

Fix possible overlapping IPs when ingressNA == nil

Logic was added to the Swarm executor in commit 0d9b0ed678e2b106e769e974f13aaf100e46351c
to clean up managed networks whenever the node's load-balancer IP
address is removed or changed in order to free up the address in the
case where the container fails to start entirely. Unfortunately, due to
an oversight the function returns early if the Swarm is lacking
an ingress network. Remove the early return so that load-balancer IP
addresses for all the other networks are freed as appropriate,
irrespective of whether an ingress network exists in the Swarm.

Signed-off-by: Cory Snider <csnider@mirantis.com>

Cory Snider authored on 2025/05/10 01:24:27
Showing 1 changed files
... ...
@@ -213,36 +213,35 @@ func (e *executor) Configure(ctx context.Context, node *api.Node) error {
213 213
 
214 214
 	if ingressNA == nil {
215 215
 		e.backend.ReleaseIngress()
216
-		return e.backend.GetAttachmentStore().ResetAttachments(attachments)
217
-	}
218
-
219
-	options := network.CreateOptions{
220
-		Driver: ingressNA.Network.DriverState.Name,
221
-		IPAM: &network.IPAM{
222
-			Driver: ingressNA.Network.IPAM.Driver.Name,
223
-		},
224
-		Options: ingressNA.Network.DriverState.Options,
225
-		Ingress: true,
226
-	}
216
+	} else {
217
+		options := network.CreateOptions{
218
+			Driver: ingressNA.Network.DriverState.Name,
219
+			IPAM: &network.IPAM{
220
+				Driver: ingressNA.Network.IPAM.Driver.Name,
221
+			},
222
+			Options: ingressNA.Network.DriverState.Options,
223
+			Ingress: true,
224
+		}
227 225
 
228
-	for _, ic := range ingressNA.Network.IPAM.Configs {
229
-		c := network.IPAMConfig{
230
-			Subnet:  ic.Subnet,
231
-			IPRange: ic.Range,
232
-			Gateway: ic.Gateway,
226
+		for _, ic := range ingressNA.Network.IPAM.Configs {
227
+			c := network.IPAMConfig{
228
+				Subnet:  ic.Subnet,
229
+				IPRange: ic.Range,
230
+				Gateway: ic.Gateway,
231
+			}
232
+			options.IPAM.Config = append(options.IPAM.Config, c)
233 233
 		}
234
-		options.IPAM.Config = append(options.IPAM.Config, c)
235
-	}
236 234
 
237
-	_, err := e.backend.SetupIngress(clustertypes.NetworkCreateRequest{
238
-		ID: ingressNA.Network.ID,
239
-		CreateRequest: network.CreateRequest{
240
-			Name:          ingressNA.Network.Spec.Annotations.Name,
241
-			CreateOptions: options,
242
-		},
243
-	}, ingressNA.Addresses[0])
244
-	if err != nil {
245
-		return err
235
+		_, err := e.backend.SetupIngress(clustertypes.NetworkCreateRequest{
236
+			ID: ingressNA.Network.ID,
237
+			CreateRequest: network.CreateRequest{
238
+				Name:          ingressNA.Network.Spec.Annotations.Name,
239
+				CreateOptions: options,
240
+			},
241
+		}, ingressNA.Addresses[0])
242
+		if err != nil {
243
+			return err
244
+		}
246 245
 	}
247 246
 
248 247
 	var (