diff --git a/internal/controller/iprange_controller.go b/internal/controller/iprange_controller.go index c459aff..3bc5a51 100644 --- a/internal/controller/iprange_controller.go +++ b/internal/controller/iprange_controller.go @@ -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) { diff --git a/internal/controller/iprangeclaim_controller.go b/internal/controller/iprangeclaim_controller.go index e3f6a34..2a583be 100644 --- a/internal/controller/iprangeclaim_controller.go +++ b/internal/controller/iprangeclaim_controller.go @@ -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 } @@ -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. @@ -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]