Skip to content

Conversation

@bruelea
Copy link
Collaborator

@bruelea bruelea commented Mar 14, 2025

In case the lock times out before a resource claimed by a prefix was successfully created in NetBox, two claims can get the same value assigned. By checking the restoration hash a resource has in NetBox assignments of the same resource to different claims can be avoided.

@jstudler jstudler self-requested a review March 20, 2025 11:00
Copy link
Collaborator

@jstudler jstudler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, would be great if @alexandernorth could also spend a few minutes to review the code.

A few minor things:

  • "mismatch" is misspelled. search/replace "issmatch" with "ismatch"
  • "restoration has" should be "restoration hash"

@jstudler jstudler requested a review from alexandernorth March 20, 2025 11:04
if err != nil {
updateStatusErr := r.SetConditionAndCreateEvent(ctx, o, netboxv1.ConditionIpaddressReadyFalse,
corev1.EventTypeWarning, err.Error())
return ctrl.Result{}, fmt.Errorf("failed to update ip address status: %w, "+
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing a check if updateStatusErr != nil

Copy link
Collaborator Author

@bruelea bruelea Mar 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added, same for the other locations. I also added some return statements that were missing.

}
if updateStatusErr := r.SetConditionAndCreateEvent(ctx, o, netboxv1.ConditionIpaddressReadyFalse,
corev1.EventTypeWarning, o.Spec.IpAddress); updateStatusErr != nil {
return ctrl.Result{}, fmt.Errorf("failed to update ip address status: %w, "+
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing a check if updateStatusErr != nil

if err != nil {
updateStatusErr := r.SetConditionAndCreateEvent(ctx, prefix, netboxv1.ConditionIpaddressReadyFalse,
corev1.EventTypeWarning, err.Error())
return ctrl.Result{}, fmt.Errorf("failed to update prefix status: %w, "+
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing a check if updateStatusErr != nil

}
if updateStatusErr := r.SetConditionAndCreateEvent(ctx, prefix, netboxv1.ConditionIpaddressReadyFalse,
corev1.EventTypeWarning, prefix.Spec.Prefix); updateStatusErr != nil {
return ctrl.Result{}, fmt.Errorf("failed to update prefix status: %w, "+
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing a check if updateStatusErr != nil

Ipam: mockIPAddress,
}

ipAddressModel := ipAddressModel("fioaf9289rjfhaeuih")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be declared as a const - it appears elsewhere too

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now defined variable for all hashes, so it's also easier to read.

StartAddress: &startAddress,
EndAddress: &endAddress,
CustomFields: map[string]interface{}{
config.GetOperatorConfig().NetboxRestorationHashFieldName: "different hash",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other controller uses something that looks like a hash - this could be aligned to either be text description or a hash for all controllers?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I chose to use sample hashes in all the tests.

@bruelea
Copy link
Collaborator Author

bruelea commented Mar 21, 2025

Looks good to me, would be great if @alexandernorth could also spend a few minutes to review the code.

A few minor things:

  • "mismatch" is misspelled. search/replace "issmatch" with "ismatch"
  • "restoration has" should be "restoration hash"

Thanks, the typos are fixed now.

@bruelea bruelea force-pushed the fix/check-restoration-hash-in-case-lock-times-out branch from 956b8c4 to d352a66 Compare April 9, 2025 14:39
@bruelea bruelea changed the base branch from main to dependabot/docker/golang-1.24.1 April 9, 2025 14:40
@dependabot dependabot bot deleted the branch dependabot/docker/golang-1.24.1 April 9, 2025 14:43
@dependabot dependabot bot closed this Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants