@@ -49,14 +49,12 @@ const (
49
49
openStackFloatingIPPool = "OpenStackFloatingIPPool"
50
50
)
51
51
52
- var (
53
- backoff = wait.Backoff {
54
- Steps : 4 ,
55
- Duration : 10 * time .Millisecond ,
56
- Factor : 5.0 ,
57
- Jitter : 0.1 ,
58
- }
59
- )
52
+ var backoff = wait.Backoff {
53
+ Steps : 4 ,
54
+ Duration : 10 * time .Millisecond ,
55
+ Factor : 5.0 ,
56
+ Jitter : 0.1 ,
57
+ }
60
58
61
59
// OpenStackFloatingIPPoolReconciler reconciles a OpenStackFloatingIPPool object.
62
60
type OpenStackFloatingIPPoolReconciler struct {
@@ -132,56 +130,56 @@ func (r *OpenStackFloatingIPPoolReconciler) Reconcile(ctx context.Context, req c
132
130
133
131
if claim .Status .AddressRef .Name == "" {
134
132
ipAddress := & ipamv1.IPAddress {}
135
- if err := r .Client .Get (ctx , client.ObjectKey {Name : claim .Name , Namespace : claim .Namespace }, ipAddress ); err != nil {
136
- if apierrors .IsNotFound (err ) {
137
- ip , err := r .getIP (scope , pool )
138
- if err != nil {
139
- return ctrl.Result {}, err
140
- }
133
+ err := r .Client .Get (ctx , client.ObjectKey {Name : claim .Name , Namespace : claim .Namespace }, ipAddress )
134
+ if client .IgnoreNotFound (err ) != nil {
135
+ return ctrl.Result {}, err
136
+ }
137
+ if apierrors .IsNotFound (err ) {
138
+ ip , err := r .getIP (scope , pool )
139
+ if err != nil {
140
+ return ctrl.Result {}, err
141
+ }
141
142
142
- ipAddress = & ipamv1.IPAddress {
143
- ObjectMeta : ctrl.ObjectMeta {
144
- Name : claim .Name ,
145
- Namespace : claim .Namespace ,
146
- Finalizers : []string {
147
- infrav1 .DeleteFloatingIPFinalizer ,
148
- },
149
- OwnerReferences : []metav1.OwnerReference {
150
- {
151
- APIVersion : claim .APIVersion ,
152
- Kind : claim .Kind ,
153
- Name : claim .Name ,
154
- UID : claim .UID ,
155
- },
156
- },
143
+ ipAddress = & ipamv1.IPAddress {
144
+ ObjectMeta : ctrl.ObjectMeta {
145
+ Name : claim .Name ,
146
+ Namespace : claim .Namespace ,
147
+ Finalizers : []string {
148
+ infrav1 .DeleteFloatingIPFinalizer ,
157
149
},
158
- Spec : ipamv1.IPAddressSpec {
159
- ClaimRef : corev1.LocalObjectReference {
160
- Name : claim .Name ,
150
+ OwnerReferences : []metav1.OwnerReference {
151
+ {
152
+ APIVersion : claim .APIVersion ,
153
+ Kind : claim .Kind ,
154
+ Name : claim .Name ,
155
+ UID : claim .UID ,
161
156
},
162
- PoolRef : corev1.TypedLocalObjectReference {
163
- APIGroup : pointer .String (infrav1 .GroupVersion .Group ),
164
- Kind : pool .Kind ,
165
- Name : pool .Name ,
166
- },
167
- Address : ip ,
168
- Prefix : 32 ,
169
157
},
170
- }
158
+ },
159
+ Spec : ipamv1.IPAddressSpec {
160
+ ClaimRef : corev1.LocalObjectReference {
161
+ Name : claim .Name ,
162
+ },
163
+ PoolRef : corev1.TypedLocalObjectReference {
164
+ APIGroup : pointer .String (infrav1 .GroupVersion .Group ),
165
+ Kind : pool .Kind ,
166
+ Name : pool .Name ,
167
+ },
168
+ Address : ip ,
169
+ Prefix : 32 ,
170
+ },
171
+ }
171
172
172
- // Retry creating the IPAddress object
173
- err = wait .ExponentialBackoff (backoff , func () (bool , error ) {
174
- if err := r .Client .Create (ctx , ipAddress ); err != nil {
175
- return false , nil
176
- }
177
- return true , nil
178
- })
179
- if err != nil {
180
- // If we failed to create the IPAddress, there might be an IP leak in OpenStack if we also failed to tag the IP after creation
181
- scope .Logger ().Error (err , "Failed to create IPAddress" , "ip" , ip )
182
- return ctrl.Result {}, err
173
+ // Retry creating the IPAddress object
174
+ err = wait .ExponentialBackoff (backoff , func () (bool , error ) {
175
+ if err := r .Client .Create (ctx , ipAddress ); err != nil {
176
+ return false , err
183
177
}
184
- } else {
178
+ return true , nil
179
+ })
180
+ if err != nil {
181
+ // If we failed to create the IPAddress, there might be an IP leak in OpenStack if we also failed to tag the IP after creation
182
+ scope .Logger ().Error (err , "Failed to create IPAddress" , "ip" , ip )
185
183
return ctrl.Result {}, err
186
184
}
187
185
}
@@ -314,17 +312,17 @@ func (r *OpenStackFloatingIPPoolReconciler) getIP(scope scope.Scope, pool *infra
314
312
315
313
// Get tagged floating IPs and add them to the available IPs if they are not present in either the available IPs or the claimed IPs
316
314
// This is done to prevent leaking floating IPs if to prevent leaking floating IPs if the floating IP was created but the IPAddress object was not
317
- taggedFIPs , err := networkingService .GetFloatingIPsByTag (pool .GetFloatingIPTag ())
315
+ taggedIPs , err := networkingService .GetFloatingIPsByTag (pool .GetFloatingIPTag ())
318
316
if err != nil {
319
317
scope .Logger ().Error (err , "Failed to get floating IPs by tag" , "pool" , pool .Name )
320
318
return "" , err
321
319
}
322
- for _ , taggedIp := range taggedFIPs {
323
- if contains (pool .Status .AvailableIPs , taggedIp .FloatingIP ) || contains (pool .Status .ClaimedIPs , taggedIp .FloatingIP ) {
320
+ for _ , taggedIP := range taggedIPs {
321
+ if contains (pool .Status .AvailableIPs , taggedIP .FloatingIP ) || contains (pool .Status .ClaimedIPs , taggedIP .FloatingIP ) {
324
322
continue
325
323
}
326
- scope .Logger ().Info ("Tagged floating IP found that was not known to the pool, adding it to the pool" , "ip" , taggedIp .FloatingIP )
327
- pool .Status .AvailableIPs = append (pool .Status .AvailableIPs , taggedIp .FloatingIP )
324
+ scope .Logger ().Info ("Tagged floating IP found that was not known to the pool, adding it to the pool" , "ip" , taggedIP .FloatingIP )
325
+ pool .Status .AvailableIPs = append (pool .Status .AvailableIPs , taggedIP .FloatingIP )
328
326
}
329
327
330
328
if len (pool .Status .AvailableIPs ) > 0 {
@@ -361,7 +359,6 @@ func (r *OpenStackFloatingIPPoolReconciler) getIP(scope scope.Scope, pool *infra
361
359
}
362
360
return true , nil
363
361
})
364
-
365
362
if err != nil {
366
363
scope .Logger ().Error (err , "Failed to tag floating IP" , "ip" , fp .FloatingIP , "tag" , tag )
367
364
}
0 commit comments