Skip to content

Commit b0a4a07

Browse files
committed
lint
1 parent 1c25e8a commit b0a4a07

File tree

1 file changed

+55
-58
lines changed

1 file changed

+55
-58
lines changed

controllers/openstackfloatingippool_controller.go

Lines changed: 55 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,12 @@ const (
4949
openStackFloatingIPPool = "OpenStackFloatingIPPool"
5050
)
5151

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+
}
6058

6159
// OpenStackFloatingIPPoolReconciler reconciles a OpenStackFloatingIPPool object.
6260
type OpenStackFloatingIPPoolReconciler struct {
@@ -132,56 +130,56 @@ func (r *OpenStackFloatingIPPoolReconciler) Reconcile(ctx context.Context, req c
132130

133131
if claim.Status.AddressRef.Name == "" {
134132
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+
}
141142

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,
157149
},
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,
161156
},
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,
169157
},
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+
}
171172

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
183177
}
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)
185183
return ctrl.Result{}, err
186184
}
187185
}
@@ -314,17 +312,17 @@ func (r *OpenStackFloatingIPPoolReconciler) getIP(scope scope.Scope, pool *infra
314312

315313
// 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
316314
// 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())
318316
if err != nil {
319317
scope.Logger().Error(err, "Failed to get floating IPs by tag", "pool", pool.Name)
320318
return "", err
321319
}
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) {
324322
continue
325323
}
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)
328326
}
329327

330328
if len(pool.Status.AvailableIPs) > 0 {
@@ -361,7 +359,6 @@ func (r *OpenStackFloatingIPPoolReconciler) getIP(scope scope.Scope, pool *infra
361359
}
362360
return true, nil
363361
})
364-
365362
if err != nil {
366363
scope.Logger().Error(err, "Failed to tag floating IP", "ip", fp.FloatingIP, "tag", tag)
367364
}

0 commit comments

Comments
 (0)