@@ -27,7 +27,6 @@ import (
27
27
"k8s.io/apimachinery/pkg/runtime"
28
28
"k8s.io/client-go/tools/record"
29
29
"k8s.io/utils/pointer"
30
- clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
31
30
ipamv1 "sigs.k8s.io/cluster-api/exp/ipam/api/v1alpha1"
32
31
"sigs.k8s.io/cluster-api/util/patch"
33
32
ctrl "sigs.k8s.io/controller-runtime"
@@ -66,7 +65,6 @@ type OpenStackFloatingIPPoolReconciler struct {
66
65
// - https://pkg.go.dev/sigs.k8s.io/[email protected] /pkg/reconcile
67
66
func (r * OpenStackFloatingIPPoolReconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (_ ctrl.Result , reterr error ) {
68
67
log := ctrl .LoggerFrom (ctx )
69
-
70
68
pool := & infrav1.OpenStackFloatingIPPool {}
71
69
if err := r .Client .Get (ctx , req .NamespacedName , pool ); err != nil {
72
70
return ctrl.Result {}, client .IgnoreNotFound (err )
@@ -84,7 +82,7 @@ func (r *OpenStackFloatingIPPoolReconciler) Reconcile(ctx context.Context, req c
84
82
}
85
83
} else {
86
84
// Handle deletion
87
- return r .reconcileDelete (ctx , scope , pool )
85
+ return ctrl. Result {}, r .reconcileDelete (ctx , scope , pool )
88
86
}
89
87
90
88
patchHelper , err := patch .NewHelper (pool , r .Client )
@@ -100,11 +98,11 @@ func (r *OpenStackFloatingIPPoolReconciler) Reconcile(ctx context.Context, req c
100
98
}
101
99
}()
102
100
103
- if err := r .reconcileFloatingIPNetwork (ctx , scope , pool ); err != nil {
101
+ if err := r .reconcileFloatingIPNetwork (scope , pool ); err != nil {
104
102
return ctrl.Result {}, err
105
103
}
106
104
107
- if err := r .setIPStatuses (ctx , scope , pool ); err != nil {
105
+ if err := r .setIPStatuses (ctx , pool ); err != nil {
108
106
return ctrl.Result {}, err
109
107
}
110
108
@@ -128,7 +126,7 @@ func (r *OpenStackFloatingIPPoolReconciler) Reconcile(ctx context.Context, req c
128
126
continue
129
127
}
130
128
131
- ip , err := r .getIP (ctx , scope , pool )
129
+ ip , err := r .getIP (scope , pool )
132
130
if err != nil {
133
131
return ctrl.Result {}, err
134
132
}
@@ -177,42 +175,42 @@ func (r *OpenStackFloatingIPPoolReconciler) Reconcile(ctx context.Context, req c
177
175
scope .Logger ().Info ("Claimed IP" , "ip" , ip )
178
176
}
179
177
}
180
- if err = r .setIPStatuses (ctx , scope , pool ); err != nil {
178
+ if err = r .setIPStatuses (ctx , pool ); err != nil {
181
179
return ctrl.Result {}, err
182
180
}
183
181
return ctrl.Result {}, nil
184
182
}
185
183
186
- func (r * OpenStackFloatingIPPoolReconciler ) reconcileDelete (ctx context.Context , scope scope.Scope , pool * infrav1.OpenStackFloatingIPPool ) (ctrl. Result , error ) {
184
+ func (r * OpenStackFloatingIPPoolReconciler ) reconcileDelete (ctx context.Context , scope scope.Scope , pool * infrav1.OpenStackFloatingIPPool ) error {
187
185
log := ctrl .LoggerFrom (ctx )
188
186
ipAddresses := & ipamv1.IPAddressList {}
189
187
if err := r .Client .List (ctx , ipAddresses , client .InNamespace (pool .Namespace ), client.MatchingFields {infrav1 .OpenStackFloatingIPPoolNameIndex : pool .Name }); err != nil {
190
- return ctrl. Result {}, err
188
+ return err
191
189
}
192
190
// If there are still IPAddress objects that are not deleted, there are still claims on this pool and we should not delete it
193
191
// beause the pool is needed to clean up the addresses from openstack
194
192
if len (ipAddresses .Items ) > 0 {
195
193
log .Info ("Waiting for IPAddress to be deleted before deleting OpenStackFloatingIPPool" )
196
- return ctrl. Result {}, errors .New ("waiting for IPAddress to be deleted, until we can delete the OpenStackFloatingIPPool" )
194
+ return errors .New ("waiting for IPAddress to be deleted, until we can delete the OpenStackFloatingIPPool" )
197
195
}
198
196
199
197
networkingService , err := networking .NewService (scope )
200
198
if err != nil {
201
- return ctrl. Result {}, err
199
+ return err
202
200
}
203
201
204
202
// Clean up ips created by the pool
205
203
for _ , ip := range diff (pool .Status .IPs , pool .Spec .PreAllocatedFloatingIPs ) {
206
204
if err := networkingService .DeleteFloatingIP (pool , ip ); err != nil {
207
- return ctrl. Result {}, fmt .Errorf ("delete floating IP: %w" , err )
205
+ return fmt .Errorf ("delete floating IP: %w" , err )
208
206
}
209
207
}
210
208
211
209
if controllerutil .RemoveFinalizer (pool , infrav1 .OpenStackFloatingIPPoolFinalizer ) {
212
210
log .Info ("Removing finalizer from OpenStackFloatingIPPool" )
213
- return ctrl. Result {}, r .Client .Update (ctx , pool )
211
+ return r .Client .Update (ctx , pool )
214
212
}
215
- return ctrl. Result {}, nil
213
+ return nil
216
214
}
217
215
218
216
func union (a []string , b []string ) []string {
@@ -245,7 +243,7 @@ func diff(a []string, b []string) []string {
245
243
return result
246
244
}
247
245
248
- func (r * OpenStackFloatingIPPoolReconciler ) setIPStatuses (ctx context.Context , scope scope. Scope , pool * infrav1.OpenStackFloatingIPPool ) error {
246
+ func (r * OpenStackFloatingIPPoolReconciler ) setIPStatuses (ctx context.Context , pool * infrav1.OpenStackFloatingIPPool ) error {
249
247
ipAddresses := & ipamv1.IPAddressList {}
250
248
if err := r .Client .List (ctx , ipAddresses , client .InNamespace (pool .Namespace ), client.MatchingFields {infrav1 .OpenStackFloatingIPPoolNameIndex : pool .Name }); err != nil {
251
249
return err
@@ -254,16 +252,14 @@ func (r *OpenStackFloatingIPPoolReconciler) setIPStatuses(ctx context.Context, s
254
252
for _ , ip := range ipAddresses .Items {
255
253
pool .Status .ClaimedIPs = append (pool .Status .ClaimedIPs , ip .Spec .Address )
256
254
}
257
- for _ , ip := range pool .Spec .PreAllocatedFloatingIPs {
258
- pool .Status .IPs = append (pool .Status .IPs , ip )
259
- }
255
+ pool .Status .IPs = append ([]string {}, pool .Spec .PreAllocatedFloatingIPs ... )
260
256
261
257
pool .Status .IPs = union (pool .Status .IPs , pool .Status .ClaimedIPs )
262
258
pool .Status .AvailableIPs = diff (diff (pool .Status .IPs , pool .Status .ClaimedIPs ), pool .Status .FailedIPs )
263
259
return nil
264
260
}
265
261
266
- func (r * OpenStackFloatingIPPoolReconciler ) getIP (ctx context. Context , scope scope.Scope , pool * infrav1.OpenStackFloatingIPPool ) (string , error ) {
262
+ func (r * OpenStackFloatingIPPoolReconciler ) getIP (scope scope.Scope , pool * infrav1.OpenStackFloatingIPPool ) (string , error ) {
267
263
var ip string
268
264
269
265
networkingService , err := networking .NewService (scope )
@@ -309,7 +305,7 @@ func (r *OpenStackFloatingIPPoolReconciler) getIP(ctx context.Context, scope sco
309
305
return ip , nil
310
306
}
311
307
312
- func (r * OpenStackFloatingIPPoolReconciler ) reconcileFloatingIPNetwork (ctx context. Context , scope scope.Scope , pool * infrav1.OpenStackFloatingIPPool ) error {
308
+ func (r * OpenStackFloatingIPPoolReconciler ) reconcileFloatingIPNetwork (scope scope.Scope , pool * infrav1.OpenStackFloatingIPPool ) error {
313
309
// If the pool already has a network, we don't need to do anything
314
310
if pool .Status .FloatingIPNetwork != nil {
315
311
return nil
@@ -322,7 +318,7 @@ func (r *OpenStackFloatingIPPoolReconciler) reconcileFloatingIPNetwork(ctx conte
322
318
323
319
netListOpts := external.ListOptsExt {
324
320
ListOptsBuilder : pool .Spec .FloatingIPNetwork .ToListOpt (),
325
- External : pointer .BoolPtr (true ),
321
+ External : pointer .Bool (true ),
326
322
}
327
323
328
324
networkList , err := networkingService .GetNetworksByFilter (& netListOpts )
@@ -342,18 +338,6 @@ func (r *OpenStackFloatingIPPoolReconciler) reconcileFloatingIPNetwork(ctx conte
342
338
return nil
343
339
}
344
340
345
- func (r * OpenStackFloatingIPPoolReconciler ) getInfraCluster (ctx context.Context , cluster * clusterv1.Cluster , claim * ipamv1.IPAddressClaim ) (* infrav1.OpenStackCluster , error ) {
346
- openStackCluster := & infrav1.OpenStackCluster {}
347
- openStackClusterName := client.ObjectKey {
348
- Namespace : claim .Namespace ,
349
- Name : cluster .Spec .InfrastructureRef .Name ,
350
- }
351
- if err := r .Client .Get (ctx , openStackClusterName , openStackCluster ); err != nil {
352
- return nil , err
353
- }
354
- return openStackCluster , nil
355
- }
356
-
357
341
func (r * OpenStackFloatingIPPoolReconciler ) iPAddressClaimToPoolMapper (_ context.Context , o client.Object ) []ctrl.Request {
358
342
claim , ok := o .(* ipamv1.IPAddressClaim )
359
343
if ! ok {
0 commit comments