Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In some cases, the Prefix and IpAddress reconcilers are stuck because a resource update prior to unlocking failed (e.g. due to concurrent edit in the kube-api). This could be e.g. the following line https://github.com/netbox-community/netbox-operator/blob/main/internal/controller/prefix_controller.go#L182
The next run of the reconciler will have
nil
forll
in https://github.com/netbox-community/netbox-operator/blob/main/internal/controller/prefix_controller.go#L203 and thus not try to unlock it. Example log output of the netbox-operator:After this, the entire reconciler will be blocked because the next object trying to aquire the lock for the same parentPrefix will time out (to the configured 60 seconds) and thus all operations on the same CRs will be blocked for these 60 seconds (each reconcile loop is single threaded).
This code change enhances the unlocking by moving the leaselocker Unlock() call up in the reconciler to the position where it actually makes sense (right after the Prefix or IP was updated in NetBox). We also move up the status update right after unlocking in order not to lose the reference to the object in NetBox.