Skip to content

Conversation

@anton-paulovich
Copy link

  1. If CR does not have finalizer - we add it and call another reconciliation
  2. If CR is going to be deleted we remove IP from NetBox and remove finalizer

Comment on lines +172 to +176
nbIP, err := r.netBox.IPAM().GetIPAddressByAddress(ipStr)
if err != nil {
logger.Error(err, "unable to find IP netbox ip address, NetBox IP will not be removed")
return nil
}
Copy link
Author

Choose a reason for hiding this comment

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

Maybe we should check for ErrNotFound here and if so we handle it as a valid case that IP was already removed from NetBox by someone
And if there is another kind of err (400/500/502) we should return err, so Reconcile() will be called again

But I did not found any existing implementation of IsErrNotFound() in NetBox client.
Should I add this check by strings parsing or smth for better error handling here?

Or we do not allow the case when IP was already deleted by someone, so we should return error here anyways?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, we should not handle it as error case if the IPAddress already removed from netbox and also not assigned to the LAG interface.

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 about how, I would ask Peter Gehrt for such details.

Comment on lines +172 to +176
nbIP, err := r.netBox.IPAM().GetIPAddressByAddress(ipStr)
if err != nil {
logger.Error(err, "unable to find IP netbox ip address, NetBox IP will not be removed")
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

yes, we should not handle it as error case if the IPAddress already removed from netbox and also not assigned to the LAG interface.

Comment on lines +172 to +176
nbIP, err := r.netBox.IPAM().GetIPAddressByAddress(ipStr)
if err != nil {
logger.Error(err, "unable to find IP netbox ip address, NetBox IP will not be removed")
return nil
}
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 about how, I would ask Peter Gehrt for such details.

return ctrl.Result{}, err
}

controllerutil.RemoveFinalizer(ipAddress, ipAddressFinalizer)
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps only update if we actually removed a finalizer?

Copy link
Author

Choose a reason for hiding this comment

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

Yea, missed that

logger := log.FromContext(ctx)
logger.Info("deleting IP Address")

if !controllerutil.ContainsFinalizer(ipAddr, ipAddressFinalizer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would just try to clean independent if we have the finalizer or not

}

controllerutil.RemoveFinalizer(ipAddress, ipAddressFinalizer)
if err = r.k8sClient.Update(ctx, ipAddress); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would either use .Patch() or include

return retry.RetryOnConflict(retry.DefaultRetry, func() error {

on updates, to avoid conflicts.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, very good point

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.

2 participants