@@ -51,6 +51,8 @@ const (
51
51
openStackFloatingIPPool = "OpenStackFloatingIPPool"
52
52
)
53
53
54
+ var errMaxIPsReached = errors .New ("maximum number of IPs reached" )
55
+
54
56
var backoff = wait.Backoff {
55
57
Steps : 4 ,
56
58
Duration : 10 * time .Millisecond ,
@@ -139,6 +141,10 @@ func (r *OpenStackFloatingIPPoolReconciler) Reconcile(ctx context.Context, req c
139
141
if apierrors .IsNotFound (err ) {
140
142
ip , err := r .getIP (ctx , scope , pool )
141
143
if err != nil {
144
+ if errors .Is (err , errMaxIPsReached ) {
145
+ log .Info ("Maximum number of IPs reached, will not allocate more IPs." )
146
+ return ctrl.Result {}, nil
147
+ }
142
148
return ctrl.Result {}, err
143
149
}
144
150
@@ -193,6 +199,7 @@ func (r *OpenStackFloatingIPPoolReconciler) Reconcile(ctx context.Context, req c
193
199
scope .Logger ().Info ("Claimed IP" , "ip" , ipAddress .Spec .Address )
194
200
}
195
201
}
202
+ conditions .MarkTrue (pool , infrav1alpha1 .OpenstackFloatingIPPoolReadyCondition )
196
203
return ctrl.Result {}, r .Client .Status ().Update (ctx , pool )
197
204
}
198
205
@@ -296,8 +303,10 @@ func (r *OpenStackFloatingIPPoolReconciler) reconcileIPAddresses(ctx context.Con
296
303
return err
297
304
}
298
305
}
306
+
299
307
unclaimedPreAllocatedIPs := diff (pool .Spec .PreAllocatedFloatingIPs , pool .Status .ClaimedIPs )
300
308
unclaimedIPs := union (pool .Status .AvailableIPs , unclaimedPreAllocatedIPs )
309
+ unclaimedIPs = diff (unclaimedIPs , pool .Status .ClaimedIPs )
301
310
pool .Status .AvailableIPs = diff (unclaimedIPs , pool .Status .FailedIPs )
302
311
return nil
303
312
}
@@ -340,9 +349,17 @@ func (r *OpenStackFloatingIPPoolReconciler) getIP(ctx context.Context, scope sco
340
349
return "" , fmt .Errorf ("get floating IP: %w" , err )
341
350
}
342
351
if fp != nil {
352
+ pool .Status .ClaimedIPs = append (pool .Status .ClaimedIPs , fp .FloatingIP )
343
353
return fp .FloatingIP , nil
344
354
}
345
355
}
356
+ maxIPs := pointer .IntDeref (pool .Spec .MaxIPs , - 1 )
357
+ // If we have reached the maximum number of IPs, we should not create more IPs
358
+ if maxIPs != - 1 && len (pool .Status .ClaimedIPs ) >= maxIPs {
359
+ scope .Logger ().Info ("MaxIPs reached" , "pool" , pool .Name )
360
+ conditions .MarkFalse (pool , infrav1alpha1 .OpenstackFloatingIPPoolReadyCondition , infrav1alpha1 .MaxIPsReachedReason , clusterv1 .ConditionSeverityError , "Maximum number of IPs reached, we will not allocate more IPs for this pool" )
361
+ return "" , errMaxIPsReached
362
+ }
346
363
347
364
fp , err := networkingService .CreateFloatingIPForPool (pool )
348
365
if err != nil {
@@ -369,7 +386,6 @@ func (r *OpenStackFloatingIPPoolReconciler) getIP(ctx context.Context, scope sco
369
386
}()
370
387
371
388
conditions .MarkTrue (pool , infrav1alpha1 .OpenstackFloatingIPPoolReadyCondition )
372
-
373
389
ip = fp .FloatingIP
374
390
pool .Status .ClaimedIPs = append (pool .Status .ClaimedIPs , ip )
375
391
return ip , nil
0 commit comments