Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
bruelea committed Nov 26, 2024
1 parent a12f7d0 commit a58fc71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 50 deletions.
41 changes: 0 additions & 41 deletions internal/controller/iprange_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,47 +292,6 @@ func (r *IpRangeReconciler) generateNetboxIpRangeModelFromIpRangeSpec(o *netboxv
}, nil
}

func (r *IpRangeReconciler) tryLockOnParentPrefix(ctx context.Context, ll *leaselocker.LeaseLocker, o *netboxv1.IpRange) (ctrl.Result, error) {
logger := log.FromContext(ctx)

// determine NamespacedName of IpRangeClaim owning the IpRange CR
orLookupKey := types.NamespacedName{
Name: o.ObjectMeta.OwnerReferences[0].Name,
Namespace: o.Namespace,
}

ipRangeClaim := &netboxv1.IpRangeClaim{}
err := r.Client.Get(ctx, orLookupKey, ipRangeClaim)
if err != nil {
return ctrl.Result{}, err
}

// get name of parent prefix
leaseLockerNSN := types.NamespacedName{
Name: convertCIDRToLeaseLockName(ipRangeClaim.Spec.ParentPrefix),
Namespace: r.OperatorNamespace,
}
ll, err = leaselocker.NewLeaseLocker(r.RestConfig, leaseLockerNSN, orLookupKey.String())
if err != nil {
return ctrl.Result{}, err
}

lockCtx, cancel := context.WithCancel(ctx)
defer cancel()

// create lock
locked := ll.TryLock(lockCtx)
if !locked {
logger.Info(fmt.Sprintf("failed to lock parent prefix %s", ipRangeClaim.Spec.ParentPrefix))
r.Recorder.Eventf(o, corev1.EventTypeWarning, "FailedToLockParentPrefix", "failed to lock parent prefix %s",
ipRangeClaim.Spec.ParentPrefix)
return ctrl.Result{}, nil
}
logger.V(4).Info(fmt.Sprintf("successfully locked parent prefix %s", ipRangeClaim.Spec.ParentPrefix))

return ctrl.Result{}, nil
}

func (r *IpRangeReconciler) removeFinalizer(ctx context.Context, o *netboxv1.IpRange) error {
logger := log.FromContext(ctx)
if controllerutil.ContainsFinalizer(o, IpRangeFinalizerName) {
Expand Down
19 changes: 10 additions & 9 deletions internal/controller/iprangeclaim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ func (r *IpRangeClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request
return ctrl.Result{}, err
}

err = r.logErrorSetConditionAndCreateEvent(ctx, o, netboxv1.ConditionIpRangeAssignedTrue, corev1.EventTypeNormal, "", nil)
err = r.logErrorSetConditionAndCreateEvent(ctx, o, netboxv1.ConditionIpRangeAssignedTrue, corev1.EventTypeNormal,
fmt.Sprintf(" , assigned ip range: %s-%s", ipRangeModel.StartAddress, ipRangeModel.EndAddress), nil)
if err != nil {
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -158,14 +159,14 @@ func (r *IpRangeClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request
}
logger.Info("reconcile loop finished")
return ctrl.Result{}, nil
} else {
err := r.logErrorSetConditionAndCreateEvent(ctx, o, netboxv1.ConditionIpRangeClaimReadyFalse, corev1.EventTypeWarning, "", nil)
if err != nil {
return ctrl.Result{}, err
}
logger.Info("reconcile loop finished")
return ctrl.Result{Requeue: true}, nil
}

err = r.logErrorSetConditionAndCreateEvent(ctx, o, netboxv1.ConditionIpRangeClaimReadyFalse, corev1.EventTypeWarning, "", nil)
if err != nil {
return ctrl.Result{}, err
}
logger.Info("reconcile loop finished")
return ctrl.Result{Requeue: true}, nil
}

// SetupWithManager sets up the controller with the Manager.
Expand Down Expand Up @@ -237,7 +238,7 @@ func (r *IpRangeClaimReconciler) tryLockOnParentPrefix(ctx context.Context, o *n
return ll, ctrl.Result{}, nil
}

func (r *IpRangeClaimReconciler) generateIpRangeClaimStatus(ctx context.Context, o *netboxv1.IpRangeClaim, ipRange *netboxv1.IpRange) (netboxv1.IpRangeClaimStatus, error) {
func (r *IpRangeClaimReconciler) generateIpRangeClaimStatus(o *netboxv1.IpRangeClaim, ipRange *netboxv1.IpRange) (netboxv1.IpRangeClaimStatus, error) {
startAddressDotDecimal := strings.Split(ipRange.Spec.StartAddress, "/")[0]
endAddressDotDecimal := strings.Split(ipRange.Spec.EndAddress, "/")[0]

Expand Down

0 comments on commit a58fc71

Please sign in to comment.