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

Fix Finalizers #78

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Fix Finalizers #78

wants to merge 2 commits into from

Conversation

MaIT-HgA
Copy link
Contributor

@MaIT-HgA MaIT-HgA commented Sep 30, 2024

Changes:

  • adding Finalizers are moved up
  • IP/Prefix deletion functions are updated with not found errors
  • error handling in Finalizers is updated with not found errors

Close #77

@MaIT-HgA MaIT-HgA force-pushed the fix/finalizers branch 3 times, most recently from 9b2fc00 to a1f57ac Compare September 30, 2024 11:37
@MaIT-HgA MaIT-HgA self-assigned this Sep 30, 2024
@MaIT-HgA MaIT-HgA added the bug Something isn't working label Sep 30, 2024
@MaIT-HgA MaIT-HgA marked this pull request as ready for review September 30, 2024 12:02
@@ -81,6 +82,14 @@ func (r *PrefixReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
if controllerutil.ContainsFinalizer(prefix, PrefixFinalizerName) {
if !prefix.Spec.PreserveInNetbox {
if err := r.NetboxClient.DeletePrefix(prefix.Status.PrefixId); err != nil {
if errors.Is(err, utils.ErrNotFound) {
setConditionErr := r.SetConditionAndCreateEvent(ctx, prefix, netboxv1.ConditionPrefixReadyFalse, corev1.EventTypeWarning, err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

Propose to use a different condition (replace netboxv1.ConditionPrefixReadyFalse with a new condition like e.g. netboxv1.ConditionPrefixReadyFalseDeletionFailed)

Currently the condition looks as follows:

  conditions:
  - lastTransitionTime: "2024-10-01T07:14:46Z"
    message: 'Failed to reserve IP in NetBox. failed to fetch IPAddress: not found'
    reason: FailedToReserveIpInNetbox
    status: "False"
    type: Ready

Propose to use reason "FailedToDeleteIpInNetbox" and message "Failed to delete IP in NetBox".

Same applies to the other controller...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree

@henrybear327 henrybear327 removed their request for review October 1, 2024 07:49
@@ -98,9 +100,17 @@ func (r *NetboxClient) UpdatePrefix(prefixId int64, prefix *netboxModels.Writabl
}

func (r *NetboxClient) DeletePrefix(prefixId int64) error {
// assuming id starts from 1 when Prefix is created so 0 means that Prefix doesn't exist
if prefixId == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what this check is about. Is it to catch the case where the prefix was never created in NetBox?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Finalizer set too late
2 participants