-
Notifications
You must be signed in to change notification settings - Fork 12
Check restoration hash in NetBox before updating resource in NetBox #266
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
Closed
bruelea
wants to merge
6
commits into
dependabot/docker/golang-1.24.1
from
fix/check-restoration-hash-in-case-lock-times-out
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5a4f67a
check restoration hash when resource is update
bruelea 433925d
fix test
bruelea be30a53
fix unit test and linting
bruelea 1d7b3e8
update status if hash mismatch but id not nil
bruelea 8a3239e
define variable for all hashes in tests
bruelea d352a66
remove duplicate code
bruelea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,10 +170,30 @@ func (r *IpAddressReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( | |
|
|
||
| netboxIpAddressModel, err := r.NetboxClient.ReserveOrUpdateIpAddress(ipAddressModel) | ||
| if err != nil { | ||
| updateStatusErr := r.SetConditionAndCreateEvent(ctx, o, netboxv1.ConditionIpaddressReadyFalse, | ||
| corev1.EventTypeWarning, o.Spec.IpAddress) | ||
| return ctrl.Result{}, fmt.Errorf("failed to update ip address status: %w, "+ | ||
| "after reservation of ip in netbox failed: %w", updateStatusErr, err) | ||
| if errors.Is(err, api.ErrRestorationHashMismatch) && o.Status.IpAddressId == 0 { | ||
| // if there is a restoration hash mismatch and the IpAddressId status field is not set, | ||
| // delete the ip address so it can be recreated by the ip address claim controller | ||
| // this will only affect resources that are created by a claim controller (and have a restoration hash custom field | ||
| logger.Info("restoration hash mismatch, deleting ip address custom resource", "ipaddress", o.Spec.IpAddress) | ||
| err = r.Client.Delete(ctx, o) | ||
| if err != nil { | ||
| if updateStatusErr := r.SetConditionAndCreateEvent(ctx, o, netboxv1.ConditionIpaddressReadyFalse, | ||
| corev1.EventTypeWarning, err.Error()); updateStatusErr != nil { | ||
| return ctrl.Result{}, fmt.Errorf("failed to update ip address status: %w, "+ | ||
| "after deletion of ip address cr failed: %w", updateStatusErr, err) | ||
| } | ||
| return ctrl.Result{Requeue: true}, nil | ||
| } | ||
| return ctrl.Result{}, nil | ||
|
|
||
| } | ||
|
|
||
| if updateStatusErr := r.SetConditionAndCreateEvent(ctx, o, netboxv1.ConditionIpaddressReadyFalse, | ||
| corev1.EventTypeWarning, err.Error()); updateStatusErr != nil { | ||
| return ctrl.Result{}, fmt.Errorf("failed to update ip address status: %w, "+ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is missing a check if |
||
| "after reservation of ip in netbox failed: %w", updateStatusErr, err) | ||
| } | ||
| return ctrl.Result{Requeue: true}, nil | ||
| } | ||
|
|
||
| // 3. unlock lease of parent prefix | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -184,8 +184,29 @@ func (r *PrefixReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr | |
|
|
||
| netboxPrefixModel, err := r.NetboxClient.ReserveOrUpdatePrefix(prefixModel) | ||
| if err != nil { | ||
| updateStatusErr := r.SetConditionAndCreateEvent(ctx, prefix, netboxv1.ConditionPrefixReadyFalse, corev1.EventTypeWarning, prefix.Spec.Prefix) | ||
| return ctrl.Result{}, fmt.Errorf("failed at update prefix status: %w, "+"after reservation of prefix in netbox failed: %w", updateStatusErr, err) | ||
| if errors.Is(err, api.ErrRestorationHashMismatch) && prefix.Status.PrefixId == 0 { | ||
| // if there is a restoration hash mismatch and the PrefixId status field is not set, | ||
| // delete the prefix so it can be recreated by the prefix claim controller | ||
| // this will only affect resources that are created by a claim controller (and have a restoration hash custom field | ||
| logger.Info("restoration hash mismatch, deleting prefix custom resource", "prefix", prefix.Spec.Prefix) | ||
| err = r.Client.Delete(ctx, prefix) | ||
| if err != nil { | ||
| if updateStatusErr := r.SetConditionAndCreateEvent(ctx, prefix, netboxv1.ConditionPrefixReadyFalse, | ||
| corev1.EventTypeWarning, err.Error()); updateStatusErr != nil { | ||
| return ctrl.Result{}, fmt.Errorf("failed to update prefix status: %w, "+ | ||
| "after deletion of prefix cr failed: %w", updateStatusErr, err) | ||
| } | ||
| return ctrl.Result{Requeue: true}, nil | ||
| } | ||
| return ctrl.Result{}, nil | ||
| } | ||
|
|
||
| if updateStatusErr := r.SetConditionAndCreateEvent(ctx, prefix, netboxv1.ConditionPrefixReadyFalse, | ||
| corev1.EventTypeWarning, err.Error()); updateStatusErr != nil { | ||
| return ctrl.Result{}, fmt.Errorf("failed to update prefix status: %w, "+ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is missing a check if |
||
| "after reservation of prefix netbox failed: %w", updateStatusErr, err) | ||
| } | ||
| return ctrl.Result{Requeue: true}, nil | ||
| } | ||
|
|
||
| /* 3. unlock lease of parent prefix */ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.