Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make unlocking more reliable #59

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions internal/controller/ipaddress_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ func (r *IpAddressReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
"after reservation of ip in netbox failed: %w", updateStatusErr, err)
}

// 3. unlock lease of parent prefix
if ll != nil {
ll.Unlock()
}

// 4. update status fields
o.Status.IpAddressId = netboxIpAddressModel.ID
o.Status.IpAddressUrl = config.GetBaseUrl() + "/ipam/ip-addresses/" + strconv.FormatInt(netboxIpAddressModel.ID, 10)
err = r.Client.Status().Update(ctx, o)
if err != nil {
return ctrl.Result{}, err
}

// update lastIpAddressMetadata annotation
if annotations == nil {
annotations = make(map[string]string)
Expand Down Expand Up @@ -204,14 +217,6 @@ func (r *IpAddressReconciler) Reconcile(ctx context.Context, req ctrl.Request) (

debugLogger.Info(fmt.Sprintf("reserved ip address in netbox, ip: %s", o.Spec.IpAddress))

// 3. unlock lease of parent prefix
if ll != nil {
ll.Unlock()
}

// 4. update status conditions
o.Status.IpAddressId = netboxIpAddressModel.ID
o.Status.IpAddressUrl = config.GetBaseUrl() + "/ipam/ip-addresses/" + strconv.FormatInt(netboxIpAddressModel.ID, 10)
err = r.SetConditionAndCreateEvent(ctx, o, netboxv1.ConditionIpaddressReadyTrue, corev1.EventTypeNormal, "")
if err != nil {
return ctrl.Result{}, err
Expand Down
21 changes: 13 additions & 8 deletions internal/controller/prefix_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ func (r *PrefixReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
return ctrl.Result{}, fmt.Errorf("failed at update prefix status: %w, "+"after reservation of prefix in netbox failed: %w", updateStatusErr, err)
}

/* 3. unlock lease of parent prefix */
if ll != nil {
ll.Unlock()
}

/* 4. update status fields */
prefix.Status.PrefixId = netboxPrefixModel.ID
prefix.Status.PrefixUrl = config.GetBaseUrl() + "/ipam/prefixes/" + strconv.FormatInt(netboxPrefixModel.ID, 10)
err = r.Client.Status().Update(ctx, prefix)
if err != nil {
return ctrl.Result{}, err
}

// update lastPrefixMetadata annotation
if annotations == nil {
annotations = make(map[string]string)
Expand Down Expand Up @@ -199,14 +212,6 @@ func (r *PrefixReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr

debugLogger.Info(fmt.Sprintf("reserved prefix in netbox, prefix: %s", prefix.Spec.Prefix))

/* 3. unlock lease of parent prefix */
if ll != nil {
ll.Unlock()
}

/* 4. update status conditions */
prefix.Status.PrefixId = netboxPrefixModel.ID
prefix.Status.PrefixUrl = config.GetBaseUrl() + "/ipam/prefixes/" + strconv.FormatInt(netboxPrefixModel.ID, 10)
if err = r.SetConditionAndCreateEvent(ctx, prefix, netboxv1.ConditionPrefixReadyTrue, corev1.EventTypeNormal, ""); err != nil {
return ctrl.Result{}, err
}
Expand Down